filtfilt() function with Matlab Coder

1 Ansicht (letzte 30 Tage)
Philipp Lessnau
Philipp Lessnau am 6 Sep. 2017
Beantwortet: feng cai am 2 Jul. 2021
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 Kommentar
Mike Hosea
Mike Hosea am 6 Sep. 2017
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?

Melden Sie sich an, um zu kommentieren.

Antworten (1)

feng cai
feng cai am 2 Jul. 2021
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.

Kategorien

Mehr zu Time-Frequency Analysis finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by