⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 noise.c

📁 TI的DSP C55X的应用程序
💻 C
字号:
/***********************************************************************************/
/*                      IS54 Baseband Simulation Software                          */
/*                                                                                 */
/*  File Description : Noise Generator                                             */
/*  File Name        : noise.c                                                     */
/*  Date             : 12/30/93                                                    */
/*                   : July, 20001 - Modified for TMS320C55x project               */
/*                                                                                 */
/*    This subroutine generates Gaussian distributed random noise by using a       */
/*    modified Box-Mueller algorithm.                                              */
/*                                                                                 */
/*    Inputs to this routine consist of signal-to-noise ration (SNR),              */
/*    number of I,Q input pairs to be corrupted, and pointers to arrays            */
/*    of input I,Q vector pairs.                                                   */
/*                                                                                 */
/*    This routine will produce independent I,Q fading samples which               */
/*    will be used to corrupt the I,Q input data in place. (i.e. the input         */
/*    I,Q arrays will be OVERWRITTEN with corrupted data).                         */
/*                                                                                 */
/*    INPUTS                                                                       */
/*        SNR             : Desired signal to noise ratio                          */
/*        num_of_samps    : Number of samples to compute for one branch.           */
/*        I               : Input (uncorrupted) I (in-phase) sample                */
/*        Q               : Input (uncorrupted) Q (quadrature) sample              */
/*                                                                                 */
/*    OUTPUTS                                                                      */
/*        I               : Output I (in-phase) sample corrupted with              */
/*                          (in-phase) noise.                                      */
/*        Q               : Output Q (quadrature) sample corrupted with            */
/*                          (quadrature) noise.                                    */
/*                                                                                 */
/*                                                                                 */
/***********************************************************************************/

/* Include Files */

#include <math.h>  
#include <intrindefs.h>

/* Function Prototypes */

void noise( int, int*, int*, int);
int noise_init( float );

/* External Function Prototypes */

extern int rand_num(void);

/* Data */

/* External Data */

/* Code */

int noise_init( float SNR )
{
    float  scale;        /* scale factor for desired SNR */  

    scale = (float)( (0.5 / sqrt( pow( 10.0,(SNR/10.0) ) ) ) * 2.0 );
	return (scale*32767.0);
}

void noise(int num_of_samps, int *I, int *Q, int Sc_fact)
{
    int    i;              /* index and temporary variables */
    int    V1,V2;          /* random variables */            
    int    awgn_r, awgn_i;

    for (i = 0 ; i < num_of_samps ; i++)
    {
        V1 = _ssub(rand_num(), 0x4000);
        V2 = _ssub(rand_num(), 0x4000);

        awgn_r = _smpy(V1, Sc_fact);
        awgn_i = _smpy(V2, Sc_fact);
         
        *(I++) = _sadd(*I, awgn_r);
        *(Q++) = _sadd(*Q, awgn_i);
    }
    return;
}



⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -