필터 지우기
필터 지우기

Efficient decimation with Embedded Coder

조회 수: 3 (최근 30일)
Jim Clay
Jim Clay 2012년 11월 7일
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?

채택된 답변

Fred Smith
Fred Smith 2012년 11월 12일
If you could make all occurrences of dcsDec the same size then you would only get one variable.
If that is not possible, you could use variable-sizing. Use coder.varsize('dcsDec',[1 1331]), and that should also force a single variable dcsDec but it will carry run-time size information.
Hope one of these two ideas helps.
-fred
  댓글 수: 1
Jim Clay
Jim Clay 2012년 11월 12일
The coder.varsize method worked very nicely. Thank you.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Multirate Signal Processing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by