How can I plot a data set after applying cascaded filter?
5 views (last 30 days)
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
Mathieu NOE on 19 Jul 2021
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
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);
Sanket Sane on 19 Jul 2021
Edited: Sanket Sane on 19 Jul 2021
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).