?? sarcpp.cpp
字號:
// 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 =0;hpointnum<h;hpointnum++)
for ( int wpointnum =0; wpointnum<w; wpointnum++)
{
AreaRCS =*(lpAreaImage+hpointnum*w+wpointnum);
if ( AreaRCS >0)
{
RatArea = sqrt((x+(hpointnum-h/2)*V_ami/PRF)*(x+(hpointnum-h/2)*V_ami/PRF) + (Rt+(wpointnum-w/2)*Rbin)*(Rt+(wpointnum-w/2)*Rbin));
angle = -4.0*PI*RatArea/Wavelenth;
Echophaset = complex<double> (cos(angle), sin(angle));
Nr_Start = floor((RatArea - R0)/Rbin - floor(NTao/2));
for (nr = Nr_Start;nr < Nr_Start + NTao; nr++)
{
double polynomial = *(LpRange_Time + nr) - 2.0*RatArea/C;
angle = PI*KR*polynomial*polynomial;
SignalPhase = complex<double>(cos(angle), sin(angle));
SignalPhase = SignalPhase * Echophaset;
*(LpRecSignalRe+na*Nr + nr) += AreaRCS*SignalPhase.real()/255;
*(LpRecSignalIm+na*Nr + nr) += AreaRCS*SignalPhase.imag()/255;
}
}
}//end for for
}//end else 面目標模擬回波數據接收結束
}
if (lpAreaImage != NULL)
{
delete lpAreaImage;
lpAreaImage = NULL;
}
return TRUE;
}
void CSAR::EchoRangeCompress()
{
if((LpAizm_Time == NULL)||(LpRecSignalRe == NULL)||(LpRecSignalIm == NULL)) return;
int w=1;
int wp=0;
int win = 1;
int winp = 0;
while(w * 2 <= Nr)
{
w *= 2;
wp++;
}
while(win * 2 <= (R_in+1)*Nr)
{
win *= 2;
winp++;
}
complex<double> *TD = new complex<double>[w];
complex<double> *FD = new complex<double>[w];
complex<double> *LpTemFilter =new complex<double>[win];//用來存放插值后的距離向匹配濾波器
complex<double> *LpTemFD =new complex<double>[win];//用來存放插值后的距離向頻域信號
complex<double> *LpTemTD =new complex<double>[win];//用來存放插值后距離壓縮距離向時域信號
complex<double> *Temp =new complex<double>[win];
//下面代碼完成匹配濾波器中間插0
for(int i = 0;i<Nr/2;i++)
{
LpTemFilter[i] = LpRangeMatchFilter[i];
LpTemFilter[R_in*Nr + Nr/2 + i] = LpRangeMatchFilter[Nr/2+i];
}
for (int j = Nr/2;j < R_in*Nr + Nr/2;j++) LpTemFilter[j] = complex<double>(0,0);//在濾波器中間插入R_in*Nr個0
for(int na = 0;na < Na;na ++)
{
for(int nr = 0;nr < Nr;nr++)
TD[nr] = complex<double>(*(LpRecSignalRe + na*Nr + nr),*(LpRecSignalIm + na*Nr + nr));
FFT(TD, FD,wp);
//下面代碼完成距離向信號頻域中間插0;
for(int ii = 0;ii<Nr/2;ii++)
{
LpTemFD[ii] = FD[ii];
LpTemFD[R_in*Nr + Nr/2 + ii] = FD[Nr/2 + ii];
}
for (int jj = Nr/2;jj < R_in*Nr + Nr/2;jj++) LpTemFD[jj] = complex<double>(0,0);//在距離向信號中間插入R_in*Nr個0
for (int kk = 0;kk < win;kk++) LpTemFD[kk] = LpTemFilter[kk]* LpTemFD[kk];
IFFT(LpTemFD,LpTemTD,winp);
for (int m= 0;m < (R_in+1)*(Nr-NTao/2);m++) Temp[m +(R_in+1)*NTao/2] = LpTemTD[m];
for (m =(R_in+1)*(Nr-NTao/2) ;m < (R_in+1)*Nr ;m++) Temp[m-(R_in+1)*(Nr-NTao/2)] = LpTemTD[m];
for ( int n =0; n<Nr;n++)
{
LpRecSignalRe[na*Nr+n]= Temp[R_in*(NTao/2+50)+n].real();
LpRecSignalIm[na*Nr+n]= Temp[R_in*(NTao/2+50)+n].imag();
}
}
delete TD;
delete FD;
delete LpTemFilter;
delete LpTemFD;
delete LpTemTD;
delete Temp;
/*由于進行距離向插值,要改變距離向的采樣率FS,以及單位像素對應的距離向距離Rbin,距離向的
起始距離R0,距離向的時間序列*/
FS = (R_in + 1)*FS;
Rbin = C/FS/2;
R0 = R0 = Rt - Rbin*floor(NTao/2) - 50*Rbin;
for (i = 0;i< Nr;i++)
{
LpRange_Time[i] = i/FS +2.0*R0/C; //發射信號時間
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -