%% $RCSfile: sdspchirp.tlc,v $ %% $Revision: 1.5 $ $Date: 2000/06/15 20:37:39 $ %% %% Copyright 1995-2000 The MathWorks, Inc. %% %% Abstract: Target file for the S-Function sdspchirp.c %% Used for the Chirp Block %implements "sdspchirp" "C" %% Function: BlockInstanceSetup =============================================== %% %function BlockInstanceSetup(block, system) void %assign OUTPORT = 0 %% Tunable parameters %assign Tsw = LibBlockParameter(SweepPeriod, "", "", 0) %assign BETA = LibBlockParameter(Beta, "", "", 0) %% TargetTime only changes beta in the block mask, so it %% is not needed in the generated code. %% Non-tunable parameters %assign Sweep = SFcnParamSettings.Sweep %assign Mode = SFcnParamSettings.Mode %assign InitialFreq = SFcnParamSettings.InitialFreq %assign TargetFreq = SFcnParamSettings.TargetFreq %assign Delta = SFcnParamSettings.SampleTime %assign SamplesPerFrame = SFcnParamSettings.SamplesPerFrame %% Calculated parameters %assign Direction = TargetFreq - InitialFreq %if Direction < 0.0 %assign tmp = InitialFreq %assign InitialFreq = TargetFreq %assign TargetFreq = tmp %endif %% Sweep enumerations: %assign SWEPT_COSINE = 1 %assign LINEAR = 2 %assign LOGARITHMIC = 3 %assign QUADRATIC = 4 %assign ModeComment = (Mode==1) ? "Unidirectional" : "Bidirectional" %switch Sweep %case SWEPT_COSINE %assign SweepComment = "Swept cosine" %break %case LINEAR %assign SweepComment = "Linear" %break %case LOGARITHMIC %assign SweepComment = "Logarithmic" %break %case QUADRATIC %assign SweepComment = "Quadratic" %break %endswitch %assign ChirpComment = "/* % % */" %assign block = block + OUTPORT + Tsw + BETA + Sweep + Mode + ... InitialFreq + TargetFreq + ... Delta + SamplesPerFrame + Direction + ... SWEPT_COSINE + LINEAR + LOGARITHMIC + ... QUADRATIC + ChirpComment %endfunction %% BlockInstanceSetup %% Function: InitializeConditions ============================================================ %% Abstract: Initialize DWorks %% %function InitializeConditions(block, system) Output /* DSP Blockset Chirp (%) - % */ % %% %if Direction < 0.0 %assign d = -Delta %assign t = Tsw %else %assign d = Delta %assign t = 0.0 %endif %% % = %; % = %; %endfunction %% Function: Outputs ========================================================== %% %function Outputs(block, system) Output /* DSP Blockset Chirp (%) - % */ % %% %assign delta = LibBlockDWork(DELTA, "", "", 0) %assign t = LibBlockDWork(CURRENT_STEP, "", "", 0) { real_T *y = %; %if SamplesPerFrame > 1 const int_T samplesPerFrame = %; % \ int_T i; for(i=0; i %% % += %; /* Go to next time step */ % \ %% %if SamplesPerFrame > 1 } %endif } %endfunction %% Outputs %% Function: DefineParams =========================================== %% %function DefineParams(Sweep) Output %% %if(InlineParameters == 0) %switch(Sweep) %% %case LINEAR %case QUADRATIC %assign p = (Sweep==LINEAR) ? 2 : 3 %% real_T beta_div_p = %/%

; %break %% %case LOGARITHMIC %% real_T beta_log_10 = % * %; %break %% %case SWEPT_COSINE %break %endswitch %endif %endfunction %% Function: SweepOutput =========================================== %% %function SweepOutput(t) Output %% %% %assign yout = (SamplesPerFrame > 1) ? "*y++" : "*y" %assign phase = LibBlockParameter(Phase, "", "", 0) %% %% Optimize out parameters when possible %% Initial frequency is nontunable, so we can always optimize it's use %assign addInitFreq_x_t = (InitialFreq == 0) ? "" : " + (% * %)" %% %if (InlineParameters != 0) %assign addPhase = (% == 0.0) ? "" : " + %" %else %assign addPhase = " + " + phase %endif %% %% %switch(Sweep) %% %case LINEAR %case QUADRATIC %assign p = (Sweep==LINEAR) ? 2 : 3 %% %if (InlineParameters != 0) %assign beta_div_p = %/p %else %assign beta_div_p = (SamplesPerFrame > 1) ? "beta_div_p" : BETA + "/%

" %endif %% % = cos(TWO_PI_DOUBLE * (% * pow(%,%

)%)%); %break %% %case LOGARITHMIC %if (InlineParameters != 0) %assign beta_log_10 = %*% %else %assign beta_log_10 = (SamplesPerFrame > 1) ? "beta_log_10" : "%*%" %endif %% % = cos(TWO_PI_DOUBLE * ( (pow(10,%*%) - 1) / (%)%)%); %break %% %case SWEPT_COSINE % = cos(TWO_PI_DOUBLE * (% * % * %%)%); %break %endswitch %% %endfunction %% Function: CheckAndResetStep =========================================== %% %function CheckAndResetStep(t,delta) Output %% %% When the target time or zero is exceeded, the current step %% may have to be reset depeding on the freq mode parameter. %% %if(Mode==1) %% UNI_DIRECTIONAL %% %if(Direction > 0.0) %% UP if(% > %) { % = 0.0; } %else %% DOWN if(% < 0.0) { % = %; } %endif %else %% BI_DIRECTIONAL %% if(% > % || % < 0.0) { % = -%; /* Change direction */ } %endif %% %endfunction %% CheckAndResetStep %% [EOF] sdspchirp.tlc