MATLAB Answers

0

How to plot Butterworth filters with own data?

Kathleen Nicole Rice さんによって質問されました 2019 年 6 月 18 日
最新アクティビティ Star Strider
さんによって コメントされました 2019 年 6 月 19 日
Trying to use a bandpass butterworth filter on an ECG signal using the code below but whenever I use the lines:
h= filter( D,C,x) % where x= data
plot(h)
at the end of my code I just get a crazy plot which does not make sense or show my data. How could I accurately plot this filter with my data?
fp= [3 120];
fs= [2 200];
fn= 1000;
[N,fc]= buttord(fp/fn, fs/fn, 1, 60);
[D,C]= butter(N, fc);
%freqz(C,D)
h= filter(D,C,x);
plot(h) % these last 2 lines give strange results

  0 件のコメント

サインイン to comment.

1 件の回答

Star Strider
回答者: Star Strider
2019 年 6 月 18 日
 採用された回答

It would help to know the sizes of ‘x’ and ‘h’.
You should also have a time vector, so:
figure
plot(t, h)
grid
will plot ‘h’ as a function of time vector ‘t’.

  4 件のコメント

Star Strider
2019 年 6 月 18 日
An improvement would be:
Fn= 1000;
Fs = Fn*2;
Wp= [3 120]/Fn;
Ws= [2 200]/Fn;
Rp = 1;
Rs = 50;
[n,Wp] = ellipord(Wp,Ws,Rp,Rs); % Elliptical Filter Parameters
[z,p,k] = ellip(n,Rp,Rs,Wp); % Elliptical Filter Design (Specify Lowpass)
[sos,g] = zp2sos(z,p,k); % Second-Order-Section For Stability
figure
freqz(sos, 2^14, Fs) % Plot Filter Characteristics
h = filtfilt(sos, g, x)
figure
plot(h)
If you want to create a time vector:
t = linspace(0, 1, numel(h))/Fs;
figure
plot(t,h);
Kathleen Nicole Rice 2019 年 6 月 19 日
Great, this fixed the problem. Thank you so much!
Star Strider
2019 年 6 月 19 日
As always, my pleasure!

サインイン to comment.



Translated by