%% $RCSfile: sdsphist2.tlc,v $ %% $Revision: 1.4 $ %% $Date: 2000/06/15 20:37:41 $ %% %% Copyright 1995-2000 The MathWorks, Inc. %% %% Abstract: Histogram Block %implements sdsphist2 "C" %% Function: InitializeConditions ============================================= %% %function InitializeConditions(block, system) Output /* DSP Blockset Histogram (%) - % */ %% %% %assign isMinComplex = CAST("Boolean",(Min.ComplexSignal == "yes")) %assign isMaxComplex = CAST("Boolean",(Max.ComplexSignal == "yes")) %% %if isMinComplex %assign min_mag = CMAGSQ(%0")>,%0")>) %else %assign min_mag = LibBlockParameterValue(Min,0) %endif %% % = %; %% %if isMaxComplex %assign max_mag = CMAGSQ(%0")>,%0")>) %else %assign max_mag = LibBlockParameterValue(Max,0) %endif %% % = %; %% %assign running = CAST("Boolean",(SFcnParamSettings.isRunning == "Yes")) %assign normalize = CAST("Boolean",(SFcnParamSettings.isNorm == "Yes")) %assign Nbins = CAST("Real",SFcnParamSettings.Nbins) %% % = % / %; %% %if running %if normalize % = 0.0; %endif /* Set all histogram bin counts to zero: */ memset(%, 0, (uint32_T)(%)*sizeof(uint32_T)); %endif %endfunction %% InitializeConditions %% Function: Outputs ========================================================== %% %function Outputs(block, system) Output /* DSP Blockset Histogram (%) - % */ %% %assign INPORT_DATA = 0 %assign INPORT_RESET = 1 %assign OUTPORT = 0 %% %assign running = CAST("Boolean",(SFcnParamSettings.isRunning == "Yes")) %assign normalize = CAST("Boolean",(SFcnParamSettings.isNorm == "Yes")) %assign Nbins = SFcnParamSettings.Nbins %assign umin = LibBlockDWork(MinMag,"", "", 0) %assign umax = LibBlockDWork(MaxMag,"", "", 0) %assign idelta = LibBlockDWork(Idelta,"", "", 0) %% %assign isFullMatrix = LibBlockInputSignalIsFullMatrix(INPORT_DATA) %assign cplx = (LibBlockInputSignalIsComplex(INPORT_DATA) != 0) %assign dType = (cplx) ? "creal_T" : "real_T" %assign width = LibBlockInputSignalWidth(INPORT_DATA) %assign dims = LibBlockInputSignalDimensions(INPORT_DATA) %assign frame = LibBlockInputSignalIsFrameData(INPORT_DATA) %assign nChans = (frame || isFullMatrix) ? dims[1] : 1 %assign nSamps = (frame || isFullMatrix) ? dims[0] : width %% %% %% Running and Non-Running: %% { %% %if !running real_T *y = %; %else %% %% Block could be multirate if and only if it has more than %% one input port (eg, a reset input). If it is multirate, %% generate "sample hit" conditional so code executes at the %% block's base rate, and not the overall model base rate. %% %assign differentPortRates = !LibIsSFcnSingleRate(block) %% %if differentPortRates if (%) { % %endif uint32_T *h = %; %endif % *u = %; real_T val = 0.0; int_T i; %if !running /* Initialize all bins to zero: */ int_T n; for(n=0; n < %; n++) { y[n] = 0.0; } %endif %% Only have a reset port in Running mode. %assign isRstPort = CAST("Boolean",(SFcnParamSettings.isRstPort == "Yes")) %if isRstPort if (% != 0.0) { memset((void *)h, 0, %*sizeof(uint32_T)); %% %if normalize % = 0.0; %endif } %endif { %if nChans > 1 int_T k = %; while(k-- > 0) { %endif %if nSamps > 1 int_T j = %; while(j-- > 0) { %endif %if cplx val = sqrt(CMAGSQ(*u)); u++; %else val = *u++; %endif /* Update appropriate histogram bin: */ if (val <= %) { i = 0; } else if (val > %) { i = %; } else { i = (int_T)(ceil((val-%) * %) - 1); } %if !running (*(y + i))++; %else (*(h + i))++; %endif %if nSamps > 1 } %endif %if nChans > 1 %if !running y += %; %else h += %; %endif } %endif } %if (!running & normalize) %if nChans > 1 y -= %; %endif i = %; while (i-- > 0) { *y++ *= %<1.0 / nSamps>; %% scale = 1/framesize or 1/width } %endif %if running %if normalize { /* Copy normalized bin count to output: */ real_T *iter_cnt = %; real_T scale; int_T i; (*iter_cnt)++; scale = 1 / (*iter_cnt * %); %if nChans > 1 h -= %; %endif for(i=0; i < %; i++) { % = scale * (real_T)(*h++); } } %else { /* Copy unnormalized bin count to output: */ int_T i; %if nChans > 1 h -= %; %endif for (i=0; i < %; i++) { % = (real_T)(*h++); } } %endif %endif %if running %if differentPortRates } %endif %endif } %endfunction %% [EOF] sdsphist2.tlc