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

📄 gmc_turboic_mimo.c

📁 B3g_phase2_C语言_Matlab程序及说明
💻 C
字号:
/********************************
Copyright (C) 2004, FuTHER@NCRL
All rights reserved.

File name: GMC_TurboIC_MIMO.c
Abstract : Main Program.

Version  : 1.0
Author   : Bin Jiang
Date     : 2004-04-09
Modify   : 
Reference: Matlab program.
*********************************/

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <time.h>

#include "common.h"
#include "channel.h"

#define MAX_FRAME	100

void main(void)
{
	//Define the Variable and Pointer
	int i;
	int result;
	int n_Frame;

	int n_IterNum = 6;

	double SNR;
	double SNR1 =  4.0;
	double SNR2 =  6.0;

	double Time_Begin;
	double ber;


	CODE_PARAMETER	code_parm;
	BASEBAND_PARM	Baseband_Parm;
	CH_PARAMETER	CH_Parameter;

	COMPLEX   PILOT_MATRIX[TxANTENNA_NUM*PATH_NUM*PILOT_LENGTH];

	//Memory
	short   * p_InfoBit;
	short   * p_DecodedBit;
	
	int 	* p_CodeInlvTable;
	int 	* p_OuterInlvTable;

	COMPLEX * p_txSignal;
	COMPLEX * p_rxSignal;

	int		n_CodeInlv_length;
	int		n_OuterInlv_length;
	int		n_InfoBitLength;
	int		n_txSignalLength;
	int		n_rxSignalLength;
	int     n_txSignalLenPerTx;
	int		n_error;
		
	srand((unsigned)time(NULL));
	s1 = rand();
	s2 = rand();
	
	//---------------------------------------------------------------
	//-----------------------Initialization--------------------------
	//------------------Configure System Parameter-------------------
	//---------------------------------------------------------------

	//Channel Setting
	CH_Parameter.Tc			= 1/(1.28e6)/18;
	CH_Parameter.Phase_R	= 2*PI*random_source();//5.96965436035132;//
	CH_Parameter.Phase_I	= 2*PI*random_source();//1.45204412448920;//
	for(i=0; i<PATH_NUM_MC; i++)
	{
		CH_Parameter.Path_Delay[i] = PATH_DELAY[i];
		CH_Parameter.Path_Gain[i]  = PATH_GAIN[i];
	}
	Time_Begin = CH_Parameter.Tc*1e8+1e5;

	//Baseband Setting
	Baseband_Parm.FRAME_SLOTNUM     = 10;	//SlotNum/(Tx*SC*Frame).
	Baseband_Parm.MODULATOR_STYLE   = 4;	//QAM16 Now can only support 16QAM.
	Baseband_Parm.n_SymbolPerSlot   = SYMBOL_SLOT;
	Baseband_Parm.n_CodedBitPerSlot = Baseband_Parm.MODULATOR_STYLE*Baseband_Parm.n_SymbolPerSlot;

	//Code Setting
//	code_parm.Code_Poly[0]     = 7;
//	code_parm.Code_Poly[1]     = 5;
//	code_parm.n_CodeMemLength  = 2;
	code_parm.Code_Poly[0]     = 13;
	code_parm.Code_Poly[1]     = 11;
	code_parm.n_CodeMemLength  = 3;
	code_parm.n_puncture       = 3-OUTPUT;
	code_parm.n_InfoBit_length = CODE_SLOTNUM*Baseband_Parm.n_CodedBitPerSlot*INPUT/OUTPUT-code_parm.n_CodeMemLength;

	n_CodeInlv_length  = code_parm.n_InfoBit_length+code_parm.n_CodeMemLength;
	n_OuterInlv_length = USED_CARRIER*TxANTENNA_NUM*Baseband_Parm.FRAME_SLOTNUM/CODE_SLOTNUM*n_CodeInlv_length*OUTPUT/INPUT;
//	n_OuterInlv_length = TxANTENNA_NUM*Baseband_Parm.FRAME_SLOTNUM/CODE_SLOTNUM*n_CodeInlv_length*OUTPUT/INPUT;
	n_InfoBitLength    = USED_CARRIER*TxANTENNA_NUM*Baseband_Parm.FRAME_SLOTNUM/CODE_SLOTNUM*code_parm.n_InfoBit_length;
	
	n_txSignalLenPerTx = Baseband_Parm.FRAME_SLOTNUM*SLOT_LENGTH*UPSAMPLE_FACTOR+FILTER_LENGTH-UPSAMPLE_FACTOR;
	n_txSignalLength   = TxANTENNA_NUM*n_txSignalLenPerTx;
	n_rxSignalLength   = RxANTENNA_NUM*(n_txSignalLenPerTx+MAX_DELAY);

	//Allocate memory
	p_CodeInlvTable  = (int *)malloc(n_CodeInlv_length*sizeof(int));
	p_OuterInlvTable = (int *)malloc(n_OuterInlv_length*sizeof(int));

	p_InfoBit		 = (short *)malloc(n_InfoBitLength*sizeof(short));	
	p_DecodedBit	 = (short *)malloc(n_InfoBitLength*sizeof(short));

	p_txSignal		 = (COMPLEX *)malloc(n_txSignalLength*sizeof(COMPLEX));
	p_rxSignal		 = (COMPLEX *)malloc(n_rxSignalLength*sizeof(COMPLEX));

	//Generate Interleaver table
	s_inter_generate(n_CodeInlv_length,  (int)sqrt(n_CodeInlv_length/2),  p_CodeInlvTable,  369, 248);
	s_inter_generate(n_OuterInlv_length, (int)sqrt(n_OuterInlv_length/2), p_OuterInlvTable, 768, 669);
	
	//Generate PilotMatrix
	result = GeneratePilotMatrix(PILOT_MATRIX);

	//-------------------------------------------------------------------------
	//------------------------Main Loop----------------------------------------
	//-------------------------------------------------------------------------
	printf("FRAME_LENGTH = %d\n", n_InfoBitLength);
	for(SNR=SNR1; SNR<=SNR2; SNR+=0.5)
	{
		//Initial Channel Parameter according current SNR
		CH_Parameter.SNR = SNR;
		printf("###############\n");
		printf("SNR = %f\n", SNR);

		n_error = 0;
		for(n_Frame=0; n_Frame<MAX_FRAME; n_Frame++)
		{
			//Generate original Info Bits
			for(i=0; i<n_InfoBitLength; i++)
			{
				//p_InfoBit[i] = i%2;
				p_InfoBit[i] = generate_binary_source();
			}

			//Transmitter
 			result = MC_Transmitter(p_InfoBit, n_InfoBitLength, p_txSignal, &Baseband_Parm, &code_parm, p_CodeInlvTable, p_OuterInlvTable);
			
			//MIMO Channel
//			printf("TxSignal is passing through MIMO channel ......\n");
			result = New_MIMO_Channel(p_txSignal, n_txSignalLength, p_rxSignal, &Time_Begin, &CH_Parameter);
//			printf("TxSignal through MIMO channel has been completed!\n");

			//Turbo Receiver
			//result = MC_Receiver(p_rxSignal, n_rxSignalLength, p_DecodedBit, &Baseband_Parm, &code_parm, p_CodeInlvTable, p_OuterInlvTable, n_IterNum, PILOT_MATRIX);
			result = tmpMC_Receiver(p_InfoBit, n_InfoBitLength, p_rxSignal, n_rxSignalLength, p_DecodedBit, &Baseband_Parm, &code_parm, p_CodeInlvTable, p_OuterInlvTable, n_IterNum, PILOT_MATRIX);
			
			//Statistic Errors
			for(i=0; i<n_InfoBitLength; i++)
			{
				n_error += abs(p_DecodedBit[i]-p_InfoBit[i]);
			}

			//Display
			ber = (double)n_error/(double)((n_Frame+1)*n_InfoBitLength);

			printf("n_Frame = %d\t Total_errors = %d\t    BER = %e\n\n", n_Frame+1, n_error, ber);

			if(n_error>300 && n_Frame>=0) break;	
		}
		if(ber<1e-6) break;
	}
	//End of Main Loop

	getchar();
	
	//Free memory
	free(p_CodeInlvTable);
	free(p_OuterInlvTable);
	free(p_InfoBit);
	free(p_DecodedBit);
	free(p_txSignal);
	free(p_rxSignal);

}

⌨️ 快捷键说明

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