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

📄 sc_turboic_mimo.c

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

File name: SC_TurboIC.c
Abstract : Main Program.

Version  : 2.0
Author   : Bin Jiang
Date     : 2004-03-25
Modify   : See head file.
Reference: Matlab program.
*********************************/

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

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

#define MAX_FRAME	1000
void main(void)
{
	//Define the Variable and Pointer.
	int 	i;
	int		result;
	int		n_Frame;

	int		n_IterNum = 8;	//4 is enough

//	FILE    * fp;
	
	double 	SNR;
	double	SNR1 =   -4.0;
	double	SNR2 =   -3.0;
	double  ber;
	
	double  Time_Begin;
	
	CODE_PARAMETER	code_parm;
	BASEBAND_PARM	Baseband_Parm;
	CH_PARAMETER	CH_Parameter;
	
	double 	  Noise_Variance;
	
	short   * p_InfoBit;
	short   * p_DecodedBit;
	
	int 	* p_CodeInlvTable;
	int 	* p_OuterInlvTable;
	
	COMPLEX * p_txSignal;
	COMPLEX * p_rxSignal;
	COMPLEX * p_rakeSignal;
	COMPLEX * p_h_half;
	
	int		n_CodeInlv_length;
	int		n_OuterInlv_length;
	int		n_InfoBitLength;
	int		n_txSignalLength;
	int		n_rxSignalLength;
	int		n_error;
		
	srand((unsigned)time(NULL));
	s1 = rand();
	s2 = rand();
		
	//Initialization(Configure System Parameter)
	
	//Channel Setting
	CH_Parameter.Tc			= 1/(1.28e6);
	CH_Parameter.Phase_R	= 5.96965436035132;//2*PI*random_source();
	CH_Parameter.Phase_I	= 1.45204412448920;//2*PI*random_source();
	for(i=0; i<PATH_NUM; i++)
	{
		CH_Parameter.Path_Delay[i] = PATH_DELAY[i];
		CH_Parameter.Path_Gain[i]  = PATH_GAIN[i];
	}
	Time_Begin = CH_Parameter.Tc*(1e8+1*554*33413);  //Begin with the worst channel.

	//Baseband Setting
	Baseband_Parm.FRAME_SLOTNUM     = 16;	//For each transmitter antenna in one 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 = TxANTENNA_NUM*Baseband_Parm.FRAME_SLOTNUM/CODE_SLOTNUM*n_CodeInlv_length*OUTPUT/INPUT;
	n_txSignalLength   = TxANTENNA_NUM*Baseband_Parm.FRAME_SLOTNUM*SLOT_LENGTH;
	n_rxSignalLength   = RxANTENNA_NUM*(Baseband_Parm.FRAME_SLOTNUM*SLOT_LENGTH+MAX_DELAY);
	n_InfoBitLength    = TxANTENNA_NUM*Baseband_Parm.FRAME_SLOTNUM/CODE_SLOTNUM*code_parm.n_InfoBit_length;

	//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));

	p_rakeSignal	 = (COMPLEX *)malloc(TxANTENNA_NUM*Baseband_Parm.FRAME_SLOTNUM*SYMBOL_SLOT*sizeof(COMPLEX));
	p_h_half		 = (COMPLEX *)malloc(TxANTENNA_NUM*TxANTENNA_NUM*PATH_NUM*Baseband_Parm.FRAME_SLOTNUM*(INTERP_FACTOR*SUBSLOT_NUM+1)*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);

	//Main Loop
	printf("FRAME_LENGTH = %d\n", n_InfoBitLength);

	for(SNR=SNR1; SNR<=SNR2; SNR+=0.25)
	{
		//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] = generate_binary_source();
				//p_InfoBit[i] = i%2; //The best source coding output!
			}

			//Transmitter
			result = Transmitter(p_InfoBit, n_InfoBitLength, p_txSignal, &Baseband_Parm, &code_parm, p_CodeInlvTable, p_OuterInlvTable);
			
			//MIMO Channel
			result = MIMO_Channel(p_txSignal, n_txSignalLength, p_rxSignal, &Noise_Variance, &Time_Begin, &CH_Parameter, &Baseband_Parm);

			//Space-Time Combination after channel estimate
            result = SpaceTimeCombine(p_rxSignal, n_rxSignalLength, p_rakeSignal, p_h_half, &Noise_Variance, &Baseband_Parm);
			
			//Turbo Detection/Decoding
			result = tmpTurboReceiver(p_InfoBit, n_InfoBitLength, p_rakeSignal, TxANTENNA_NUM*Baseband_Parm.FRAME_SLOTNUM*SYMBOL_SLOT, p_h_half, TxANTENNA_NUM*TxANTENNA_NUM*PATH_NUM*Baseband_Parm.FRAME_SLOTNUM*(INTERP_FACTOR*SUBSLOT_NUM+1), p_DecodedBit, p_OuterInlvTable, p_CodeInlvTable, &Baseband_Parm, &code_parm, Noise_Variance, n_IterNum);
			
			//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);
			
//			fp = fopen("Out.dat", "a");
//			fprintf(fp, "n_Frame = %d\t errors = %d\t ber = %e\n", n_Frame+1, n_error, ber);
//			fclose(fp);

			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);
	free(p_rakeSignal);
	free(p_h_half);
}

⌨️ 快捷键说明

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