Filtering an Audio File in MATLAB 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&lt;(Fs/2))
    filter(abs(f-f0)&lt;25)=1;
    filter(abs(f+f0)&lt;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.
First of all, you don't need to shift the spectrum of the signal. Also, your filter is zero everywhere. Your frequency vector contains normalized frequencies, which is fine, but then you are using real frequencies when you build the filter. Either change the frequency vector f to real frequencies or normalize f0 too