Effacer les filtres
Effacer les filtres

Can u use filtfilt with structfun?

1 vue (au cours des 30 derniers jours)
Simon Hoffmann
Simon Hoffmann le 11 Août 2021
Commenté : Simon Hoffmann le 11 Août 2021
I needed to segregate my signal due to noise in several parts of a long-term measuremt, which is why the remaining section have different lengths (which is why i am using a struct). Now i want to filter the signal parts with a cheby type 2 IIR filter, but i get the error:
"Invalid expression. When calling a function or indexing a variable, use parentheses. Otherwise, check for mismatched delimiters."
% High-Pass filter with 0.4Hz Stopband-Frequency to remove the dc offset and trend from raw data
cheby_hp = designfilt('highpassiir', 'FilterOrder', 10, 'StopbandFrequency', 0.4, 'StopbandAttenuation', 80, 'SampleRate', 200);
% Detrend with IIR-HP filter
phases_struct_hp_filtered = structfun(@filtfilt(cheby_hp), phases_struct_appended,'UniformOutput', false);

Réponse acceptée

Rik
Rik le 11 Août 2021
You need to use either a function handle, or create an anonymous function. Your syntax does neither. Try this modification.
% High-Pass filter with 0.4Hz Stopband-Frequency to remove the dc offset and trend from raw data
cheby_hp = designfilt('highpassiir', 'FilterOrder', 10, 'StopbandFrequency', 0.4, 'StopbandAttenuation', 80, 'SampleRate', 200);
% Detrend with IIR-HP filter
phases_struct_hp_filtered = structfun(@(x) filtfilt(cheby_hp,x), phases_struct_appended,'UniformOutput', false);
  1 commentaire
Simon Hoffmann
Simon Hoffmann le 11 Août 2021
This works just fine, thank you for your fast reply!

Connectez-vous pour commenter.

Plus de réponses (1)

Chunru
Chunru le 11 Août 2021
cheby_hp = designfilt('highpassiir', 'FilterOrder', 10, 'StopbandFrequency', 0.4, 'StopbandAttenuation', 80, 'SampleRate', 200);
% Detrend with IIR-HP filter
phases_struct_appended.n1 = randn(70,1);
phases_struct_appended.n2 = randn(40,1);
phases_struct_hp_filtered = structfun(@(x)filtfilt(cheby_hp, x), phases_struct_appended,'UniformOutput', false);
phases_struct_hp_filtered
phases_struct_hp_filtered = struct with fields:
n1: [70×1 double] n2: [40×1 double]

Community Treasure Hunt

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

Start Hunting!

Translated by