# windowed sinc filter in matlab

Hello i'm designing a low pass filter windowed sinc in matlab

Fs = 2048;
Fc = 250/Fs;  % 250hz
M=2048 % (to get a 4hz transition bandwidth) sig contains 200hz + 300hz sinusoids, i'm aiming at leaving only the 200hz

filt =sinc(2*Fc*((1:length(t))- M/2)).*(0.42-0.5*cos(2*pi*(1:length(t))/M)+0.08*cos(4*pi*(1:length(t))/M))';
filt(M/2)=2*pi*Fc;
fsig = sig .* filt;


i understand that the winsinc filter is applied by convolution in the freq domain, so it means a multiplication in the time domain, which i did, but i get an erroneous result, i get a 0 flat frequency everywhere in my frequency plot. what's wrong?

doing a freqz(filt) i get this, it seems correct reponse

Your understanding is mistaken. LTI filters are applied via convolution in time domain and multiplication in frequency domain.

The confusion possibly happens about designing the filter vs applying it.

The windowed sinc filter impulse response is given by

$$h[n] = w[n] h_i[n] ,$$

where $$h_i[n]$$ is the ideal (infinite length) sinc filter which corresponds to a brickwall lowpass type in your case. To approximate and taper that filter, you apply a window $$w[n]$$ of length $$L$$ to it by multiplication in time domain and its effect in the frequency domain is a convolution by the well known Fourier modulation theorem:

$$H(e^{j\omega}) = W(e^{j\omega}) \star H_i(e^{j\omega})$$

However, when the filter is applied on an input, the output equation in the time domain is

$$y[n] = h[n] \star x[n] ,$$

and the corresponding frequency domain equation is

$$Y(e^{j\omega}) = H(e^{j\omega}) X(e^{j\omega}).$$

So, rewrite your code base don this to get an expected result.

• Thanks for your reply. Here is what I understand , FIR filters are used by convolution and IIR filters by recursion. And i have been using multiplication instead of convolution so i corrected and update my code First: normalize my flter filt = filt / sum(filt); then i use the convolution function in matlab then i compare it with filter function fsig = conv(sig , filt,'same') ; fsignoise = conv(signoise , filt,'same'); fsig =filter(filt,1,sig); fsignoise =filter(filt,1,signoise); and here are my results : conv: imgur.com/a/XYLTCGU filt: imgur.com/a/JtGOmzO – carterwild Sep 19 '19 at 9:25
• as you can see there is a cut off frequency around by it doesnt filter the second frequency it only diminish its amplitude by a large factor – carterwild Sep 19 '19 at 9:26
• yes it can only diminish it as a practical filter. Only ideal filters would completely eliminate them. – Fat32 Sep 19 '19 at 18:21