Can u use filtfilt with structfun?

4 views (last 30 days)
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);

Accepted Answer

Rik
Rik on 11 Aug 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 Comment
Simon Hoffmann
Simon Hoffmann on 11 Aug 2021
This works just fine, thank you for your fast reply!

Sign in to comment.

More Answers (1)

Chunru
Chunru on 11 Aug 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!