Generating C code from MATLAB functions

4 次查看(过去 30 天)
Hello,
I have two functions in MATLAB. One of them implements a filter for some signals and I really need this. I have an APP in android studio, and I'm trying to generate C code from these two functions so I can use them in my APP, but when I do this, I have some functions that are not supported in C.
First, this is my filter code:
function Hd = hpfilter
Fs = 1000; % Sampling Frequency
Fstop = 0.4; % Stopband Frequency
Fpass = 0.8; % Passband Frequency
Astop = 60; % Stopband Attenuation (dB)
Apass = 1; % Passband Ripple (dB)
match = 'passband'; % Band to match exactly
% Construct an FDESIGN object and call its ELLIP method.
h = fdesign.highpass(Fstop, Fpass, Astop, Apass, Fs);
Hd = design(h, 'cheby2', 'MatchExactly', match);
end
And it says the functions design and fdesign.highpass are not supported. I tried using coder.ceval, but then it says it doesn't recognize the type of my variable h.
In my other function, the unsupported variables are:
pwelch and periodogram
Do you know if I can replace them with any others that are supported with the same result? or any suggestions for it to work?
Thank you a lot!

回答(2 个)

Honglei Chen
Honglei Chen 2017-10-25
Could you share which release are you using? Looks like your script is generated from filterDesigner (or FDAToll)? If you are using recent releases, you can choose 'Generate MATLAB Code' -> 'Data Filtering Function' to get the code that supports code generation.
If your release doesn't support this, you may want to use coder.extrinsic to compute the coefficients and then use filter() function to filter the data, that should work too.
pwelch and periodogram don't support code generation yet, but periodogram is simply the magnitude square of FFT so you can just use fft, which supports code generation, to compute it.
HTH

Sean de Wolski
Sean de Wolski 2017-10-25
You could use the dsp.SpectrumEstimator which does the same thing as pwelch and supports code generation.
  4 个评论
Sean de Wolski
Sean de Wolski 2017-10-26
Something along these lines, not tested in ML:
pest = dsp.SpectrumEstimator('Window',rectwin(length(x)),'SampleRate',fs,'FFTLength',N)
f = getFrequencyVector(pest)
p = pest(x);
User 864
User 864 2017-10-26
编辑:User 864 2017-10-26
I tried it but it shows me an error saying: Error using matlab.system.StringSet/findMatch Invalid setting for the Window property. And it also says: getFrequencyVector before locking the object is not supported.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 C Code Generation 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by