MATLAB Answers

How can I plot a data set after applying cascaded filter?

조회 수: 2(최근 30일)
Soeun Lee
Soeun Lee 2021년 7월 19일
댓글: Mathieu NOE 2021년 7월 19일
I created a cascaded filter and applied it to my datasets. How can I plot the datasets after the filter is applied? I'm getting an error that says "Error using plot. Data must be numeric, datetime, duration or an array convertible to double". Please let me know what I can do to create the plot. Thank you in advance.
Wn=10; % low cutoff
Wn_2=[60 60];


Mathieu NOE
Mathieu NOE 2021년 7월 19일
hello Soeun
I did a couple of modifications / corrections in your code
please note that for the notch filter , the low and high cut off frequencies cannot be equal , so you have to give a non zero bandwith to your filter
also i reduced the order friom 5 to 2 as the bode plot was not correct in my opinion; I always wondered why the butter function would generate strange filters (sometimes unstable) with high orders. So as far as I can live with it , I stick to N = 2;
I generated some dummy data as I don't have yours
% X=RawData;
samples = 1e4;
t = (0:samples -1)'/Fs;
fn=10; % low cutoff
fn_2=[60-5 60+5]; % the low and high freqs must not coincide
figure(1),dbode(b1,a1,1/Fs); % debug / check filter is correct
figure(2),dbode(b2,a2,1/Fs); % debug / check filter is correct
out = filter(Hcas,X);
hold on
hold off
  댓글 수: 2
Mathieu NOE
Mathieu NOE 2021년 7월 19일
the butter filter needs frequencies being normalized by the Nyquist frequency (= Fs/2) and not the sampling frequency (Fs) . if you plot the Bode plot of the filters , you would have seen the factor 2 was lacking

댓글을 달려면 로그인하십시오.

Sanket Sane
Sanket Sane 2021년 7월 19일
편집: Sanket Sane 2021년 7월 19일
You cannot directly plot a filter object. Convert the filter to its representation in the frequency domain using the freqz function.
[h,w] = freqz(b, a, n)
Where h is the frequency response (vector of complex numbers), w is the normalized angular frequency, b and a are the transfer coefficients you obtained using butter, and n is the number of points.
Or you can use
[h,w] = freqz(d, n)
Where d is the digital filter. Eg. H1 in your case.
Use abs(h) to convert h to magnitude.
Another option is using
Which plots the frequency response magnitude in dB.
Then to filter your data, you can use.
Y = filter(b, a, X).

Community Treasure Hunt

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

Start Hunting!

Translated by