Filtering out a Specific Sound from a Audio File
99 次查看(过去 30 天)
显示 更早的评论
I would appreciate any help with my program. The problem and what I attempted is below.
problem: You have been provided with a sound file, buzzjc.wav, which is an audio clip of someone saying something, but it has been corrupted by adding a buzzer signal consisting of a few tones. First load the signal into MATLAB using the command wavread (using older MATLAB versions) and audioread (using newer versions) which you can read more about in the MATLAB help file. Example of loading audio file and playing audio in MATLAB (2017a):
% Read the audio file and store the audio in data and sampling rate into fs [data, fs] = audioread('test3_Q3.wav');
% Play audio file
player = audioplayer(data,fs);
play(player);
a.) Use the DFT to figure out the tone frequencies (at least approximately). List the tone frequencies.
b.) Describe how you would remove these unwanted tones in the audio signal using topics covered during this course.
c.) Next, remove these tones and then listen to the clip (note: if you are using an older version of MATLAB, you may have to use the command wavplay to play your audio clip. What the person in the clip is saying?
My solution:
[data, fs]=audioread('buzzjc.wav');
player = audioplayer(data,fs);
play(player);
dt = 1/fs; % Sampling time [s]
t = 0:dt:1; % Time
N = length(data);
f = (1:N/2+1)*fs/N; % Frequency
clip = 205; % Clip size (number of points)
X = zeros(clip, length(data)-clip); % Clips matrix
Y = zeros(length(f), length(data)-clip); % Spectrogram
for i = 1:length(data)-clip
X(:,i) = data(i:i+clip-1);
tmpS = fft(X(:,i), N);
Y(:,i) = abs(tmpS(1:N/2+1));
end
imagesc(t, f, (Y))
title('Spectrogram of Hidden words');
xlabel('Time [s]')
ylabel('Frequency [Hz]')
beginFreq = 800 / (fs/2);
endFreq = 900 / (fs/2);
[b,a] = butter(6, (beginFreq/endFreq/2));
fOut = filtfilt(b, a, f);
p = audioplayer(fOut, fs);
p.play;
I got the frequencies that needed to be removed were. 975Hz, 875Hz, 675Hz and 450Hz.
When ran it had the error message Attempt to execute SCRIPT butter as a function: /Users/Leah/Documents/MATLAB/butter.m
Error in Test3Bonus (line 32) [b,a] = butter(6, (beginFreq/endFreq/2))
It wouldn't allow me to attach the file. Any help would be greatly appreciated.
1 个评论
Allen Bastian
2020-5-14
编辑:Adam Danz
2020-5-15
how can we remove instrumenatl music to give just the audio file
回答(6 个)
Greg Dionne
2017-4-25
Use periodogram to figure out the frequencies. Then:
load buzzjc
%soundsc(f,fs)
n = numel(f);
fold = f;
for fi=[220 440 660 880]
a = sum(f .* cos(2*pi*fi/fs*(1:n)'))/n;
b = sum(f .* sin(2*pi*fi/fs*(1:n)'))/n;
f = f - a.*cos(2*pi*fi/fs*(1:n)')*2;
f = f - b.*sin(2*pi*fi/fs*(1:n)')*2;
end
plot([fold f])
soundsc(f,fs)
0 个评论
Image Analyst
2017-4-24
You called your script butter.m (/Users/Leah/Documents/MATLAB/butter.m). Call it something else because butter() is a built in function and it's getting confused as to which butter to use. Call it exercise6.m or something descriptive. But not butter.m
6 个评论
Star Strider
2017-4-24
编辑:Star Strider
2017-4-25
I may be missing something, but I can’t hear (or see) anything other than the four frequencies in that signal. I designed a multiple-notch FIR filter, then because of its length, used fftfilt to filter it. There was nothing left that I can hear as intelligible words.
The Code —
d = load('buzzjc.mat');
signal = d.f;
Fs = d.fs;
% player = audioplayer(f,fs);
%play(player);
N = size(signal,1); % Determine total number of samples in audio file
Fn = Fs/2;
FTsignal = fft(signal)/N;
Fv = linspace(0, 1, fix(N/2)+1)*Fn; % Frequency Vector
Iv = 1:length(Fv); % Index Vector
[pks,frqs] = findpeaks(abs(FTsignal(Iv))*2, Fv, 'MinPeakHeight',0.1);
figure(1)
plot(Fv, abs(FTsignal(Iv))*2)
hold on
plot(frqs, pks, '+r')
hold off
grid
notch_frq = sort([frqs-2.5 frqs+2.5 frqs-1.5 frqs+1.5]);;
mags = [1 0 1 0 1 0 1 0 1];
devs = [0.05 0.01 0.05 0.01 0.05 0.01 0.05 0.01 0.05];
[n,Wn,beta,ftype] = kaiserord(notch_frq,mags,devs,Fs);
n = n + rem(n,2);
hh = fir1(n,Wn,ftype,kaiser(n+1,beta),'scale');
figure(2);
freqz(hh, 1, 2^16, Fs)
fOut = fftfilt(hh, signal);
FTOut = fft(fOut)/N;
figure(3)
plot(Fv, abs(FTOut(Iv))*2)
grid
figure(4)
plot(Fv, abs(FTOut(Iv)./FTsignal(Iv))*2)
grid
p1 = audioplayer(fOut*50, Fs);
play(p1);
I leave you to experiment with this to see if you can get something out of it. The filter seems to have worked successfully, although I can’t figure out the reason the output is unintelligible. You may want to create separate Chebyshev Type II filters for each identified frequency (the ‘frqs’ output of the findpeaks call), then cascade them in series, and see if you can get a better result. You can use the filtfilt function with shorter filters. My filter here was longer than your signal, so I went with an alternative filtering method. You can get very narrow transition regions (steep rolloffs) with Chebyshev filters, so transition regions on the order of 1-2 Hz are possible.
0 个评论
Jim Thompson
2019-6-19
I have just registered, so I'm a brand new member of this forum.
Please note: I have never coded anything in my life, just cut and pasted published arduino sketches - with success I should add.
I have an interest in this due to several friends suffereing from tinnitus and I would like to create a notched music file, using the frequency or frequencies specific to each individual sufferer.
Questions:
- What is the supportive (underlying) program or application for the above files?
- What prerequisites would be needed to use them? (what coding skills etc.)
- Any tips for the beginner into this subject will be most appreciated.
Thanks in advance,
Jim Thompson
Australia.
2 个评论
Image Analyst
2019-6-19
I could be wrong, but doesn't tinnitus mean a ringing/tone in the ears/brain that occurs regardless of what audio waveform is being sent into the ears? So altering the input audio would not remove the ringing.
Or does it just amplify certain frequencies so you hear one tone much louder than it should be heard (I doubt this is the case but I could be wrong)?
Jim Thompson
2019-6-19
Image Analyst.
Thanks for the reply with the question.
There is no short answer to your question, so I will have to defer any attempts to answer it until later on. I fully intend to do so, with some explanatory links etc.
More later when time permits........
Jim.
Kavitha Kavi
2020-12-31
How to test the FIR filter with an audio file and also plot the spectrum of audio signal before and after filtering?
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Audio I/O and Waveform Generation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!