%% $RCSfile: sdsp2norm2.tlc,v $ %% $Revision: 1.5 $ $Date: 2000/06/15 20:37:38 $ %% %% Copyright 1995-2000 The MathWorks, Inc. %% %% Abstract: Target file for the S-Function sdsp2norm2.c %% %implements "sdsp2norm2" "C" %% Function: BlockInstanceSetup =============================================== %% %function BlockInstanceSetup(block, system) void %assign INPORT = 0 %assign OUTPORT = 0 %% NormType enumerations: %assign NORM = 1 %assign NORMSQ = 2 %assign NumDims = LibBlockInputSignalNumDimensions(INPORT) %assign InDims = LibBlockInputSignalDimensions(INPORT) %assign InCols = (NumDims == 2) ? InDims[1] : 1 %assign InRows = InDims[0] %% %assign Bias = SFcnParamSettings.Bias %assign Sqr = CAST("Number", SFcnParamSettings.NormType) %assign framebased = LibBlockOutputSignalIsFrameData(OUTPORT) %if(!framebased && InRows == 1 && InCols != 1) %% Treat single rows as a column vector when not framebased %assign InRows = InCols %assign InCols = 1 %endif %assign cmplx = LibBlockOutputSignalIsComplex(OUTPORT) %assign DType = cmplx ? "creal_T" : "real_T" %assign block = block + INPORT + OUTPORT + ... NORM + NORMSQ + ... InCols + InRows + ... Sqr + Bias + ... cmplx + DType %endfunction %% BlockInstanceSetup %% Function: Outputs ========================================================== %% %% Abstract: Compute the norm of a vector %% %function Outputs(block, system) Output /* DSP Blockset Normalization (%) - % */ %% %assign inplace = (LibBlockInputSignalBufferDstPort(INPORT) == OUTPORT) { %if inplace % \ %else % \ %endif } %endfunction %% Outputs %% Function: NormCore ============================ %% %function NormCore( ) Output %% %if Bias == 0 %if Sqr == NORM /* Normalize input vector by 2-norm: */ E = 1.0 / sqrt(E); %else /* Normalize input vector by squared 2-norm: */ E = 1.0 / E; %endif %else %if Sqr == NORM /* Normalize input vector by 2-norm: */ E = 1.0 / (sqrt(E) + %); %else /* Normalize input vector by squared 2-norm: */ E = 1.0 / (E + %); %endif %endif %% %endfunction %% NormCore %% Function: NormInplace ============================ %% %function NormInplace( ) Output %% % *y = %; int_T inRows = %; %% %if InCols > 1 int_T inCols = %; int_T c; for(c=0; c 0; ) { %if !cmplx real_T u = *y++; E += u*u; %else const creal_T u = *y++; E += CMAGSQ(u); %endif } %% % \ %% y -= inRows; /* Back up to beginning of output column. */ for(i=inRows; i-- > 0; ) { %if !cmplx *y++ *= E; %else y->re *= E; (y++)->im *= E; %endif } %if InCols > 1 } %endif %% %endfunction %% NormInplaceReal %% Function: Norm =================================== %% %function Norm( ) Output %% % *y = %; % *u0 = %; int_T inRows = %; %% %if InCols > 1 int_T inCols = %; int_T c; for(c=0; c 0; ) { %if !cmplx real_T u = *u0++; E += u*u; %else const creal_T *u = u0++; E += CMAGSQ(*u); %endif } %% % \ %% u0 -= inRows; /* Back up to beginning of input column. */ for(i=inRows; i-- > 0; ) { %if !cmplx *y++ = *u0++ * E; %else const creal_T *u = u0++; y->re = u->re * E; (y++)->im = u->im * E; %endif } %if InCols > 1 } %endif %% %endfunction %% NormReal %% EOF: sdsp2norm2.tlc