📄 gmsksimulation_acc.c
字号:
/*
* This file is not available for use in any application other than as a
* MATLAB(R) MEX file for use with the Simulink(R) Accelerator product.
*/
/*
* GMSKsimulation_acc.c
*
* Real-Time Workshop code generation for Simulink model "GMSKsimulation_acc.mdl".
*
* Model Version : 1.4
* Real-Time Workshop version : 6.6 (R2007a) 01-Feb-2007
* C source code generated on : Wed Mar 26 19:41:57 2008
*/
#include <math.h>
#include "GMSKsimulation_acc.h"
#include "GMSKsimulation_acc_private.h"
#include <stdio.h>
#include "simstruc.h"
#include "fixedpoint.h"
#define CodeFormat S-Function
#define AccDefine1 Accelerator_S-Function
/* Outputs for root system: '<Root>' */
static void mdlOutputs(SimStruct *S, int_T tid)
{
/* local block i/o variables */
creal_T B_0_3_0;
creal_T B_0_4_0;
creal_T B_0_5_0;
real_T B_0_0_0;
/* Signal Processing Blockset Random Source (sdsprandsrc2) - '<S2>/B_0_0' */
MWDSP_RandSrc_U_D((real64_T *)&B_0_0_0,&((Parameters *) ssGetDefaultParam(S)
)->P_0,1,&((Parameters *) ssGetDefaultParam(S))->P_1,1,
&((D_Work *) ssGetRootDWork(S))->RandomSource_STATE_DWORK[0],
1,1);
((BlockIO *) _ssGetBlockIO(S))->B_0_2_0 = (real_T)(B_0_0_0 > ((Parameters *)
ssGetDefaultParam(S))->P_2);
/* Communications Blockset CPM modulator (scomcpmmod)
<S4>/B_0_2 */
{
if (ssIsSampleHit(S, 0, 0)) {
{
const real_T *const input = &((BlockIO *) _ssGetBlockIO(S))->B_0_2_0;
real_T* symInput = &((D_Work *) ssGetRootDWork(S))
->CPMModulatorBaseband_bin2intVec;
{
/* Binary to integer conversion */
int_T symVal = 0;
/* Index from MSB first */
symVal <<= 1;
symVal += (int_T) input[0];
/* Unipolar to bipolar mapping: 0 -> -(M-1), 1 -> -(M-2), etc */
symVal += symVal - 1;
/* Write the integer symbol to the integer vector */
symInput[0] = (real_T) symVal;
}
/* If new input sample is currently available, first perform upsampling
* and update the polyphase (multirate) filter at the upsampled rate.
*/
{
real_T *const outBuf = &((D_Work *) ssGetRootDWork(S))
->CPMModulatorBaseband_OutBuff[0];
int_T curTapIdx, curPhaseIdx, j;
real_T sum, u;
const real_T* inputPtr = symInput;
const real_T* mem;
real_T* tap0 = &((D_Work *) ssGetRootDWork(S))
->CPMModulatorBaseband_TapDelayBu[0];
const real_T* filterCoef;
int_T *const wrIdx = &((D_Work *) ssGetRootDWork(S))
->CPMModulatorBaseband_WriteIndex;
int_T *const tapIdx = &((D_Work *) ssGetRootDWork(S))
->CPMModulatorBaseband_TapDelayIn;
curTapIdx = *tapIdx;
curPhaseIdx = 0;
u = *inputPtr++;
filterCoef = &((Parameters *) ssGetDefaultParam(S))->P_3[0];
/* Generate the output samples */
/* Most recently saved input */
mem = tap0 + curTapIdx;
/* The filter coefficients have (hopefully) been
* re-ordered into phase order */
sum = u * (*filterCoef++);
for (j = 0; j <= curTapIdx; j++) {
sum += (*mem--) * (*filterCoef++);
}
/* mem was pointing at the -1th element. Move to end. */
mem += 4;
while (j++ < 4) {
sum += (*mem--) * (*filterCoef++);
}
*(outBuf + (*wrIdx)++) = sum;
curPhaseIdx++;
/* Update the counters modulo their buffer size */
if (curPhaseIdx >= 1)
curPhaseIdx = 0;
if (curPhaseIdx == 0) {
if (++curTapIdx >= 4)
curTapIdx = 0;
/* Save the current input value */
tap0[curTapIdx] = u;
}
tap0 += 4;
/* Update stored indices */
*tapIdx = curTapIdx;
if (*wrIdx >= 2)
*wrIdx = 0;
}
}
{
creal_T *const output = &B_0_3_0;
/* Output the next processed sample */
{
const real_T* out = &((D_Work *) ssGetRootDWork(S))
->CPMModulatorBaseband_OutBuff[0];
real_T* y = &((D_Work *) ssGetRootDWork(S))
->CPMModulatorBaseband_phaseVecto[0];
int_T *const rdIdx = &((D_Work *) ssGetRootDWork(S))
->CPMModulatorBaseband_ReadIndex;
int_T rIdx = 0;
int_T idx = -1;
rIdx = (idx += 1);
/* Output the current samples, NORMALIZED by the Interpolation */
/* Factor in order to preserve input signal scaling. Note that */
/* this is done here once at the end of the computation (i.e. */
/* just before the output gets sent out) in order to preserve */
/* as much signal numerical precision as possible. */
*y++ = *(out + *rdIdx + rIdx++) / ((real_T) 1);
if ((*rdIdx += 1) >= 2) {
*rdIdx = 0;
}
}
/* Integrate the shaped inputs to form the CPM phase. */
{
int_T frameOffset = -1, idx;
real_T T, ST;
real_T *const phaseState = &((D_Work *) ssGetRootDWork(S))
->CPMModulatorBaseband_phaseState;
real_T *const phaseVector = &((D_Work *) ssGetRootDWork(S))
->CPMModulatorBaseband_phaseVecto[0];
ST = phaseState[0];
frameOffset += 1;
idx = frameOffset;
T = phaseVector[idx];
phaseVector[idx] = ST;
ST += T;
/* To avoid overflow */
phaseVector[idx] = fmod(phaseVector[idx], (real_T) DSP_TWO_PI);
/* Assign complex output argument */
output[idx].re = cos(phaseVector[idx]);
output[idx].im = sin(phaseVector[idx]);
/* Update the state */
phaseState[0] = ST;
}
}
}
}
/* Signal Processing Blockset Random Source (sdsprandsrc2) - '<S1>/B_0_3' */
MWDSP_RandSrc_GZ_Z((creal64_T *)&B_0_4_0,(creal64_T *)&((Parameters *)
ssGetDefaultParam(S))->P_11,1,&((Parameters *) ssGetDefaultParam(S))->P_5,1,
&((D_Work *) ssGetRootDWork(S))->RandomSource_STATE_DWORK_h
[0],1,1);
/* Communications Blockset AWGN Channel (scomawgnchan2) - '<S1>/B_0_4' */
{
const creal_T *xptr = &B_0_3_0;
const creal_T *nptr = &B_0_4_0;
creal_T *yptr = &B_0_5_0;
real_T *stdDev = &((D_Work *) ssGetRootDWork(S))->DynamicAWGN_STDDEV;
/* Add noise to signal for each sample */
yptr->re = xptr->re + (*stdDev) * (nptr->re);
yptr->im = xptr->im + (*stdDev) * (nptr->im);
yptr++;
xptr++;
nptr++;
}
/* Communications Blockset CPM Demodulator (scomcpmdemod)
<S3>/B_0_5 */
{
if (ssIsSampleHit(S, 0, 0)) {
{
const creal_T *input = &B_0_5_0;
/* Write input to the buffer */
creal_T *inputBuff = &((D_Work *) ssGetRootDWork(S))->InputBuff[0];
writeBuffer( (void *)inputBuff, (const void *)input, 1,
&((D_Work *) ssGetRootDWork(S))->InBuffTopIdx,
&((D_Work *) ssGetRootDWork(S))->InBuffDtAvail,
2, sizeof(creal_T) );
/* Decode Symbols */
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -