Reputation: 8604
In order to design a filter (windowing method), I first generate my sinc function, like so:
L = 20;
fc = 0.25;
n = (1:L)';
my_sinc = sin(2*pi*fc*(n-L/2)) ./ (pi*(n-L/2));
my_sinc(L/2) = 2*fc;
Then I apply window:
win = blackman(L, 'symmetric');
filter_coeffs = (my_sinc .* win);
Can the first step be done using Matlab's builtin sinc()
function?
Upvotes: 2
Views: 2244
Reputation: 14577
Absolutely. You can use the builtin sinc
function to get exactly the same result as what you have calculated in my_sinc
. Since sinc(x) = sin(pi*x)/(pi*x)
, in your case the input argument to the sin function, x
, is equal to 2*pi*fc*(n-L/2)
. The denominator can then be written as a function of this x
(pi*(n-L/2) = 0.5*x/fc
) which gives you a scaling factor of 2*fc
multiplying the sinc
. This can be illustrated here:
builtin_sinc = 2*fc*sinc(2*fc*(n-L/2));
hold off; stem(n, my_sinc);
hold on; plot(n, builtin_sinc, 'rx');
You can then subsequently obtain the same filter coefficients with
filter_coeffs = (builtin_sinc .* win);
or directly
filter_coeffs = 0.5*sinc(2*fc*(n-L/2)) .* win;
Upvotes: 3