filtfilt() function with Matlab Coder

조회 수: 1 (최근 30일)
Philipp Lessnau
Philipp Lessnau 2017년 9월 6일
답변: feng cai 2021년 7월 2일
Hello,
I am trying to get the Matlab Coder to convert my matlab code to C code.
And there is a problem with the filtfilt() function I do not understand.
The error that the Coder gives me is the following: "The numerator coefficients B and denominator coefficients A must be constant."
I get the coefficients from a butterworth filter, so basically I do the following:
[b, a] = butter(n,Wn,'low');
euler(:,3) = filtfilt(b,a,euler(:,3));
I even tried just grabbing the values and define a and b before calling the function like this:
a = [1 -3.37801139459687 4.75177537470702 -3.43971331083559 1.27399988148292 -0.192388596001173];
b = [0.000489436086134679 0.00244718043067339 0.00489436086134679 0.00489436086134679 0.00244718043067339 0.000489436086134679];
euler(:,3) = filtfilt(b,a,euler(:,3));
But it still gives me the same error. I really don't know how to make this work, can somebody please help me?
  댓글 수: 1
Mike Hosea
Mike Hosea 2017년 9월 6일
I don't understand it, either. This works fine for me in 16b:
function e = tff(e)
n = 5;
Wn = .3;
[b, a] = butter(n,Wn,'low');
e = filtfilt(b,a,e);
The variables n and Wn are constant, right? Are you re-using the variables a and b for other purposes? Used coder.varsize on these variable names?

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

답변 (1개)

feng cai
feng cai 2021년 7월 2일
if the code like this:
b and a is defined outside the function bandpass
function filt_data = bandpass(b,a,data)
filt_data = filtfilt(b,a,data);
end
Error: The numerator coefficients B and denominator coefficients A must be constant.
----------------------------------------------------------------------------------
if the code like this:
function filt_data = bandpass(data)
a = [1,-2.86834067990259,3.20377999626534,-1.70427191678698,0.378619299408443];
b= [0.0790937181169893,0,-0.158187436233979,0,0.0790937181169893];
filt_data = filtfilt(b,a,data);
end
Source Code generation succeeded.

카테고리

Help CenterFile Exchange에서 Time-Frequency Analysis에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by