%% $RCSfile: sdspconv2.tlc,v $ %% $Revision: 1.3 $ $Date: 2000/06/15 20:37:39 $ %% %% Copyright 1995-2000 The MathWorks, Inc. %% %% Abstract: Target file for the S-Function sdsp2norm.c %% %implements "sdspconv2" "C" %% Function: Outputs ========================================================== %% %% Abstract: %% %function Outputs(block, system) Output /* DSP Blockset Convolution (%) - % */ %% %assign INPORTA = 0 %assign INPORTB = 1 %assign OUTPORT = 0 %% %assign framebased = LibBlockOutputSignalIsFrameData(OUTPORT) %assign cmplxA = LibBlockInputSignalIsComplex(INPORTA) %assign cmplxB = LibBlockInputSignalIsComplex(INPORTB) %% %assign nDimsA = LibBlockInputSignalNumDimensions(INPORTA) %assign dimsA = LibBlockInputSignalDimensions(INPORTA) %assign widthA = LibDataInputPortWidth(INPORTA) %assign nRowsA = framebased ? dimsA[0] : widthA %assign nColsA = framebased ? dimsA[1] : 1 %% %assign nDimsB = LibBlockInputSignalNumDimensions(INPORTB) %assign dimsB = LibBlockInputSignalDimensions(INPORTB) %assign widthB = LibDataInputPortWidth(INPORTB) %assign nRowsB = framebased ? dimsB[0] : widthB %assign nColsB = framebased ? dimsB[1] : 1 %% %assign nDimsOut = LibBlockOutputSignalNumDimensions(OUTPORT) %assign dimsOut = LibBlockOutputSignalDimensions(OUTPORT) %assign widthOut = LibDataOutputPortWidth(OUTPORT) %assign nRowsOut = framebased ? dimsOut[0] : widthOut %assign nColsOut = framebased ? dimsOut[1] : 1 %% %% If a port has a single channel then don't move the pointer to the next channel. %assign GotoNextChanA = (framebased && nColsA == 1) %assign GotoNextChanB = (framebased && nColsB == 1) %assign GotoNextChanAstr = GotoNextChanA ? "" : " + (c * nRowsA)" %assign GotoNextChanBstr = GotoNextChanB ? "" : " + (c * nRowsB)" %% %% %if !cmplxA && !cmplxB %% Both ports are real: { const int_T nRowsA = %; const int_T nRowsB = %; const int_T nRowsOut = %; real_T *y = %; %% %if nColsOut > 1 real_T *uA0 = %; real_T *uB0 = %; real_T *uA; real_T *uB; const int_T nColsOut = %; int_T c; for (c=0; c; uB = uB0%; %else real_T *uA = %; real_T *uB = %; %endif %% { int_T r; for (r = 0; r < nRowsOut; r++) { const int_T j_end = MIN(r, nRowsA-1); real_T sum = 0.0; int_T j; for (j = MAX(0, r-nRowsB+1); j <= j_end; j++) { sum += uA[j] * uB[r-j]; } *y++ = sum; } } %if nColsOut > 1 } %endif } %% %elseif cmplxA && cmplxB %% %% Both ports are complex: { const int_T nRowsA = %; const int_T nRowsB = %; const int_T nRowsOut = %; creal_T *y = %; %% %if nColsOut > 1 creal_T *uA0 = %; creal_T *uB0 = %; creal_T *uA; creal_T *uB; const int_T nColsOut = %; int_T c; for (c=0; c; uB = uB0%; %else creal_T *uA = %; creal_T *uB = %; %endif %% { int_T r; for (r = 0; r < nRowsOut; r++) { const int_T j_end = MIN(r, nRowsA-1); creal_T sum = {0.0, 0.0}; int_T j; for (j = MAX(0, r-nRowsB+1); j <= j_end; j++) { const creal_T val0 = uA[j]; const creal_T val1 = uB[r-j]; sum.re += CMULT_RE(val0, val1); sum.im += CMULT_IM(val0, val1); } *y++ = sum; } } %if nColsOut > 1 } %endif } %else { %% Mixed case (one port is complex, the other port is real) %% %% Two possible cases here: %% if c0 -> First port complex, second port real %% if c1 -> First port real, second port complex %% %% uA will always point to the complex input %% uB will always point to the real input %% creal_T *y = %; %% %if cmplxA %assign uA0 = LibBlockInputSignalAddr(INPORTA, "", "", 0) %assign uB0 = LibBlockInputSignalAddr(INPORTB, "", "", 0) %% const int_T nRowsA = %; const int_T nRowsB = %; %else %% We need to swap all port properties! %% %assign uA0 = LibBlockInputSignalAddr(INPORTB,"", "", 0) %assign uB0 = LibBlockInputSignalAddr(INPORTA,"", "", 0) %assign GotoNextChanTmp = GotoNextChanA %assign GotoNextChanA = GotoNextChanB %assign GotoNextChanB = GotoNextChanTmp %assign GotoNextChanAstr = GotoNextChanA ? "" : " + (c * nRowsA)" %assign GotoNextChanBstr = GotoNextChanB ? "" : " + (c * nRowsB)" %% const int_T nRowsA = %; const int_T nRowsB = %; %endif %% const int_T nRowsOut = %; %% %if nColsOut > 1 creal_T *uA0 = %; real_T *uB0 = %; creal_T *uA; real_T *uB; const int_T nColsOut = %; int_T c; for (c=0; c; uB = uB0%; %else creal_T *uA = %; real_T *uB = %; %endif %% { int_T r; for (r = 0; r < nRowsOut; r++) { const int_T j_end = MIN(r, nRowsA-1); creal_T sum = {0.0, 0.0}; int_T j; for (j = MAX(0, r-nRowsB+1); j <= j_end; j++) { const creal_T u0 = uA[j]; const real_T u1 = uB[r-j]; sum.re += u0.re * u1; sum.im += u0.im * u1; } *y++ = sum; } } %if nColsOut > 1 } %endif } %endif %endfunction %% Outputs %% EOF: sdspconv2.tlc