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

📄 ofdm_bench.c

📁 ofdm的完整系统模型,包含信道参数,多径模型,doppler频移等都可以自由修改!是您做仿真的有力帮助.c语言运行速度快!
💻 C
字号:
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <ctype.h>
#include <string.h>

#include "cgs.h"
#include "ofdm_bench.h"

Ovector			Data_Buff;
//RayParams		ray_params_1[12];
RayParams		ray_params_1;
GauParams		gauss_params_1;
FreqParams		freq_params_1;
double			Noise_Sigma;
double			Ch_Norm_Factor;
#define BLK_NUM			4
#define MAX_FRAME		4
void main()
{
	int i, loop_idx, frm_num;
	static long rand_bitseed = 100;
	
//	float tmp_real, tmp_imag;
//	FILE *fp_true;

	static Complex ofdm_buffer_tx[BLK_NUM][MAX_FRAME][SUBCARRIERS+CP_LENGTH];
	static Complex ofdm_buffer_rx[BLK_NUM][MAX_FRAME][SUBCARRIERS+CP_LENGTH];
	
	static Complex pilot_buf1[MAX_FRAME][PILOT_LENGTH];			// noise free
	static Complex pilot_buf2[MAX_FRAME][PILOT_LENGTH];			// LS 
	
	static Complex data_buf1[MAX_FRAME][DATA_SUBC_LEN];			// original data
	static Complex data_buf2[MAX_FRAME][DATA_SUBC_LEN];			// with noise

	int	snr_idx;
	double SN_Ratio;
	double papr0=1.0;
	double ccdf_i=0.0;

	for (snr_idx = 0; snr_idx < 7; snr_idx++) {	
		
		rand_bitseed = 100;
		// initial SNR 
		SN_Ratio = SNR_INI + snr_idx * 5.0;
	
//		SN_Ratio = 30
		// initial channel 
		initial_sel(&ray_params_1);
		initial_gauss(&gauss_params_1, CHANNEL_DELAY, SIGNAL_POWER, SN_Ratio);		
//		fp_true = fopen(LOG_TAP_TRUE, "r");
		for (loop_idx = 0; loop_idx < BLK_NUM; loop_idx++) {
			printf("fd=%dHz, SNR=%gdB, block(%d): %d\n", CH_DOPPLER_FREQ, SN_Ratio, BLK_NUM, loop_idx);
			for (frm_num = 0; frm_num < MAX_FRAME; frm_num++) {
				ofdm_pakgen(&rand_bitseed, ofdm_buffer_tx[loop_idx][frm_num], data_buf1[frm_num]);	
			}
		}
		//ofdm_pts(ofdm_buffer_tx);
		ccdf_i=ofdm_papr_stat(ofdm_buffer_tx,papr0);
		
		for (loop_idx = 0; loop_idx < BLK_NUM; loop_idx++) {
			for (frm_num = 0; frm_num < MAX_FRAME; frm_num++) {
				// add channel:
				for (i = 0; i < SUBCARRIERS+CP_LENGTH; i++) {
					ofdm_buffer_rx[loop_idx][frm_num][i] = rayleigh_sel(ofdm_buffer_tx[loop_idx][frm_num][i], &ray_params_1);
					ofdm_buffer_rx[loop_idx][frm_num][i] = awgn_channel(ofdm_buffer_rx[loop_idx][frm_num][i], &gauss_params_1);
				}
				ofdm_depak(ofdm_buffer_rx[loop_idx][frm_num], data_buf2[frm_num], pilot_buf2[frm_num]);
			}
		}//end block loop
		free_rayleigh_sel(&ray_params_1);
		free_gauss(&gauss_params_1);
	} //end snr_idx
	
}


void ofdm_pts(Complex ***ofdm_buffer_tx)
{
	
}
double ofdm_papr_stat(Complex ***ofdm_buffer_tx,double papr0)
{
	int i,j,k;
	double power;
	int counter=0;
	for(i=0;i<BLK_NUM;i++){
		for(j=0;j<MAX_FRAME;j++){
			for(k=0;k<(SUBCARRIERS+CP_LENGTH);k++){
				power=calc_power(ofdm_buffer_tx[i][j][k]);
				if(power>papr0)counter++;
			}
		}
	}
	return (double)((float)counter/(float)(BLK_NUM*MAX_FRAME*(SUBCARRIERS+CP_LENGTH)));
}
double calc_power(Complex data)
{
	return data.imag*data.imag+data.real*data.real;
}
void ofdm_ici(Complex ***ofdm_buffer_rx)
{

}

⌨️ 快捷键说明

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