# Using sinc as a filter

187 views (last 30 days)
Juan on 5 May 2014
Edited: Juan on 7 May 2014
I'm trying to use a cardinal sine as a lowpass filter for a cosine signal with a fundamental of 1k.
In frequency domain, what really happens is that I'm multiplying two impulses (centered at -1k and 1k) with a rectangular pulse of width equals 2 (convolution is multiplication in frecuency domain). The result would be a constant zero function. However using the above code in Matlab I'm getting again the sinc function as output. Any help would be appreciated (attached the full plot).
D = 5;
f0 = 1000;
fm = 2*f0; % nyquist reestriction
t = (-D:1/fm:D);
x = cos(1000*2*pi*t);
h = sinc(t);
x_p = filter(h,1,x);
plot(x_p);
This questions was also asked on http://dsp.stackexchange.com/questions/15961/using-sinc-as-a-filter but is still unanswered. Using conv(h,x) I'm getting two cardinal sines, also tested with filter(x,1,h)

Honglei Chen on 7 May 2014
Hi Juan,
Your filter is as long as your signal, that means whatever you see is basically the transient while Fourier analysis gives the stabilized result. If you shorten your filter to a quarter of length, you will see that after the transient, the result is close to 0. (Note I changed your total points to even to make the bookkeeping easy but you can surely reproduce this with odd number of points)
D = 5;
f0 = 1000;
fm = 2*f0; % nyquist reestriction
t = (-D:1/fm:D-1/fm);
x = cos(1000*2*pi*t);
h = sinc(t(3*numel(t)/8:5*numel(t)/8-1));
x_p = filter(h,1,x);
plot(x_p);
1. Your signal is critically sampled so you have only two points in one period of cosine. This does not impact your result but your signal is actually a zigzag line rather than a sinusoid.
2. I'd like to also point out that sinc function is actually the continuous Fourier transform of a boxcar and in the discrete system, it should be a Dirichlet function. Again, this doesn't really affect your result much but I figure it is better if you align everything correctly. Below is an example if you want to use this approach
ns = numel(t);
ns = ns/4;
f = -fm/2:fm/ns:fm/2-fm/ns;
h1 = ifftshift(diric(f/fm,2*ns));
x_p1 = filter(h1,1,x);
plot(x_p1);
HTH
Juan on 7 May 2014
Thanks Honglei Chen, makes a lot of sense. I knew that boxcar is the dft of sinc but I was trying attack the problem from the time domain.
Just another question, I noticed that when appling the filter I get a line close to zero but I also have a little sinc function present in one corner. Is there any way to improve the filter's performance?
Thanks a lot!