Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a Simple FIR Filter using Matlab?

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?

like image 708
Cihan Keser Avatar asked Nov 15 '09 20:11

Cihan Keser


1 Answers

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.

like image 117
sellibitze Avatar answered Oct 13 '22 08:10

sellibitze