I've tested the "Verify FIR Filter on ARM Cortex-M Processor in MATLAB" example, which works fine and generates CMSIS-DSP function calls so I'm fairly certain all of the dependent packages are installed correctly: https://uk.mathworks.com/help/supportpkg/armcortexm/ref/Verify-FIR-Filter-on-ARM-Cortex-M-Processor-in-MATLAB-example.html
I've modified it to use a 256 point FFT, using DSP.fft() and abs(), and I'm hoping to generate code calling arm_rfft_fast_f32() and arm_abs_f32().
I'm observing two problems, with the compiled code, that I've been going round in circles trying to resolve, for days.
1/ arm_rfft_fast_f32() and arm_abs_f32() are not being called.
2/ The return array (X) is being declared as the maximum stack allocation size (65536), even if I pre-declare it using zeros() or coder.nullcopy(), so is eating up too much memory:
void ec_fft(const double x[256], double X[65536])
static creal_T Y0[65536];
The test code is listed below. Its very short but the full source code is in the attachment.
Any help would be most appreciated.
Thanks very much,
John
FFT Function: (ec_fft.m)
function [X]=ec_fft(x)
persistent ft;
if isempty(ft)
ft = dsp.FFT('FFTLengthSource','Property','FFTLength',256);
end
X = abs(ft(x));
end
Test App: (ec_fft_test.m)
Fs = 1000;
L = 256;
t = (0:L-1)'/Fs;
x = cos(2*pi*250*t);
X = coder.nullcopy(x);
X = ec_fft(x);
plot(Fs/2*linspace(0,1,128), X(1:128))
title('Single-sided amplitude spectrum of noisy signal y(t)')
xlabel('Frequency (Hz)'); ylabel('|X(f)|')
Script For Creating Library (run_codegen_arm.m):
ec_fft_test
cfgEx = coder.config('lib');
cfgEx.CodeReplacementLibrary = 'ARM Cortex-M';
cfgEx.HardwareImplementation.ProdHWDeviceType = 'ARM Compatible->ARM Cortex-M';
cfgEx.GenCodeOnly = true;
codegen -d ec_fft_lib ec_fft.m -report -rowmajor -config cfgEx -args {zeros(1,256)}