FIR filter implementation to ECG
5 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I am trying to write a Matlab function that implements an FIR filter with impulse response in the form value myFIR(value, coefficients),where both the value argument adn return value are scalars
Does anyone understand the function output = myFIR(input,hn)? Can explain it to me?
0 Commenti
Risposte (1)
Patrik Ek
il 14 Nov 2013
Hi,
If I have understood correctly you have a FIR filter which you want to implement on a signal input in matlab. MATLAB have already a function that can do that. It is called filter and the syntax is
y = filter(b,a,x)
b is a vector with the coefficients of the nominator in an IIR filter and a is the denominator. The filter is a direct form II transpose type IIR filter. If you want you can create a filter object using dfilt to create an IIR filter of another kind. Then implement it as
y = filter(h,x)
h is the filter object. This should not be necessary for you though since your filter is a FIR type. The first coefficient in a need to be set to one. Otherwise MATLAB normalizes it. For you a should be a scalar with value 1.
Fo more information use the help of filter.
BR/ Patrik
2 Commenti
Nur safura
il 18 Nov 2013
Hi, I have a similar question as above. But for my assignment, I am told not to use the matlab function, but instead create our own FIR function. How do I go about this? Thanks in advance.
Patrik Ek
il 9 Dic 2013
Modificato: Patrik Ek
il 10 Dic 2013
Sorry for the late answer, you have most likely already got an answer by now. Regarding your question, A FIR filter is only a polynom. There are no real shortcuts for that. A tip is to find the zeros. They amplification is high far from the zeros and low close to the zeros.Regarding the implementation it is just basic matlab. The FIR filter has the form:
y(t) = a0*x(t)+a1*x(t-1)+a2*x(t-2)+...+an*x(t-n)
where each where t is the time sample vector. So simply, create a time vector t = 1:m, where m => n should apply. By calling (pseudo code):
t = 1:m+n;
x = randn(m,1); % Or rather your input.
y = a0*x(t)+a1*x(t-1)+a2*x(t-2)+...+x(t-n);
The only things needed to be adjusted by you is the input (x values and m), the length of the filter (n) and the coefficients a0,a1,...,an.
Especcially, try
t = 3:1000;
x = randn(1000,1); % Or rather your input.
y = x(t)-0.99*2*cos(pi/4)*x(t-1)+0.99^2*x(t-2);
w = fft(y);
figure;
plot(abs(w(1:length(w)/2)));
which you can see is a simple band-stop filter. Notice though that the first two elements are removed from t and that last elements of t is removed. These valuse should be there as well for a proper FIR filter implementation, which require a special treatment of these values to avoid a crash. If you try to plot the complete w vector you will see the aliasing effects as well.
Vedere anche
Categorie
Scopri di più su Single-Rate Filters in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!