filtfilt() function with Matlab Coder
Show older comments
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 Comment
Mike Hosea
on 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?
Answers (1)
feng cai
on 2 Jul 2021
0 votes
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.
Categories
Find more on Digital Filter Design in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!