How to go from filter designer to C/C++ Code

17 ビュー (過去 30 日間)
Dario Vazquez
Dario Vazquez 2019 年 2 月 14 日
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 件)

カテゴリ

Help Center および File ExchangeDigital Filter Analysis についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by