📄 example6_acc_dsp.c
字号:
/*
* example6_acc_dsp.c
*
* DSP Blockset function calls
* Real-Time Workshop code generation for Simulink model "example6_acc.mdl".
*
* Model Version : 1.42
* Real-Time Workshop file version : 4.1 $Date: 2001/05/16 13:59:43 $
* Real-Time Workshop file generated on : Sun May 18 17:35:27 2003
* TLC version : 4.1 (May 19 2001)
* C source code generated on : Sun May 18 17:35:27 2003
*
* Relevant TLC Options:
* InlineParameters = 0
* RollThreshold = 5
* CodeFormat = S-Function
*
* Simulink model settings:
* Solver : VariableStep
* StartTime : 0.0 s
* StopTime : 10.0 s
* Variable step solver used
*/
#include "example6_acc_dsp.h"
/* Function: DSP_InitializeSeed
* Bit-shift the given initial seed
*/
extern void DSP_InitializeSeed(uint32_T *urandSeed, real_T initSeed)
{
const uint32_T maxseed = 2147483646; /* 2^31-2 */
const uint32_T seed0 = 1144108930; /* Seed #6, starting from seed = 1 */
const uint32_T bit16 = 32768; /* 2^15 */
*urandSeed = (uint32_T)initSeed;
/* Interchange bits 1-15 and 17-31 */
{
int_T r = *urandSeed >> 16;
int_T t = *urandSeed & bit16;
*urandSeed = ((*urandSeed - (r << 16) - t) << 16) + t + r;
}
if (*urandSeed < 1) {
*urandSeed = seed0;
}
if (*urandSeed > maxseed) {
*urandSeed = maxseed;
}
} /* end DSP_InitializeSeed */
/*
* DSP Blockset Random Source block
* Uniform random number generator
* Generates random number in range (0,1)
*/
extern real_T DSP_UniformRand(uint32_T *seed) /* pointer to a running seed */
{
const uint32_T IA = 16807; /* magic multiplier = 7^5 */
const uint32_T IM = 2147483647; /* modulus = 2^31-1 */
const uint32_T IQ = 127773; /* IM div IA */
const uint32_T IR = 2836; /* IM modulo IA */
const real_T S = 4.656612875245797e-10; /* reciprocal of 2^31-1 */
uint32_T hi = *seed / IQ;
uint32_T lo = *seed % IQ;
int32_T test = IA * lo - IR * hi; /* never overflows */
*seed = ((test < 0) ? (unsigned int)(test + IM) : (unsigned int)test);
return( (real_T) ((*seed) * S) );
} /* end DSP_UniformRand */
/* Function: DSP_NormalRand
* Normal (Gaussian) random number generator
*/
extern real_T DSP_NormalRand(unsigned int *seed)
{
real_T sr, si, t;
do {
sr = 2.0 * DSP_UniformRand(seed) - 1.0;
si = 2.0 * DSP_UniformRand(seed) - 1.0;
t = sr * sr + si * si;
} while (t > 1.0);
return(sr * sqrt((-2.0 * log(t)) / t));
} /* end DSP_NormalRand */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -