Can u use filtfilt with structfun?

조회 수: 2 (최근 30일)
Simon Hoffmann
Simon Hoffmann 2021년 8월 11일
댓글: Simon Hoffmann 2021년 8월 11일
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);

채택된 답변

Rik
Rik 2021년 8월 11일
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
Simon Hoffmann
Simon Hoffmann 2021년 8월 11일
This works just fine, thank you for your fast reply!

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

추가 답변 (1개)

Chunru
Chunru 2021년 8월 11일
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]

카테고리

Help CenterFile Exchange에서 Digital Filtering에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by