I am trying to process an audio file in Matlab by filtering out all frequencies except those within $\pm 25\ Hz$ of $523\ Hz$ (as well as its harmonics up to the Nyquist).
The resulting waveform should look like the green wave displayed below (blue being the original):
However, my resulting waveform is entirely zero:
Here is the simple code I wrote:
[s, Fs] = wavread('file.wav');
n = length(s);
f = linspace(-n/2, n/2, n)/(n*Fs);
S = fftshift(fft(s)/n);
filter = zeros(size(S));
f0 = 523;
while (f0<(Fs/2))
filter(abs(f-f0)<25)=1;
filter(abs(f+f0)<25)=1;
f0 = f0+523;
end
s_filter = real(ifft(fftshift(S.*filter)*n));
s_filter = int16(s_filter);
Tspan = n/Fs;
t = linspace(0,n,n)/n*Tspan;
plot(t,s, t, s_filter);
The problem is that the filter array returns only zeros. But what exactly causes that?
Any help would be greatly appreciated.
fir2
? $\endgroup$