Efficient decimation with Embedded Coder
Show older comments
I have the following code as part of a Matlab Function block in Simulink/Embedded Coder:
[dcsDec, state.dcsDec1FiltState] = filter(state.dcsDec1Filt, 1, state.phaseDiffBuf(1:numSampsToProcess), state.dcsDec1FiltState);
dcsDec = dcsDec(state.dcsDec1Factor:state.dcsDec1Factor:end);
[dcsDec, state.dcsDec2FiltState] = filter(state.dcsDec2Filt, 1, dcsDec, state.dcsDec2FiltState);
dcsDec = dcsDec(state.dcsDec2Factor:state.dcsDec2Factor:end);
[dcsDec, state.dcsDec3FiltState] = filter(state.dcsDec3Filt, 1, dcsDec, state.dcsDec3FiltState);
dcsDec = dcsDec(state.dcsDec3Factor:state.dcsDec3Factor:end);
state.dcsPhaseDiffBuf(state.dcsPhaseDiffBufLen+1:state.dcsPhaseDiffBufLen+length(dcsDec)) = dcsDec;
state.dcsPhaseDiffBufLen = state.dcsPhaseDiffBufLen + length(dcsDec);
I apologize for the ugly indexing, but the gist of it is that it is doing standard FIR filtering on a signal and then decimating it. The same buffer is reused to minimize the memory usage. The problem is that the D_Work global struct that Embedded Coder generates includes the following:
real_T dcsDec_data[1331];
real_T b_dcsDec_data[1328];
real_T c_dcsDec_data[1329];
real_T d_dcsDec_data[1330];
real_T c_dcsDec_data_m[1330];
real_T b_dcsDec_data_c[1329];
real_T state_data[1328];
real_T b_dcsDec_data_k[1331];
There are no other references to "dcsDec" in the Simulink model or Matlab code, so it appears to just be creating a new array for each iteration, without even recognizing that the arrays should be getting smaller. There has to be a better way to do this. What is the "right" way to do this with Embedded Coder?
Accepted Answer
More Answers (0)
Categories
Find more on Multirate Signal Processing 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!