%% $RCSfile: sdsprms.tlc,v $ %% $Revision: 1.6 $ %% $Date: 2000/06/15 20:37:48 $ %% %% Copyright 1995-2000 The MathWorks, Inc. %% %% Abstract: Find the rms value of a vector %implements sdsprms "C" %% Function: BlockInstanceSetup =============================================== %% %function BlockInstanceSetup(block, system) void %% % % % % %% %endfunction %% BlockInstanceSetup %% Function: InitializeConditions ============================================= %% %function InitializeConditions(block, system) Output %% %assign running = LibBlockParameterValue(Running,0) != 0 %% %if running /* DSP Blockset Rms (%) - % */ %% % = 0.0; %% %endif %endfunction %% InitializeConditions %% Function: Outputs ========================================================== %% %function Outputs(block, system) Output /* DSP Blockset Rms (%) - % */ %% %assign INPORT_DATA = 0 %assign INPORT_RESET = 1 %assign OUTPORT = 0 %% %assign running = LibBlockParameterValue(Running,0) != 0 %assign cplx = (LibBlockInputSignalIsComplex(INPORT_DATA) != 0) %assign contig = IsInputPortContiguous(block, INPORT_DATA) %assign width = LibDataInputPortWidth(INPORT_DATA) %assign dtype = cplx ? "creal_T" : "real_T" %% %if !running %% %% Not Running %% %if width==1 %% %% When width is 1, the rms output equals the input %% /* width1 */ %assign y = LibBlockOutputSignal(OUTPORT, "", "", 0) %assign u = LibBlockInputSignal(INPORT_DATA, "", "", 0) %if !cplx % = fabs(%); %else CABS(%, %); %endif %else %% { real_T sx2 = 0.0; %assign rollVars = ["U"] %roll sigIdx = RollRegions, lcv = RollThreshold,\ block, "Roller", rollVars %assign u = LibBlockInputSignal(0, "", lcv, sigIdx) %if !cplx sx2 += % * %; %% REAL %else sx2 += CMAGSQ(%); %% COMPLEX %endif %endroll % = sqrt(sx2 / %); } %endif %% if width==1 %else %% %% Running %% %assign resetport = LibBlockParameterValue(ResetPort,0) != 0 %assign framebased = LibBlockParameterValue(Framebased,0) != 0 %assign nchans = framebased ? CAST("Number",LibBlockParameterValue(Nchans,0)) : width %assign nsamps = width/nchans %% /* Output running rms value */ %if (!contig) % %endif %% { real_T *msqsum = %; real_T *iter_cnt = %; %if resetport if(% != 0.0) { /* Reset iteration count. */ *iter_cnt = 0.0; } %endif %% if(*iter_cnt == 0.0) { /* Clear the current sum. */ %if nchans!=1 int_T i = %; while(i-- > 0) { *msqsum++ = 0.0; } msqsum -= %; /* Reset the pointer */ %else *msqsum = 0.0; %endif } *iter_cnt += %; %% %if width ==1 %assign u = LibBlockInputSignal(INPORT_DATA,"","", 0) %if !cplx *msqsum += % * %; %% REAL %else *msqsum += CMAGSQ(%); %% COMPLEX %endif % = sqrt(*msqsum / *iter_cnt); %else { % *u = %; real_T *y = %; real_T den = 1.0 / *iter_cnt; %if nchans != 1 int_T i = %; while(i-- > 0) { %endif %% %if nsamps !=1 real_T tsqsum = *msqsum; int_T j = %; while(j-- > 0) { const % val = *u++; %if !cplx tsqsum += val * val; %% REAL %else tsqsum += CMAGSQ(val); %% COMPLEX %endif } *msqsum++ = tsqsum; *y++ = sqrt(tsqsum * den); %else % val = *u++; %if !cplx *msqsum += val * val; %% REAL %else *msqsum += CMAGSQ(val); %% COMPLEX %endif *y++ = sqrt((*msqsum++) * den); %endif %% %if nchans != 1 } %endif } %endif } %endif %endfunction %% [EOF] sdsprms.tlc