📄 common.h
字号:
#ifndef __COMMON__
#define __COMMON__
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <memory.h>
#include <string.h>
#define Pi 3.1415926f
typedef struct
{
float real;
float imag;
}complex;
#define IN
#define OUT
#define SeedRand
#define N_POINTS 4 //work points
#define BPS 2 //bits per symbol QPSK
#define Ns 13 //spread spectrum factor: 1,3,11,13
#define PSDU_LENGTH_BIT 1000
#define PACKET_NUM 20000
#define PULSE_SIZE 1 //1:Not use over sampling;
#define MULTIPATH_NUM 8 //1:1 path; 8: 8 path
#define F_OFFSET 10 //n ppm of 2.4GHz
#define PREAMBLE_LENGTH 15
#define TRAINING_TIMES 8 //number of preambles
#define CE_NUM 2 //channel estimation smoothing times
#define SYN_NUM 2
#define FO_NUM 2
#define RANDOM_flag 1 //1: random the Transmitted data; 0: set data with all zeros
#define MULTIPATH_flag 1 //1: Through multipath channel
#define AWGN_flag 1 //1: Add Gaussian noise
#define SYN_flag 1 //1: with synchronization; 0: without synchronization
#define OFFSET_flag 0 //1: Add frequency offset; 0: ignore the F offset
#define SFD_flag 0 //1: Use SFD detection;
#define IDEAL_ESTIMATION 0 //0: Channel Estimation; 1: Ideal Channel
#define EST_DOMAIN 0 //0: time domain; 1: Frequency domain
#define EST_MODE 1 //1: correlation; 2: LS
#define NORM_DEFINITION 1 //1: Normalize channel energy every realization; 2: Statistical normalization
#define PSDU_LENGTH_SYM (PSDU_LENGTH_BIT/BPS)
#define Num_Reserved_Chip 50
#define PACKET_LENGTH_CHIP (PSDU_LENGTH_SYM*Ns+Num_Reserved_Chip)
#define CHIP_SIZE PULSE_SIZE
#define MemLength MULTIPATH_NUM*CHIP_SIZE
#define TRAINING_LENGTH PREAMBLE_LENGTH*(TRAINING_TIMES+1) // one SFD preamble
#define TOTAL_CHIP (TRAINING_LENGTH + PACKET_LENGTH_CHIP)
/***************Functions****************************/
void Transmit();
void Modulation(IN int *DataBin,complex *TxSymbol); //Mapping
void Gen_Fuction(float *GenerateFunction); //Genarate Barker sequence
void Gen_msequence(complex *mseq);
void SpreadSprectrum(IN complex *TxSymbol, OUT complex *SpreadSignal); //spread spectrum
void Gen_Pulse(float *Pulse);
void PulseShaping(IN complex *SpreadSignal,OUT complex *TxSignal);
void Channel();
void GenChannel(OUT complex *Channel_ImpRep);
void AddMutiChannel(complex *Signal,IN complex *channel, IN complex *ChannelMem, IN int Length);//Signal is a variance both input and output
void AddGaussNoise(complex *Signal, IN double Ps, IN int Length);//Signal is a variance both input and output
void AddFrequencyOffset(complex *ChannelOut,int i);
void Receive();
void MatchFilter(IN complex *Rxbuffer, IN int length,OUT complex *MatchResult);
void DeSpread(IN complex *MatchResult, IN float *Barker, IN int k, OUT complex *RxSymbol);
void Rake(IN complex *MatchResult, IN int length, OUT complex *RakeResult);
void Demodulate(IN complex *RakeResult,IN int length,OUT int *DemodResult);
int Syn(complex *buffer);
void FO_Compensate(FILE *fpt_RxSignal, FILE *fpt_RxSignal_FOC);
void SFD(complex CEsequence[PREAMBLE_LENGTH], FILE *fpt_RxSignal);
void TimeEst(complex *CEsequence);
void FrequencyEst(complex *CEsequence);
void Count_BER();
void Count_PER();
/**********Tool Functions*****************************/
float Gauss_rand();
complex ComplexMul(complex a,complex b);
complex ComplexMulR(complex a,float b);
complex ComplexAdd(complex a,complex b);
complex ComplexSub(complex a,complex b);
complex ComplexConj(complex a);
float ComplexPow(complex a);
float ComplexPhase(complex a);
complex ComplexDiv(complex a,complex b);
complex ComplexDivR(complex a, float b);
void FFT(complex *Signal,complex *FFTsignal,int flag,int FFTn);
void ComMatrix_Mul(IN complex *p1,IN complex *p2,IN int M, IN int N, IN int K, OUT complex *p3);
void ComMatrix_Inv( IN complex *p1, IN int N, OUT complex *p2);
void ComMatrix_H(IN complex *p1, IN int M, IN int N, OUT complex *p2);
void ComMatrix_T(IN complex *p1, IN int M, IN int N, OUT complex *p2);
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -