How to go from filter designer to C/C++ Code
17 views (last 30 days)
Show older comments
I am now being acostumed to using the Filter Builder GUI to create a simple or complex filter function. I need to implement this on a DSP chip, I think the first natural step is to get it to work on my sandbox on my Host Computer, I havent found a simple way to get the C code, I have tried to used Matlab Coder but built int function like 'fdesign.lowpass'
I have also used Filter Designer to get the SOS and G coefficients for the filter, but I am failing to get a hold on code that will apply the filtering just by adding the coeficients.
Another requirement as is normal in DSP aplications, is that the function needs to work on a pre-defined number of samples at a time.
function y = doFilter(x)
%DOFILTER Filters input x and returns output y.
% MATLAB Code
% Generated by MATLAB(R) 9.1 and the DSP System Toolbox 9.3.
% Generated on: 14-Feb-2019 10:31:58
persistent Hd;
if isempty(Hd)
Fpass = 9000; % Passband Frequency
Fstop = 10000; % Stopband Frequency
Apass = 1; % Passband Ripple (dB)
Astop = 30; % Stopband Attenuation (dB)
Fs = 44100; % Sampling Frequency
h = fdesign.lowpass('fp,fst,ap,ast', Fpass, Fstop, Apass, Astop, Fs);
Hd = design(h, 'equiripple', ...
'MinOrder', 'any', ...
'StopbandShape', 'flat');
set(Hd, 'Arithmetic', 'single');
set(Hd,'PersistentMemory',true);
end
y = filter(Hd,x);
0 Comments
Answers (0)
See Also
Categories
Find more on Digital Filter Analysis in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!