MATLAB: How to generate C code of the transfer function from Filter designer app
Signal Processing Toolbox
Do we have provision to generate C code of the transfer function from Filter designer app?
Best Answer
There is no direct way to generate C/C++ code for a transfer function from filterDesigner but you can generate MATLAb code from the app and then use MATLAB coder app to generate C/C++ code.
When you are trying to generate MATLAB code from the app, you will see three different options to do that.
1) Filter Design Function.
2) Filter Design Function (with System Objects)
3) Data Filtering Function (with System Objects)
If you generate MATLAB code with the first two options, the resulting MATLAB code will not be codgen compatible.
The MATLAB code generated with option 3 is codegen compatible. Once the code is generated, use the MATLAB coder app to go through with further process to generate C/C++ code.
Not sure if this is what you want, but if you go to File -> Generate MATLAB Code, there is an option to generate a data filtering function. If you save that function as saymyfilter.m, then you can get the filtered signal by calling
Look under File -> Generate Matlab Code -> Filter Design Function. If I choose that option and then make some adjustments in the output file (code generation does not support dfilt objects or fdesign as you discovered)
function b = myfilter %#codegen
%MYFILTER Returns a discrete-time filter object.
%
% MATLAB Code
% Generated by MATLAB(R) 7.14 and the Signal Processing Toolbox 6.17.
%
% Generated on: 01-Jul-2012 05:38:14
%
% Equiripple Lowpass filter designed using the FIRPM function.
% All frequency values are normalized to 1.
Fpass = 0.45; % Passband Frequency
Fstop = 0.55; % Stopband Frequency
Dpass = 0.057501127785; % Passband Ripple
Dstop = 0.001; % Stopband Attenuation
dens = 20; % Density Factor
% Calculate the order from the parameters using FIRPMORD.
Best Answer