📄 waterfill.c
字号:
#include <stdio.h>
#include <math.h>
#include "receiver.h"
/* function which computes the bit allocation from the channel estimation.
The function uses the so called waterfilling algorithm. */
// inputs: Hreal, Himag, Noise_var
// outputs: bn, en, btot
/**************waterfill***********/
#define SUBCARSIZE 124
//bit allocation function
void waterfill_simple(float *h_hat, float Noise_var, short *bn, float *en, float *gn) //, int *btot)
{
// initialization
// float gn[SUBCARSIZE];
int i;
float gap = 10; //10;
float K;
float sum = 0;
// float En_min;
float inv_Noise_var = 1/Noise_var; //1*_rcpsp(Noise_var);
float inv_subcar=1*_rcpsp(SUBCARSIZE);
// dB into normal scale
gap = pow(10,gap/10);
// find gn for multitone
for(i= 0; i<SUBCARSIZE; i++)
{
gn[i] = (h_hat[2*i]*h_hat[2*i] + h_hat[2*i+1]*h_hat[2*i+1]) * inv_Noise_var;
sum = sum + 1/(gn[i]);
}
K = (Ex*SUBCARSIZE + gap*sum)* inv_subcar;
for(i= 0; i<SUBCARSIZE; i++)
{
en[i] = K - gap / gn[i];
bn[i] = ceil(0.5 * log10(K * gn[i] / gap)/log10(2));
if(bn[i]>6 && bn[i]<=12)
bn[i]=6;
if(bn[i]>12)
bn[i]=6;
if (fmod(bn[i],2)!=0)
bn[i]=bn[i]-1;
if(bn[i]<1)
bn[i]=0;
// btot = btot + bn[i];
}
}
/*
void main(void)
{
float Hreal[Ntot], Himag[Ntot];
float en[Ntot];
int bn[Ntot];
int btot;
int i;
for(i= 0; i<2; i++)
{
Hreal[i] = 5;
Himag[i] = 0;
}
for(i= 2; i<Ntot; i++)
{
Hreal[i] = 0.1;
Himag[i] = 0;
}
waterfill(Hreal, Himag, bn, en, btot);
for(i= 0; i<Ntot; i++)
{
printf("Output=%d, %f \n",bn[i], en[i]);
}
}
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -