%% $RCSfile: sdspuencode.tlc,v $ %% $Revision: 1.3 $ %% $Date: 1999/04/29 17:04:17 $ %% %% Copyright (c) 1995-98 by The MathWorks, Inc. %% %% Abstract: Uniformly quantizes and encodes input into N-bits. %implements sdspuencode "C" %include "dsplib.tlc" %include "dsp_intbounds.tlc" %% Function: BlockInstanceSetup ================================================ %function BlockInstanceSetup(block, system) void %% %assign INPORT = 0 %assign OUTPORT = 0 %assign block = block + INPORT + OUTPORT %% %assign fcnUnsigned = 1 %assign fcnSigned = 2 %% %assign isDouble = (LibBlockInputSignalDataTypeId(INPORT) == tSS_DOUBLE) %assign dtype_cast = isDouble ? "Real" : "Real32" %assign isSigned = (CAST("Number",SFcnParamSettings.ISSIGN[0]) == fcnSigned) %assign Nbits = CAST("Number",SFcnParamSettings.NBITS[0]) %assign Nbytes = (Nbits <= 8) ? 1 : ((Nbits <= 16) ? 2 : 4) %% %% TLC Cast for parameters: V,T are of type dtype_cast (double or single) %assign V = CAST(dtype_cast,SFcnParamSettings.PEAK[0]) %assign T = CAST(dtype_cast,FEVAL("pow2", Nbits)/(2*V)) %% T = (2^N)/(2*V) %% %% I/O Datatype casts: %assign dtype_in = isDouble ? "real64_T" : "real32_T" %if (isSigned) %assign dtype_out = (Nbytes==1) ? "int8_T" : ((Nbytes==2) ? "int16_T" : "int32_T") %else %assign dtype_out = (Nbytes==1) ? "uint8_T" : ((Nbytes==2) ? "uint16_T" : "uint32_T") %endif %% %assign block = block + isSigned + Nbits + V + T + dtype_in + dtype_out %endfunction %% Function: Outputs ========================================================== %% %function Outputs(block, system) Output /* DSP Blockset Uniform Encoder (%) - % */ % \ %if isSigned % \ %endif %assign isCplx = (LibBlockInputSignalIsComplex(INPORT) != 0) %assign isContig = IsInputPortContiguous(block,INPORT) { %% % *y = (% *)%; const % V = %; /* Peak */ const % T = %; /* 2^N /(2*V) */ %% %if isContig %% %% Contiguous input: %% %assign width = LibDataInputPortWidth(INPORT) %if isCplx /* Treating contiguous complex input as a real double length input */ %assign width = width*2 %endif %% % *uptr = (% *)(%); %% int_T i1; for (i1=0; i1<%; i1++) { %% % u = ((*uptr++) + V) * T; % } %else %% %% Discontiguous input: %% %assign rollVars = ["U"] %roll sigIdx = RollRegions, lcv = RollThreshold, block, "Roller", rollVars %if !isCplx % %else % %endif %endroll %endif } %endfunction %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% Local functions: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% Function: ScalarToInt %% %% Saturate scalar input and cast to output data type. %% This function is call directly in the contiguous case %% and by Real and Complex functions in the discontiguous case. %% %function ScalarToInt(block) Output %% %if isSigned %assign LowerBoundMacro = IntBoundMacroName(1,Nbits,"MIN") %assign UpperBoundMacro = IntBoundMacroName(1,Nbits,"MAX") u += %; %else %assign LowerBoundMacro = IntBoundMacroName(0,Nbits,"MIN") %assign UpperBoundMacro = IntBoundMacroName(0,Nbits,"MAX") %endif if (u < %) u = %; else if (u > %) u = %; *y++ = (%)floor((real64_T)u); %% %endfunction %% ScalarToInt %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% Function: RealToInt %% %% Quantize input by: u = (u+V)*T, and then call ScalarToUnsignInt %% to saturate and cast. This function is called only in the %% discontiguous, real inputs. %% %function RealToInt(block,lcv,sigIdx) Output { % u = (% + V)*T; % } %% %endfunction %% RealToUnsignInt %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% Function: CplxToInt %% %% Quantize input by: u = (u+V)*T, and then call ScalarToUnsignInt %% to saturate and cast. This function is called only in the %% discontiguous, complex inputs. The complex inputs are separated %% into real and imaginary components and processed separatly. %% %function CplxToInt(block,lcv,sigIdx) Output { % u = (%%")> + V)*T; % u = (%%")> + V)*T; % } %endfunction %% CplxToUnInt %% [EOF] sdspuencode.tlc