IIR filter from diff. equation
9 次查看(过去 30 天)
显示 更早的评论
Hey,
I got a rather silly problem. I got the difference equation of a transfer function, and I need to create a filter from this. My first thought was to take the a's and b's directly from it, but if I do that, and use
bode(b,a);
I get what looks like a highpass filter, from a difference equation that is supposed to be of a lowpass. The difference equation is
y(n) = 2*y(nT-T) - y(nT-2T) + x(nT) - 2x(nT-6T) + x(nT-12T)
I'm not gonna tell you what I took a and b to be, since I think i got it wrong :-)
0 个评论
采纳的回答
Wayne King
2012-9-28
Perhaps you are not representing the system correctly in bode()?
A = [1 -2 1];
B = [1 0 0 0 0 0 -2 0 0 0 0 0 1];
fvtool(B,A)
2 个评论
Wayne King
2012-9-28
编辑:Wayne King
2012-9-28
No, it's not bode(A,B), the problem is that bode() is operating on the premise that you have positive powers of the variable (not negative as you have), so it's interpreting:
A = [1 -2 1];
as z^2-2z^1+1 for example.
更多回答(2 个)
Wayne King
2012-10-1
编辑:Wayne King
2012-10-1
This is a lowpass filter:
aLowpass = [1 -2 1];
bLowpass = [1 0 0 0 0 0 -2 0 0 0 0 0 1];
As you can see with:
fvtool(bLowpass,aLowpass,'Fs',100)
but it is not a very good one. And the highpass filter is not particular good either.
Since you have the Signal Processing Toolbox, why not design your filters with that software?
For example, say you want a lowpass Butterworth (IIR) filter for data sampled at 100 Hz and you want to lowpass everything below 10 Hz. I'll make the attenuation in the stopband 40 dB and the passband ripple 0.5 dB.
D = fdesign.lowpass('Fp,Fst,Ap,Ast',10,15,0.5,40,100);
filtobj = design(D,'butter');
fvtool(filtobj)
Now you can filter your data with:
lowpass_ecg = filter(filtobj,ecg_chan);
By the way, you are supposed to accept answers when people have answered your question.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Frequency Transformations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!