Ideal audio filter with pulse
이전 댓글 표시
I am trying to add a sinusoid of 12000 Hz to a .wav file to create noise and then create an ideal filter as a pulse that is of amplitude 1 at desired frequencies and of amplitude 0 at unwanted frequencies. When multipying this pulse with the noisy signals frequency components it should act as an ideal filter. After the multiplication we are to take the ifft and play the audio signal and should not hear the sine wave. In the code below I am trying to make a lowpass filter with cuttoff of 10000 Hz. Our teacher told us the ideal filter could be created with this model.
To create an idea low pass filter in the FD, find the index of the cut of frequency, -fc and fc:
idx_p = find(f >= fc,1);
idx_n = find(f >= -fc, 1);
lpf = zeros(1,L);
lpf (idx_n:idx_p) = 0.5;
plot(f,h)
My attempt at this is below: Can someone explain where I went wrong and why this isnt working. I do not understand why he specified the index ranges to be = to .5 either.
[y,fs]=wavread('one.wav'); % fs=44101
f=12000;
fnyquist=fs/2
L=length(y)
nfft=1024;
ts=1/fs;
t = (0:L-1)/fs;
x=sin(2*pi*f*t);
%sound(x,fs)
%figure('Name','Time Domain Audio','NumberTitle','off');
%plot(t,y)
figure('Name','Time Domain sinusoid','NumberTitle','off');
plot(t,x);
idx = find(t>= 0.001, 1);
plot (t(1:idx), x(1:idx))
x1=x.';
whos
left=y(:,1);
Z=x1+left;
%sound(Z,fs);
Y = fftshift(fft(Z));
f = (-(L-1)/2:L/2)/fs;
w = 2*pi*f;
MagY = abs(Y);
PhY = angle(Y)*180/pi;
figure('Name','Noisy Freq Domain ','NumberTitle','off');
plot(f,MagY)
idx_p = find(f >= 10000,1);
idx_n = find(f >= -10000, 1);
lpf = zeros(1,L);
lpf =lpf (idx_n:idx_p) = 0.5;
figure('Name','lpf ','NumberTitle','off');
lpf2=lpf.';
plot(f,lpf)
whos
Filteredsignal=lpf2.*Y;
Filteredsignal1=ifft(Filteredsignal);
Filteredsignal2=abs(Filteredsignal1);
sound(Filteredsignal2,fs);
답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Fourier Analysis and Filtering에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!