views:

816

answers:

2

How can I make a simple low-pass FIR filter using Matlab (without using the built-in function) ?

Problem example:

Implement a FIR LPF with cut-off frequency 250Hz

it may also be necessary that, sampling freq is given...

Solution attempt or what I already know:

x = [...] -> input signal
A = 1; -> Since this is FIR
B = [?????]
y = filter(B, A, x) -> Output signal

Afaik, B should contain the coefficients for the FIR filter. But; how do I calculate these coefficients given that I only have the cut-off frequency?

+3  A: 

The simplest thing is a "windowed sinc" filter:

fs = 44100;
cutoff = 250;
t = -256:256;  % This will be a 513-tap filter
r = 2*cutoff/fs;
B = sinc(r*t).*r .* blackman(length(t))';
freqz(B);

The length of the filter (see t=...) controls the width of the transition band. cutoff is in this case the -6 dB point. blackman is the name of a popular window. You can check out this Wikipedia page for more infos on window functions. They basically have different trade-offs between transition band width and stopband rejection.

sellibitze
I cant use the built in fir functions as I have already stated in the question...
kramer
Sorry for that. I changed my answer.
sellibitze
Thanks :) I'll need to do some research on window functions...
kramer
A: 

If you wan't a different shape of the amplitude spectrum, do exactly as sellibitze suggested, only replace the sinc function with the real part of the inverse Fourier-transform of the desired amplitude response (delayed to get causal symmetrical impulse response).

S.C. Madsen