www.pudn.com > 35890064SAR.rar > SAR.cpp, change:2005-12-20,size:24197b


// 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;  //发射信号时间 
	} 
    
} 
 
void CSAR::RCMC() 
{ 
   /* 接收回波变换到距离多普勒域 */ 
	int wa=1,wr=1,win=1; 
    int wap=0,wrp=0,winp=0; 
	int na,nr; 
	int i; 
	double Rat;//SAR与目标距离随SAR运动而改变 
	double N_cR0,N_cRat; 
	while(wa * 2 <= Na) 
	{ 
		wa *= 2; 
		wap++; 
	} 
    while(wr * 2 <= Nr) 
	{ 
		wr *= 2; 
		wrp++; 
	} 
    while(win * 2 <= (RCM_in + 1)*Nr) 
	{ 
		win *= 2; 
		winp++; 
	} 
	complex<double> *TD = new complex<double>[wa]; 
    complex<double> *FD = new complex<double>[wa]; 
    complex<double> *LpTemFD =new complex<double>[win];//用来存放插值后距离向频域信号 
    complex<double> *LpTemTD =new complex<double>[win];//用来存放插值后距离向时域信号 
 
	for (nr = 0; nr < Nr;nr++) 
	{ 
		for (na = 0;na < Na;na++) TD[na] = complex<double>(*(LpRecSignalRe + na*Nr + nr),*(LpRecSignalIm + na*Nr + nr)); 
         FFT(TD, FD,wap); 
        for (na = 0;na < Na;na++) 
		{ 
          *(LpRecSignalRe + na*Nr + nr) = FD[na].real(); 
          *(LpRecSignalIm + na*Nr + nr) = FD[na].imag(); 
		} 
	} 
	delete TD; 
	delete FD; 
    TD = new complex<double>[wr]; 
    FD = new complex<double>[wr]; 
    /*计算距离徙动,在插值域通过计算Rt处和Rat处的像素个数偏移差得到*/ 
     N_cR0 = floor((RCM_in + 1)*Rt/Rbin); 
 
	 for( na =0 ;na < Na/2;na++) 
	 { 
		 if (na >(Na/2)*(B_d/PRF))  
			 Rat = sqrt((V_ami*Na/(2*PRF))*(V_ami*Na/(2*PRF)) + Rt*Rt); 
		 else  
			  Rat = sqrt( (V_ami*(na)/B_d)*(V_ami*(na)/B_d) +Rt*Rt);    
		 N_cRat = floor( (RCM_in + 1)*Rat/Rbin); 
		 for (nr = 0;nr < Nr;nr++) TD[nr] = complex<double>(*(LpRecSignalRe + na*Nr + nr),*(LpRecSignalIm + na*Nr + nr)); 
         FFT(TD, FD,wrp); 
         for (i = 0;i < Nr/2;i++) 
		 { 
			 LpTemFD[i] = FD[i]; 
             LpTemFD[RCM_in*Nr + Nr/2 + i] = FD[Nr/2 +i]; 
		 } 
		 for (i =  Nr/2; i< (RCM_in*Nr +Nr/2);i++) LpTemFD[i] = complex<double>(0,0); 
         IFFT(LpTemFD,LpTemTD,winp); 
		 /*将时域信号徙动进行校正*/ 
		 for (nr = 0;nr < Nr -int(floor((N_cRat -N_cR0)/(RCM_in+1)));nr++)  
		 { 
          *(LpRecSignalRe + na*Nr + nr) = LpTemTD[int(N_cRat -N_cR0) + nr*(RCM_in+1)].real(); 
          *(LpRecSignalIm + na*Nr + nr) = LpTemTD[int(N_cRat -N_cR0) + nr*(RCM_in+1)].imag();  
		 } 
         for (nr = Nr - int(floor((N_cRat -N_cR0)/(RCM_in+1)));nr < Nr;nr++) 
		 { 
           *(LpRecSignalRe + na*Nr + nr) = 0; 
           *(LpRecSignalIm + na*Nr + nr) = 0; 
		 } 
		  
		 /*对Na-na进行距离徙动校正*/ 
         for (nr =0;nr < Nr;nr++) TD[nr] = complex<double>(*(LpRecSignalRe + (Na-1-na)*Nr + nr),*(LpRecSignalIm + (Na-1 - na)*Nr + nr)); 
         FFT(TD, FD,wrp); 
         for (i = 0;i < Nr/2;i++) 
		 { 
			 LpTemFD[i] = FD[i]; 
             LpTemFD[RCM_in*Nr + Nr/2 + i] = FD[Nr/2 +i]; 
		 } 
		 for (i =  Nr/2; i< (RCM_in*Nr +Nr/2);i++) LpTemFD[i] = complex<double>(0,0); 
         IFFT(LpTemFD,LpTemTD,winp); 
		 /*将时域信号徙动进行校正*/ 
		 for (nr = 0;nr < Nr -int(floor((N_cRat -N_cR0)/(RCM_in+1)));nr++)  
		 { 
          *(LpRecSignalRe + (Na-1-na)*Nr + nr) = LpTemTD[int(N_cRat -N_cR0) + nr*(RCM_in+1)].real(); 
          *(LpRecSignalIm + (Na-1-na)*Nr + nr) = LpTemTD[int(N_cRat -N_cR0) + nr*(RCM_in+1)].imag();  
		 } 
         for (nr = Nr - int(floor((N_cRat -N_cR0)/(RCM_in+1)));nr < Nr;nr++) 
		 { 
           *(LpRecSignalRe + (Na-1-na)*Nr + nr) = 0; 
           *(LpRecSignalIm + (Na-1-na)*Nr + nr) = 0; 
		 } 
 
	 } 
	 delete TD; 
     delete FD; 
	 delete LpTemTD; 
     delete LpTemFD; 
 
 
} 
 
void CSAR::EchoAzimuthCompress() 
{ 
  if (LpAizm_Time ==NULL) return; 
  int na,nr,i,j; 
  double angle; 
  int w=1; 
  int wp=0; 
  int win = 1; 
  int winp = 0; 
  while(w * 2 <= Na) 
	{ 
		w *= 2; 
		wp++; 
	} 
  while(win * 2 <= (A_in+1)*Na) 
	{ 
		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]; 
  memset(TD,0,sizeof(double)*Na); 
  /*产生方位向匹配滤波器*/ 
  for (na = 0;na < NaEffective;na++) 
  { 
      angle = -PI*FR*LpAizm_Time[na]*LpAizm_Time[na]; 
      TD[na] = complex<double>(cos(angle),sin(angle)); 
  } 
    FFT(TD, FD,wp); 
	 //下面代码完成匹配滤波器中间插0 
   for(i = 0;i<Na/2;i++) 
   { 
       LpTemFilter[i] = FD[i]; 
	   LpTemFilter[A_in*Na + Na/2 + i] = FD[Na/2+i]; 
	} 
   for (j = Na/2;j < A_in*Na + Na/2;j++)  LpTemFilter[j] = complex<double>(0,0);//在滤波器中间插入A_in*Nr个0  
   for (nr = 0;nr <Nr; nr++) 
   { 
       //下面代码完成回波方位向多普勒信号中间插0 
	   for (na = 0;na<Na/2;na++) 
	   { 
	    LpTemFD[na] = complex<double>(LpRecSignalRe[na*Nr+nr], LpRecSignalIm[na*Nr+nr]); 
        LpTemFD[A_in*Na+Na/2+na] = complex<double>(LpRecSignalRe[(Na/2+na)*Nr+nr], LpRecSignalIm[(Na/2+na)*Nr+nr]); 
	   } 
	   for (na = Na/2;na<A_in*Na+Na/2;na++) LpTemFD[na] = complex<double>(0,0); 
	   //下面完成多普勒域方位向,通过与方位匹配滤波器点乘 
       for ( i = 0;i < (A_in+1)*Na;i++) LpTemFD[i] = LpTemFD[i]*LpTemFilter[i]; 
	   IFFT(LpTemFD,LpTemTD,winp); 
       for (j = int((A_in+1)*(Na-floor(NaEffective/2)));j < (A_in+1)*Na;j++) Temp[j-int((A_in+1)*(Na-floor(NaEffective/2)))] = LpTemTD[j];   
	   for (j = 1;j < int((A_in+1)*(Na-floor(NaEffective/2)));j++) Temp[j + int((A_in+1)*(floor(NaEffective/2)))] = LpTemTD[j]; 
       for (na = 0;na< Na;na++)  
	   { 
         LpRecSignalRe[na*Nr+nr] = Temp[A_in*int(floor(NaEffective/2)) +na].real();  
         LpRecSignalIm[na*Nr+nr] = Temp[A_in*int(floor(NaEffective/2)) +na].imag(); 
	   } 
    } 
   delete TD; 
   delete FD; 
   delete LpTemFilter; 
   delete LpTemFD; 
   delete LpTemTD; 
   delete Temp; 
    
} 
 
void CSAR::CSAParaInit() 
{ 
  int na,nr; 
  if (LpAizm_Frequency != NULL) delete LpAizm_Frequency; 
     LpAizm_Frequency = new double [Na]; 
   
  if ( LpAizm_Frequency != NULL) 
  { 
	  for (na = 0;na < Na;na++)  
	  { 
        LpAizm_Frequency[na] = -PRF/2.0 + na*PRF/Na; 
	  } 
  } 
 
  if (LpRange_Frequency != NULL) delete LpRange_Frequency; 
     LpRange_Frequency = new double [Nr]; 
  if (LpRange_Frequency != NULL)  
  { 
     for (nr = 0;nr < Nr;nr++)  
	  { 
        LpRange_Frequency[nr] = -FS/2.0 + (nr + 1)*FS/Nr; 
	  } 
  } 
 
  if (LpVTao != NULL) delete LpVTao; 
     LpVTao = new double [Nr]; 
  if (LpVTao != NULL)  
  { 
     for (nr = 0;nr < Nr;nr++)  
	  { 
        LpVTao[nr] = ((nr+1 - Nr/2.0)*Rbin + Rt)*2.0/C; 
	  } 
  }  
 
    if(LpBeta != NULL) delete LpBeta; 
	   LpBeta =  new double [Na]; 
    if (LpBeta != NULL) 
	{ 
      double Data; 
	  for (na = 0;na < Na;na++) 
	  { 
	  Data = Wavelenth*LpAizm_Frequency[na]/(2*V_ami); 
      LpBeta[na] = sqrt(1- Data*Data); 
      } 
	} 
 
  if( LpKsrcInv != NULL) delete LpKsrcInv; 
     LpKsrcInv = new double [Na]; 
  if(( LpKsrcInv !=NULL)&&(LpBeta != NULL)) 
  { 
     for (na = 0;na < Na;na++)  
	  { 
	    LpKsrcInv[na] = 2.0*Wavelenth*Ref*(1-pow(LpBeta[na],2))/C/C/(pow(LpBeta[na],3)); 
	  } 
  } 
 
  if(LpKm !=NULL) delete LpKm; 
     LpKm = new double [Na]; 
  if ((LpKm != NULL)&&(LpKsrcInv !=NULL)) 
  { 
   for (na = 0;na < Na;na++)  
   { 
     LpKm[na] = fabs(KR)/(1 + fabs(KR)*LpKsrcInv[na]); 
   } 
  } 
 
 
  if (LpVTaoRef != NULL) delete LpVTaoRef; 
     LpVTaoRef = new double [Na]; 
  if ((LpVTaoRef != NULL)&&(LpBeta != NULL))  
  {    
      for (na = 0;na < Na;na++)  
	  { 
	    LpVTaoRef[na] = 2.0*Ref/(LpBeta[na]*C); 
	  } 
  } 
   
} 
 
void CSAR::CSAChirpSacle() 
{ 
    int na,nr; 
	double angle; 
	complex<double> ChirpScaleData; 
	complex<double> ChirpScaleF; 
    for (nr = 0;nr< Nr;nr++) 
	{ 
     for (na = 0;na < Na;na++) 
	 { 
       angle = -PI*LpKm[na]*(1/LpBeta[na]-1)*(LpVTao[nr]-LpVTaoRef[na])*(LpVTao[nr]-LpVTaoRef[na]); 
	   ChirpScaleF = complex<double>(cos(angle),sin(angle));  
       ChirpScaleData = complex<double>(LpRecSignalRe[na*Nr+nr], LpRecSignalIm[na*Nr+nr]);  
       ChirpScaleData = ChirpScaleData*ChirpScaleF; 
       LpRecSignalRe[na*Nr+nr] = ChirpScaleData.real(); 
       LpRecSignalIm[na*Nr+nr] = ChirpScaleData.imag(); 
	 } 
    } 
	 
} 
 
void CSAR::CSAAzimuthFFT() 
{ 
  int w=1; 
  int wp=0; 
  int na,nr; 
  while(w * 2 <= Na) 
  { 
	w *= 2; 
	wp++; 
  } 
  complex<double> *TD = new complex<double>[w]; 
  complex<double> *FD = new complex<double>[w]; 
  memset(TD,0,sizeof(double)*w); 
  for (nr = 0;nr < Nr;nr++) 
  { 
    for (na = 0;na < Na;na++) 
		TD[na]= complex<double>(LpRecSignalRe[na*Nr+nr], LpRecSignalIm[na*Nr+nr]); 
        FFT(TD, FD,wp); 
    for (na = 0;na < Na;na++) 
	{ 
	 LpRecSignalRe[na*Nr+nr] = FD[na<w/2? na+w/2: na-w/2].real(); //保存方位向FFT变换的实部并作fftshift 
     LpRecSignalIm[na*Nr+nr] = FD[na<w/2? na+w/2: na-w/2].imag(); //保存方位向FFT变换的虚部并作fftshift 
	} 
  } 
  delete TD; 
  delete FD; 
 
} 
 
void CSAR::CSARangeCompress() 
{ 
  //首先要保证进行方位向FFT变换,变换到二维频域 
   int na,nr; 
   int w=1; 
   int wp=0; 
   double phase1,phase2,angle; 
   complex<double> CSARangeCompressF; 
   while(w * 2 <= Nr) 
   { 
    w *= 2; 
	wp++; 
   } 
   complex<double> *TD = new complex<double>[w]; 
   complex<double> *FD = new complex<double>[w]; 
   memset(FD,0,sizeof(double)*w); 
   memset(TD,0,sizeof(double)*w); 
   for(na = 0;na<Na;na++) 
   { 
    phase1 = -PI*(1/fabs(KR) + LpKsrcInv[na])*LpBeta[na]; 
    phase2 = 4.0*PI*Ref*(1.0/LpBeta[na] -1)/C; 
	for(nr = 0;nr<Nr;nr++) 
	{ 
      angle = (phase1*LpRange_Frequency[nr] + phase2)*LpRange_Frequency[nr]; 
      CSARangeCompressF = complex<double>(cos(angle),sin(angle)); 
	  TD[nr] = complex<double>(LpRecSignalRe[na*Nr+nr],LpRecSignalIm[na*Nr+nr]); 
	  FD[nr<w/2? nr+w/2:nr-w/2] = TD[nr]*CSARangeCompressF; 
	} 
     IFFT(FD, TD,wp); 
	 for(nr = 0;nr<Nr;nr++) 
	 { 
	  LpRecSignalRe[na*Nr+nr] = TD[nr].real(); 
      LpRecSignalIm[na*Nr+nr] = TD[nr].imag(); 
     } 
   } 
    delete FD; 
	delete TD; 
    
} 
 
void CSAR::CSAAzimuthCompress() 
{ 
   int na,nr; 
   int w=1; 
   int wp=0; 
   double phase1,phase2,angle; 
   complex<double> CSAAzimuthCompressF; 
   while(w * 2 <= Na) 
   { 
    w *= 2; 
	wp++; 
   } 
   complex<double> *TD = new complex<double>[w]; 
   complex<double> *FD = new complex<double>[w]; 
   memset(FD,0,sizeof(double)*w); 
   for (nr = 0;nr<Nr;nr++) 
   { 
	 for(na = 0;na < Na;na++) 
	 { 
	   phase1 = -4.0*PI*(1-LpBeta[na])/Wavelenth; 
       phase2 = 4.0*PI*LpKm[na]/C/C*(1/LpBeta[na])*(1/LpBeta[na]-1); 
       angle = phase1*LpVTao[nr]*C/2 +phase2*(LpVTao[nr]*C/2 -Ref)*(LpVTao[nr]*C/2 -Ref); 
       CSAAzimuthCompressF = complex<double>(cos(angle),sin(angle)); 
       FD[na] = complex<double>(LpRecSignalRe[na*Nr+nr], LpRecSignalIm[na*Nr+nr]); 
	   FD[na]= FD[na]* CSAAzimuthCompressF; 
	 } 
     IFFT(FD, TD,wp); 
     for(na = 0;na < Na;na++) 
	 { 
      LpRecSignalRe[na*Nr+nr] = TD[na].real(); 
      LpRecSignalIm[na*Nr+nr] = TD[na].imag(); 
	 } 
   } 
   delete TD; 
   delete FD; 
 
} 
 
void CSAR::CSARangeFFT() 
{ 
  int w=1; 
  int wp=0; 
  int na,nr; 
  while(w * 2 <= Nr) 
  { 
	w *= 2; 
	wp++; 
  } 
  complex<double> *TD = new complex<double>[w]; 
  complex<double> *FD = new complex<double>[w]; 
  memset(TD,0,sizeof(double)*w); 
  for (na = 0;na < Na;na++) 
  { 
    for (nr = 0;nr < Nr;nr++) 
		TD[nr]= complex<double>(LpRecSignalRe[na*Nr+nr], LpRecSignalIm[na*Nr+nr]); 
        FFT(TD, FD,wp); 
    for (nr = 0;nr < Nr;nr++) 
	{ 
	 LpRecSignalRe[na*Nr+nr] = FD[nr<w/2? nr+w/2: nr-w/2].real(); //保存距离向FFT变换的实部并作fftshift 
     LpRecSignalIm[na*Nr+nr] = FD[nr<w/2? nr+w/2: nr-w/2].imag(); //保存距离向FFT变换的虚部并作fftshift 
	} 
  } 
  delete TD; 
  delete FD; 
} 
/* 该函数通过打开面目标图像文件FileName,得到面目标图像的宽高及文件数据*/ 
/* 输入参数FileName, 输出参数 w,h, lpAreaImage                        */ 
void CSAR::GetAreaInformation(CString *FileName, int* w, int* h, BYTE **lpAreaImage) 
{ 
    CFile cf; 
    BITMAPFILEHEADER bfh; 
    BITMAPINFOHEADER bih; 
	if(!cf.Open(*FileName,CFile::modeReadWrite)) 
	{ 
		AfxMessageBox("Read AreaTarget Failure"); 
		return; 
	} 
 
	cf.Read(&bfh,sizeof(BITMAPFILEHEADER)); 
	cf.Read(&bih,sizeof(BITMAPINFOHEADER));	 
	if(bih.biBitCount!=0x0008) 
	{ 
	    AfxMessageBox("Area target must be  8bit scale bitmap"); 
	    return; 
	} 
	*h = bih.biHeight; 
	*w = bih.biWidth; 
	*lpAreaImage = new BYTE[(*w)*(*h)]; 
	if (*lpAreaImage == NULL)  
	{ 
		AfxMessageBox("Can't allocate memory"); 
		return; 
	} 
	cf.Seek(1024,CFile::current);/*隔过调色版不读*/    
	cf.ReadHuge(*lpAreaImage,(*w)*(*h)); 
}