作者 群号 C语言交流中心 240137450 微信 15013593099
作者 群号 C语言交流中心 240137450 微信 15013593099
高斯噪声
今天编了一个用C语言实现高斯白噪声的程序,希望可以给大家带来方便。做出来的序列*n,其方差比预先规定的要小10的-2次方量级,但是总体来说是比较准确的。可以通过改变量化精度Stride来增加概率估计的准确性。
# include
# include
# define PI (3.14)
# define Stride (0.005)
short interleaver[length] = {...........};
注:interleaver是个交织器,长度与参数length一致就行,里面是乱序排列,这个在matlab里用randperm实现就行。
例如:short interleaver[10] = {7,1,9,6,3,2,5,8,4,0};
void awgn(float db, int length, float *n)
{
float pdf[10000] = {0};
float *amp;
float delta=0, amplitude = 0, sum = 0, temp1=0, temp2=0;
int *num;
int counter, counter1, counter2, counter3;
int half_length;
delta = 1 / ( 2 * pow(10,0.1*db) ); // 计算噪声功率
counter = 0; // 通过概率密度计算幅度集合和对应的概率密度
while( sum < (0.5/Stride) )
{
pdf[counter] = 1/sqrt(2*PI*delta)*exp(-0.5*pow(amplitude,2)/delta);
sum += pdf[counter];
amplitude += Stride;
counter++;
} // 最后得到的counter是幅度集合的长度
num = (int *)calloc(counter,sizeof(int)); // num每个幅度在序列中出现的次数,幅度放在amp中
amp = (float *)calloc(counter,sizeof(float));
amplitude = 0;
sum = 0;
temp1 = length*Stride;
temp2 = 0;
for(counter1=0;counter1<counter;counter1++)
{
temp2 = temp1*pdf[counter1];
if( (int)(temp2+0.5)>(int)temp2 )
*(num+counter1) = (int)(temp2+1);
else
*(num+counter1) = (int)temp2;
sum += *(num+counter1);
*(amp+counter1)=amplitude;
amplitude += Stride;
}
temp1 = 0;
half_length = length>>1;
if(sum<half_length) // 使num的和恰好是length的一半
{
temp1 = half_length-sum;
for(counter1=0;counter1<temp1;counter1++)
(*(num+counter-1-counter1))++;
}
else if(sum>half_length)
{
temp1 = sum-half_length;
*num -= temp1;
}
counter3 = 0;
for(counter1=0;counter1<counter;counter1++) // 往*n里填入幅度值
{
for(counter2=0;counter2<*(num+counter1);counter2++)
{
*(n+counter3) = *(amp+counter1);
*(n+length-1-counter3) = -*(amp+counter1);
counter3++;
}
}
for(counter1=0;counter1<length;counter1++)
{
temp1 = *(n+counter1);
*(n+counter1) = *(n+interleaver[counter1]);
*(n+interleaver[counter1]) = temp1;
for(counter2=0;counter2<length-counter1-1;counter2++)
if(interleaver[counter1+counter2+1]==counter1)
interleaver[counter1+counter2+1] = interleaver[counter1];
}
}
去除while true
sed 's/while true/while false/' app_init>app_init2| mv app_init2 app_init
电话按键上每个点的fft
9 861 1497 862 1493
8 867 1306 875 1312
7 865 1192 875 1187
6 750 1500 737 1500
5 740 1312 750 1312
4 750 1194 750 1187
3 681 1482 687 1487
2 681 1310 687 1306
1 674 1193 687 1187
# 936 1500 931 1487
0 937 1312 931 1306
* 931 1190 931 1187
ti汇编
A Accumulator A
AR Auxiliary register, general usage
T Temporary register
ST0, ST1 Status register 0, status register 1
SP Stack pointer
PMST Processor mode status register
Xmem 16-bit dual data-memory operand used in dual-operand instructions
Ymem 16-bit dual data-memory operand used in dual-operand instructions
Lmem 32-bit single data-memory operand using long-word addressing
Smem 16-bit single data-memory operand
BRAF Block-repeat active flag in ST1
C16 Dual 16-bit/double-precision arithmetic mode bit in ST1
FRCT Fractional mode bit in ST1
INTM Interrupt mode bit in ST1
OVM Overflow mode bit in ST1
XF External flag status bit in ST1
C16 Dual 16-bit/double-precision arithmetic mode bit in ST1
OVA Overflow flag for accumulator A in ST0
OVB Overflow flag for accumulator B in ST0
ASM 5-bit accumulator shift mode field in ST1 (–16
void getprior()
{
short i,maxC;
unsigned short i1=0,i2=0;
unsigned long psAll=0;
//unsigned long msdAll=0;
unsigned long pnAll=0;
unsigned long fromquittovoice=0;
//unsigned long curface = 0;
for(i=0;i<CHANNELS;i++)
{
if(HOST_IN[i]==0xffff){
psAllarr[i]=0;
pnAllarr[i]=0;
snrAllarr[i]=0;
continue;
}
if((ps_val[i]>NOISEPS)&&(psAll>NOISESNR)){
if(infirstsample==0){
infirstsample=1;
fromquittovoice=1;
}else{
fromquittovoice=0;
}
}else{
infirstsample=0;
fromquittovoice=0;
}
}
if(infirstsample==0)return;
if(fromquittovoice){
for(i=0;i<CHANNELS;i++)
{
psAllarr[i]=0;
pnAllarr[i]=0;
snrAllarr[i]=0;
}
totSamples=0;
}
for(i=0;i<CHANNELS;i++)
{
psAllarr[i]+=ps_val[i];;
pnAllarr[i]+=pn_val[i];;
psAll = CALCSNR(ps_val[i],pn_val[i]);
snrAllarr[i]+=psAll;
}
totSamples++;
if((totSamples%200)==199){
psAll=0;
for(i=0;i<CHANNELS;i++){
if(psAll<snrAllarr[i]){
psAll=snrAllarr[i];
i1=i;
}
}
psAll=0;
for(i=0;i<CHANNELS;i++){
if(i==i1)continue;
if(psAll<snrAllarr[i]){
psAll=snrAllarr[i];
i2=i;
}
}
if((snrAllarr[i1]>snrAllarr[i2]-SNRdiff)&&(psAllarr[i1]>=PWRthreshold))
{
maxC=i1;
}
else
{
psAll = snrAllarr[i1]* psAllarr[i1];
pnAll = snrAllarr[i2]* psAllarr[i2];
if(psAll>pnAll)maxC=i1;
else maxC=i2;
}
}
//cur_prior = maxC;
avrCurPS=psAllarr[cur_prior]/totSamples;
avrCurSNR=snrAllarr[cur_prior]/totSamples;
if(snrAllarr[i1]){
if(is_first_frame){
cur_prior = maxC;
is_first_frame = 0;
}else{
if((avrCurPS>=GOODPS)&&(avrCurSNR>=GOODSNR))
{
}
else if((snrAllarr[maxC]>=(snrAllarr[cur_prior]*CHFACTORS))&&(psAllarr[maxC]>=psAllarr[cur_prior]))
{
cur_prior = maxC;
}
}
}else{
cur_prior = 0;
for(i=0;i<CHANNELS;i++){
if(HOST_IN[i]!=0xffff){
cur_prior = i;
break;
}
}
}
}
信号对比 ccs的fft和我自己的fft
放音乐
按键
z0
z1
z2
z3
增加噪声放大信号代码
short getrand()
{
#define noimod 101
short t;
t = rand();
t = t % noimod;
return t-(noimod/2);
}
short getgtz(short a)
{
#define flyfact 3
return a/flyfact;
}
音乐1
音乐2
音乐3
音乐4
音乐5
白噪声0%
白噪声10%
白噪声30%
白噪声50%
100bzs
mix