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

📄 frequencyoffset.cpp

📁 扩展的直序扩频系统
💻 CPP
字号:
#include "Common.h"

/**** add frequency-offset on the i th chip/sampling_point ****/

void AddFrequencyOffset(complex *ChannelOut,int i)
{
	int k;
	double theta;
	complex phase;

	theta = 2*2.4*20*Pi*(float)(F_OFFSET)/(1000000.*(float)(CHIP_SIZE));      // the phase difference between two adjacent point

	for(k=0; k<CHIP_SIZE; k++)
	{
		phase.real = (float)(cos((i*CHIP_SIZE+k) * theta));
		phase.imag = (float)(sin((i*CHIP_SIZE+k) * theta));
		ChannelOut[k] = ComplexMul(ChannelOut[k], phase);
	}
}


//////////////////// Estimate the D_phase //////////////////////
float FO_Est(FILE *fpt_RxSignal)
{
	complex Preamble1[PREAMBLE_LENGTH] = {0.f, 0.f};
	complex Preamble2[PREAMBLE_LENGTH] = {0.f, 0.f};
	complex temp = {0.f,0.f};
	int i;
	float phase;

	fread(Preamble1, sizeof(complex), PREAMBLE_LENGTH, fpt_RxSignal);
	fread(Preamble2, sizeof(complex), PREAMBLE_LENGTH, fpt_RxSignal);

	for(i=0; i<PREAMBLE_LENGTH; i++)
	{
		temp = ComplexAdd( temp , ComplexMul( Preamble2[i], ComplexConj(Preamble1[i]) ));
	}

	phase = ComplexPhase(temp)/(float)(PREAMBLE_LENGTH);    
	return phase;

}


////////////////// Frequency offset cancel ///////////////////////

void FO_Compensate(FILE *fpt_RxSignal, FILE *fpt_RxSignal_FOC)
{
	float phase = 0.;
	int i=0;
	complex signal[1] = {0.,0.}, signal_foc[1] ={0.,0.};
	complex foc = {0.,0.};
	
	phase = FO_Est(fpt_RxSignal);

	while ( !(feof(fpt_RxSignal)) )       
	{
		foc.real = (float)(cos(-i*phase));
		foc.imag = (float)(sin(-i*phase));
		fread(signal, sizeof(complex), 1, fpt_RxSignal);
		
		signal_foc[0] = ComplexMul(signal[0], foc);

		fwrite(signal_foc, sizeof(complex), 1, fpt_RxSignal_FOC);
		
		i++;
	}

}

⌨️ 快捷键说明

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