Effacer les filtres
Effacer les filtres

Using coefficients from designNotchPeakIIR generated an error message

6 vues (au cours des 30 derniers jours)

I used designNotchPeakIIR function to calculate coefficients of N-order notch filter. The size of both a and b are N/2-by-3. Unfortunately, I could not use them in filtfilt function because this function requires a vector input. Anyone has a solution for me?

  1 commentaire
Hany Ferdinando
Hany Ferdinando le 12 Jan 2024
I got the solution recently,
notchFilter = designNotchPeakIIR('Response', 'notch', 'CenterFrequency', wo, 'Bandwidth', bw, 'FilterOrder', 50, "SystemObject", true, "HasScaleValues", true);
s_cleaned = notchFilter(s_cleaned);
I added those parameters and use the output as a function.

Connectez-vous pour commenter.

Réponse acceptée

Star Strider
Star Strider le 12 Jan 2024
The filtfilt function needs a 6-column second-order-section matrix and a scale factor. The matrix can be created by horizontally concatenating the Numerator and Denominator matrices. That (and fudging the scale factor) satisfies filtfilt, and then it (and freqz as well) work.
Try this —
wo = 0.25;
bw = 0.01;
notchFilter = designNotchPeakIIR('Response', 'notch', 'CenterFrequency', wo, 'Bandwidth', bw, 'FilterOrder', 50, "SystemObject", true, "HasScaleValues", true)
notchFilter =
dsp.SOSFilter with properties: Structure: 'Direct form II transposed' CoefficientSource: 'Property' Numerator: [25×3 double] Denominator: [25×3 double] HasScaleValues: true ScaleValues: [26×1 double] Use get to show all properties
% s_cleaned = notchFilter(s_cleaned)
figure
freqz([notchFilter.Numerator, notchFilter.Denominator], 2^16)
s_in = randn(10000, 1);
s_out = filtfilt([notchFilter.Numerator, notchFilter.Denominator], 0.88, s_in);
[p_in,f_in] = pspectrum(s_in);
[p_out,f_out] = pspectrum(s_out);
TrFn = p_out ./ p_in;
% F = [f_in f_out]
figure
plot(f_in, p_in)
hold on
plot(f_out, p_out)
hold off
grid
xlabel('Normalised Frequency')
ylabel('Magnitude')
title('Filter Results')
figure
plot(f_in, pow2db(TrFn/max(TrFn)), '-g')
grid
xlabel('Normalised Frequency')
ylabel('Magnitude')
title('Transfer Function')
axis('padded')
I do not have the DSP Toolbox, so I just experimented until I got an approach that works. This seems to do what you want.
.
  2 commentaires
Hany Ferdinando
Hany Ferdinando le 12 Jan 2024
Thanks @Star Strider, it worked. You knew precisely what I need.
I opened filtfilt documenation and found that 0.88 is scale factor. How did you get this number? Also, is it possible to tweaks this notch filter to reduce the attenuation? Thus, not completely suppressed the center frequency.
s_out = filtfilt([notchFilter.Numerator, notchFilter.Denominator], 0.88, s_in);
Star Strider
Star Strider le 12 Jan 2024
My pleasure!
I just guessed ast the scale factor until I got something that looked right. The Signal Processing Toolbox normally calculates this on its own, and I never explored it to determine how it does that calculation.
I do not have the DSP Toolbox, so I have very little experience with it (only here on Answers where I have limited access to its functions). I do not see any option for changing the stopband attenuation, unlike the Signal Processing Toolbox functions that allow this. The DSP toolbox may have a GUI tool that can help with this.
Otherwise, design it in the Signal Ptocessing Toolbox (an elliptc filter is likely the most efficient, although it may not be best for your application, since it appears to me to be a Butterworth design), and then split the ‘sos’ matrix into two (Nx3) matrices to form the numerator and denominator matrces for DSP Toolbox compatibility (assuming that is the only relevant compatibility consideration). That is probably the only available option.

Connectez-vous pour commenter.

Plus de réponses (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by