MATLAB: Generate C code from a filter which created by fdatool or filterbuilder

filter

Hello everyone, Can I generate C code from a fileter which created by fdatool or filterbuilder. For example, I have created a lowpass filter with filterbuilder, and it works well in matlab. Now,I hope matlab can generate c code for this filter, so I can use this filter in my DSP board. I am looking for some simple examples. Thank you.

Best Answer

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.
[N, Fo, Ao, W] = firpmord([Fpass, Fstop], [1 0], [Dpass, Dstop]);
% Calculate the coefficients using the FIRPM function.
b = firpm(N, Fo, Ao, W);
I am able to generate C code