%% $RCSfile: sdspmdn.tlc,v $ %% $Revision: 1.7 $ %% $Date: 2000/06/15 20:37:43 $ %% %% Copyright 1995-2000 The MathWorks, Inc. %% %% Abstract: Output the median value of an input vector %implements sdspmdn "C" %openfile buffer /* DSP Blockset Median Block dependencies: */ extern void qid_RecSort(const real_T *qid_array, int_T *qid_index, int_T i, int_T j); %closefile buffer % %% Function: BlockInstanceSetup =============================================== %% %function BlockInstanceSetup(block, system) void %% %assign INPORT = 0 %assign width = LibDataInputPortWidth(INPORT) % %endfunction %% BlockInstanceSetup %% Function: InitializeConditions ============================================= %% %function InitializeConditions(block, system) Output /* DSP Blockset Median (%) - % */ %% %assign INPORT = 0 %assign width = LibDataInputPortWidth(INPORT) %% { int_T i; for (i=0; i < %; i++) { % = i; } } %endfunction %% InitializeConditions %% Function: Outputs ========================================================== %% %function Outputs(block, system) Output /* DSP Blockset Median (%) - % */ %% %assign INPORT = 0 %assign OUTPORT = 0 %% %assign cplx = (LibBlockInputSignalIsComplex(INPORT) != 0) %assign contig = IsInputPortContiguous(block, INPORT) %assign N = LibDataInputPortWidth(INPORT) %assign dtype = cplx ? "creal_T" : "real_T" %% %if !contig % %else %if N != 1 %% %% Only sort if the input width is greater than one. %% %if !cplx %% %% REAL %% /* Sort input vector: */ qid_RecSort(%, \ &%, 0, %); %else %% %% COMPLEX %% { /* Copy magnitude of complex input values into temp scratch area: */ real_T *sort_in = %; %assign rollVars = ["U"] %roll sigIdx = RollRegions, lcv = RollThreshold, block, "Roller", rollVars *sort_in++ = CMAGSQ(%); %endroll %% /* Sort input vector: */ qid_RecSort(sort_in - %, &%, 0, %); } %endif %endif %endif %% %if (N % 2 == 0) /* Even number of elements - interpolate: */ %% %if !cplx %% %% REAL %% %assign u0 = LibBlockInputSignal(INPORT, "%", "", 0)>", "", "") %assign u1 = LibBlockInputSignal(INPORT, "%", "", 0)>", "", "") %% % = 0.5 * (% + %); %else %% %% COMPLEX %% %assign u0re = LibBlockInputSignal(INPORT, "%", "", 0)>", "", "%") %assign u0im = LibBlockInputSignal(INPORT, "%", "", 0)>", "", "%") %assign u1re = LibBlockInputSignal(INPORT, "%", "", 0)>", "", "%") %assign u1im = LibBlockInputSignal(INPORT, "%", "", 0)>", "", "%") %% %0")> = 0.5 * (% + %); %0")> = 0.5 * (% + %); %endif %% %else %% %% REAL AND COMPLEX uses same code in this case %% % = \ %", "", 0)>","", 0)>; %endif %endfunction %% [EOF] sdspmdn.tlc