Plotting different filtering functions WITH DATA

Hi everyone,
I'm trying to filter an ECG signal but I am unsure how to filter the data and then plot the filter with my own data using the parameters set. I know that fvtool and freqz can plot the magnitude and phase but I can't figure out how to plot the filter on my data (yes I've tried using plot! :) ) I've used a ton of different filtering techniques and my latest can be seen below (taken from a previous post). Can I use "plot" to plot my data with this filter and if so how? Please let me know as I am desperate!!! Thank you in advance.
Fs = 2000; % Sampling Frequency
Fn = Fs/2; % Nyquist Frequency
Wp = [2 100]/Fn; % Filter Passband (Normalised)
Ws = Wp .* [0.5 1.2]; % Filter Stopband (Normalised)
Rp= 1;
Rs= 50;
[n,Ws] = cheb2ord(Wp,Ws,Rp,Rs);
[b,a] = cheby2(n, Rs, Ws);
[sos,g] = tf2sos(b,a);
%figure(1)
%freqz(sos, 1024, Fs)

 採用された回答

Star Strider
Star Strider 2019 年 6 月 18 日

0 投票

Can I use "plot" to plot my data with this filter and if so how?
Yes. It depends on what you want to plot.
To plot your filtered data as a function of time, and if ‘t’ is your time vector, and ‘data’ is your data vector:
filtered_data = filtfilt(sos, g, data);
figure
plot(t, filtered_data)
grid

4 件のコメント

Kathleen Nicole Rice
Kathleen Nicole Rice 2019 年 6 月 18 日
編集済み: Kathleen Nicole Rice 2019 年 6 月 18 日
For some reason when I plot this nothing shows up on the graph. Below is the full code I have currently. There is no usable time t variable because of the software we use and how it counts time on a repetitive scale so I have previously just plotted just saying "plot(filter_x11)" and it has worked. I am not sure why nothing is being plotted since all of the variables are there and working.
Fs = 2000; % Sampling Frequency
Fn = Fs/2; % Nyquist Frequency
Wp = [2 100]/Fn; % Filter Passband (Normalised)
Ws = Wp .* [0.5 1.2]; % Filter Stopband (Normalised)
Rp= 1;
Rs= 50;
[n,Ws] = cheb2ord(Wp,Ws,Rp,Rs);
[b,a] = cheby2(n, Rs, Ws);
[sos,g] = tf2sos(b,a);
%figure(1)
%freqz(sos, 1024, Fs)
filtered_data = filtfilt(sos, g, filter_x11); %filter_x11 is
% previously filtered ecg data with 60Hz notch filters
figure
plot(filtered_data)
Star Strider
Star Strider 2019 年 6 月 18 日
A problem with transfer function representation is that your filters do not always do what you believe they are doing. That’s the reason the zero-pole-gain and second-order-section representation is best.
Try this instead:
[z,p,k] = cheby2(n, Rs, Ws);
[sos,g] = zp2sos(z,p,k);
That worked with the random signal I used for ‘filter_x11’.
Also, I appreciate your quoting my code. My later code using ellliptical filters is significantly better than my eariler code.
Kathleen Nicole Rice
Kathleen Nicole Rice 2019 年 6 月 19 日
It works! Thank you so much- you have been extremely helpful! :)
Star Strider
Star Strider 2019 年 6 月 19 日
As always, my pleasure!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeApplications についてさらに検索

製品

リリース

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by