// SAR.cpp: implementation of the CSAR class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "SAR.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CSAR::CSAR()
{
TargetSimuType = POINT_TARGET;/*初始按执行点目标模拟,选中面目标模拟选项执行面目标模拟*/
LpAizm_Time = NULL;
LpRange_Time = NULL;
LpTranSignalRe = NULL;
LpTranSignalIm = NULL;
LpRangeMatchFilter = NULL;
LpRecSignalRe = NULL;
LpRecSignalIm = NULL;
LpAizm_Frequency = NULL;
LpRange_Frequency = NULL;
LpVTao = NULL;
LpVTaoRef = NULL;
LpBeta = NULL;
LpKm = NULL;
LpKsrcInv = NULL;
SARParaInit();
}
CSAR::~CSAR()
{
if(LpAizm_Time != NULL)
{
delete LpAizm_Time;
LpAizm_Time = NULL;
}
if(LpRange_Time != NULL)
{
delete LpRange_Time;
LpRange_Time = NULL;
}
if(LpTranSignalRe != NULL)
{
delete LpTranSignalRe;
LpTranSignalRe = NULL;
}
if(LpTranSignalIm != NULL)
{
delete LpTranSignalIm;
LpTranSignalIm = NULL;
}
if (LpRangeMatchFilter != NULL)
{
delete LpRangeMatchFilter;
LpRangeMatchFilter = NULL;
}
if (LpRecSignalRe != NULL)
{
delete LpRecSignalRe;
LpRecSignalRe = NULL;
}
if (LpRecSignalIm != NULL)
{
delete LpRecSignalIm;
LpRecSignalIm = NULL;
}
//释放CS算法指针变量
if (LpAizm_Frequency != NULL)
{
delete LpAizm_Frequency;
LpAizm_Frequency = NULL;
}
if (LpRange_Frequency != NULL)
{
delete LpRange_Frequency;
LpRange_Frequency = NULL;
}
if (LpVTao != NULL)
{
delete LpVTao;
LpVTao = NULL;
}
if (LpVTaoRef != NULL)
{
delete LpVTaoRef;
LpVTaoRef = NULL;
}
if (LpBeta != NULL)
{
delete LpBeta;
LpBeta = NULL;
}
if (LpKm != NULL)
{
delete LpKm;
LpKm = NULL;
}
if(LpKsrcInv !=NULL)
{
delete LpKsrcInv;
LpKsrcInv = NULL;
}
}
void CSAR::SARParaInit()
{
A_in = 3;
// A_in = 0;
// R_in = 5;
R_in = 3;
// RCM_in =5;
RCM_in = 3;
R_Res = 5;
A_Res = 2.5;
Wavelenth = 0.24;
V_ami = 180;
Pulsewidth = 0.00001;
Rt = 15000+500;
B_r = C/(2*R_Res);
B_d = V_ami/A_Res;
PRF = B_d*1.1;
FS = B_r*1.1;
Rbin = C/(2*FS);
KR = -B_r/Pulsewidth;
FR = -2.0*V_ami*V_ami/(Rt*Wavelenth);
Tsyn = fabs(B_d/FR);
NTao = int(floor(Pulsewidth*FS));
Nrcm = int(floor((sqrt(Rt*Rt + V_ami*V_ami*Tsyn*Tsyn/4.0) - Rt)/Rbin ));
Nr = NTao + Nrcm + 100;
Na =int( floor(Tsyn*PRF));
if (LpAizm_Time != NULL)
{
delete LpAizm_Time;
LpAizm_Time = NULL;
}
if (LpRange_Time != NULL)
{
delete LpRange_Time;
LpRange_Time = NULL;
}
if (LpTranSignalRe != NULL)
{
delete LpTranSignalRe;
LpTranSignalRe = NULL;
}
if (LpTranSignalIm != NULL)
{
delete LpTranSignalIm;
LpTranSignalIm = NULL;
}
if (LpRangeMatchFilter != NULL)
{
delete LpRangeMatchFilter;
LpRangeMatchFilter = NULL;
}
if (LpRecSignalRe != NULL)
{
delete LpRecSignalRe;
LpRecSignalRe = NULL;
}
if (LpRecSignalIm != NULL)
{
delete LpRecSignalIm;
LpRecSignalIm = NULL;
}
/*对采样频率FS及脉冲重复频率PRF优化,并使距离向和方位向的采样点数为2的指数次方*/
int nr=1,na=1;
while (pow(2,nr) < Nr) nr++;
while (pow(2,na) < Na) na++;
double rate = 1.1;
while (pow(2,nr) > Nr + nr/2)
{
rate += 0.01; //0.01为调整优化的步长
FS = B_r*rate;
Rbin = C/(2*FS);
NTao = int(floor(Pulsewidth*FS));
Nrcm = int(floor((sqrt(Rt*Rt + V_ami*V_ami*Tsyn*Tsyn/4.0) - Rt)/Rbin ));
Nr = NTao + Nrcm + 100;
}
R0 = Rt - Rbin*floor(NTao/2) - 50*Rbin;
rate = 1.1;
while (pow(2,na) > Na +na/2)
{
rate += 0.01; //0.01为调整优化的步长
PRF = B_d*rate;
Na = int(floor(Tsyn*PRF));
}
NaEffective = Na;//方位向采样有效点数
NrEffective = Nr;//距离向采样有效点数
Nr = int( pow(2,nr)); //这里的Nr大于距离向的有效点数
Na = int( pow(2,na)); //这里的Na大于综合孔径时间对应的方位向点数
//CS参数初始化
Ref = Rt;
if (LpAizm_Frequency != NULL)
{
delete LpAizm_Frequency;
LpAizm_Frequency = NULL;
}
if (LpRange_Frequency != NULL)
{
delete LpRange_Frequency;
LpRange_Frequency = NULL;
}
if (LpVTao != NULL)
{
delete LpVTao;
LpVTao = NULL;
}
if (LpVTaoRef != NULL)
{
delete LpVTaoRef;
LpVTaoRef = NULL;
}
if (LpBeta != NULL)
{
delete LpBeta;
LpBeta = NULL;
}
if (LpKm != NULL)
{
delete LpKm ;
LpKm = NULL;
}
if (LpKsrcInv != NULL)
{
delete LpKsrcInv;
LpKsrcInv = NULL;
}
}
BOOL CSAR::LMFSignalProduce()
{
if ((LpTranSignalIm == NULL)&& (LpTranSignalRe == NULL)&&(LpRange_Time == NULL))
{
LpRange_Time = new double [Nr];
LpTranSignalRe = new double [Nr];
LpTranSignalIm = new double [Nr];
}
if ( (LpTranSignalRe == NULL)||(LpTranSignalIm ==NULL)||(LpRange_Time == NULL))
{
AfxMessageBox("allocate memeory fail");
return FALSE;
}
memset( LpTranSignalRe,0,sizeof(double)*Nr);//信号缓冲区置0
memset( LpTranSignalIm,0,sizeof(double)*Nr);//信号缓冲区置0
for (int i = 0;i< Nr;i++)
{
LpRange_Time[i] = i/FS +2.0*R0/C; //发射信号时间
}
for (int j=0;j < NTao; j++)
{
double PolyNomal = LpRange_Time[j] - 2.0*R0/C - Pulsewidth/2.0;
LpTranSignalRe[j] = cos(PI*KR*PolyNomal*PolyNomal); //产生发射信号实部
LpTranSignalIm[j] = sin(PI*KR*PolyNomal*PolyNomal); //产生发射信号虚部
}
return TRUE;
}
BOOL CSAR::RecEchoSignal()
{
if ((LpTranSignalIm == NULL)||(LpTranSignalRe == NULL)||(LpRange_Time == NULL)) return FALSE;
if((LpAizm_Time ==NULL)&&(LpRecSignalRe == NULL)&&(LpRecSignalIm == NULL))
{
LpAizm_Time = new double[Na];
LpRecSignalRe = new double[Na*Nr];
LpRecSignalIm = new double[Na*Nr];
}
if((LpAizm_Time ==NULL)||(LpRecSignalRe == NULL)||(LpRecSignalIm == NULL))
{
AfxMessageBox("接收回波内存分配失败");
return FALSE;
}
memset(LpAizm_Time,0,sizeof(double)*Na);
memset(LpRecSignalRe,0,sizeof(double)*Na*Nr);
memset(LpRecSignalIm,0,sizeof(double)*Na*Nr);
int na,nr,Nr_Start;
complex<double> Echophaset,SignalPhase;//回波产生的相位,线性调频信号的相位
int w,h;//面目标图像的尺寸
BYTE *lpAreaImage = NULL;//面目标图像DIB数据
if(TargetSimuType == AREA_TARGET )
GetAreaInformation(&lpAreaTargetImageFileName,&w,&h,&lpAreaImage);
for( na=0;na<NaEffective;na++)
{
double Rat[5],RatArea,x,angle;
if( na/PRF < Tsyn) *(LpAizm_Time + na) = -Tsyn/2.0 + na/PRF;
x=(*(LpAizm_Time + na))*V_ami;
if(TargetSimuType == POINT_TARGET)//按点目标进行模拟
{
Rat[0] = sqrt(x*x + Rt*Rt);
Rat[1] = sqrt((x-20)*(x-20) + Rt*Rt);
Rat[2] = sqrt((x+20)*(x+20) + Rt*Rt);
Rat[3] = sqrt((x+40)*(x+40) + Rt*Rt);
Rat[4] = sqrt(x*x + (Rt-50)*(Rt-50));
for(int pointnum =0; pointnum<5;pointnum++)
{
angle = -4.0*PI*Rat[pointnum]/Wavelenth;
Echophaset = complex<double> (cos(angle), sin(angle));
Nr_Start = floor((Rat[0] - R0)/Rbin - floor(NTao/2));
for (nr = Nr_Start;nr < Nr_Start + NTao; nr++)
{
double polynomial = *(LpRange_Time + nr) - 2.0*Rat[pointnum]/C;
angle = PI*KR*polynomial*polynomial;
SignalPhase = complex<double>(cos(angle), sin(angle));
SignalPhase = SignalPhase * Echophaset;
*(LpRecSignalRe+na*Nr + nr) += SignalPhase.real();
*(LpRecSignalIm+na*Nr + nr) += SignalPhase.imag();
}
}
}//点目标模拟回波数据接收结束
else //按打开的面目标进行模拟
{
double AreaRCS;
for (int hpointnum