Xem mẫu

  1. int iter,i,k; int k1,inc1; int k2,j,k3,k4; char *buff1,*buff2,tmp; long loc; buff1=(char *)malloc(N*sizeof(char)); buff2=(char *)malloc(N*sizeof(char)); N1=N/2; inc=1; inc1=2; 10 04 24 34 00 20 30 14 00 01 02 03 04 05 06 07 11 05 25 35 01 21 31 15 10 12 16 11 13 14 15 17 12 06 16 26 36 02 22 32 21 23 25 27 20 22 24 26 13 07 17 27 37 03 23 33 30 31 32 33 34 35 36 37 44 54 64 74 40 50 60 70 41 43 45 47 40 42 44 46 45 55 65 75 41 51 61 71 50 52 51 53 55 57 54 56 46 66 61 63 65 67 56 76 42 52 62 72 60 62 64 66 47 67 57 77 43 53 63 73 70 74 76 71 72 73 75 77 b­íc 0 b­íc 2 10 40 60 00 20 30 50 70 02 06 10 12 16 04 14 00 11 41 61 01 21 31 51 71 03 07 11 13 17 05 15 01 12 42 62 02 22 32 52 72 20 30 22 32 24 34 26 36 13 43 63 03 23 33 53 73 21 31 23 33 25 35 27 37 40 44 54 04 14 24 34 44 54 64 74 42 46 50 52 56 53 57 41 43 47 45 55 05 15 25 35 45 55 65 75 51 60 62 66 64 74 70 72 76 16 46 66 06 26 36 56 76 61 63 67 65 75 71 73 77 17 47 67 07 27 37 57 77 b­íc 1 Ma trËn chuyÓn vÞ 116
  2. Hình 6.10 Thuật toán của Eklundh cho dịch chuyển một ma trận. for(iter=0;iter
  3. for(j=k3;j
  4. inc1*=2; N1/=2; } Để kiểm tra chương trình 6.5 chúng ta sẽ áp dụng thuật toán này lên ảnh cho trong hình 6.11. ảnh này chứa trên đĩa đi kèm theo cuốn sách này dưới file có tên là “MOHSEN.IMG”. Chương trình 6.6 “ FFT2D.C” 2-D FFT /****************************** * Program developed by: * * M.A.Sid-Ahmed. * * ver. 1.0 1992. * * @ 1994 * ******************************/ /* 2D-FFT - Using Decimation-in-time routine.*/ #define pi 3.141592654 #include #include #include #include #include #include void bit_reversal(unsigned int *, int , int); void WTS(float *, float *, int, int); void FFT(float *xr, float *xi, float *, float *, int, int ) ; void transpose(FILE *, int, int); void FFT2D(FILE *, FILE *, float *, float*, unsigned int *,int,int,int); 119
  5. Hình 6.11 Ảnh đã được dịch chuyển, "MOHSEN.IMG". void main() { int N,n2,m,k,i; unsigned int *L; float *wr , *wi; char file_name[14]; FILE *fptr,*fptro; double nsq; clrscr(); printf(" Enter name of input file-> "); scanf("%s",file_name); if((fptr=fopen(file_name,"rb"))==NULL) { printf("file %s does not exist.\n"); exit(1); } nsq=(double)filelength(fileno(fptr)); N=sqrt(nsq); m=(int)(log10((double)N)/log10((double)2.0)); k=1 ; 120
  6. for(i=0;i1)-1; wr=(float *)malloc(n2*sizeof(float)); 121
  7. wi=(float *)malloc(n2*sizeof(float)); /*Generating LUT for twiddle factors. */ WTS(wr,wi,N,-1); FFT2D(fptr,fptro,wr,wi,L,N,m,-1); } void FFT2D(FILE *fptr, FILE *fptro, float *wr, float *wi, unsigned int *L, int N, int m, int sign) { /* 2-D FFT Algorithm. */ /* fptr=file pointer to input file. fptro=file pointer to output file. Note: fptr, fptro should be opened in the main routine. They are closed before return to @he main routine. wr[1,wj[I input arrays for twiddle factors, calculated by calling procedure WTS. L[I look-up table for bit reversal. N input array size ( NxN words.) =2 to the power m. sign =-1 for 2-D FFT, =1 for 2-D IFFT. For FFT (sign= 1) the input data is assumed to be real. The result of the FFT has its origin shifted to (N/2,N/2).*/ int N2,i,j,k,kk; long loc,NB; float *xr,*xi,*buff; N2=N
  8. /* First stage. */ gotoxy(1,3); printf(" First stage. "); for(j=0;j
  9. printf(" Transposing of intermediate file. "); rewind(fptro); transpose(fptro,N,m); rewind(fptro); /* Second stage. */ printf("\n Second stage."); for(j=0;j
  10. fwrite(buff,NB,1,fptro); } fclose(fptro); } void FFT (float *xr, float *xi, float *wr, float *wi, int m, int N) { /* FFT algorithm. Decimation-in-time algorithm. Note: 1. N=2 to the power of m. 2. The input arrays are assumed to be rearranged in bit-reverse order. You will need to use routine "bit-reversal" for that purpose. 3. The twiddle factors are assumed to be stored in LUT's wr[] and wi[]. You will need to use routine LUT for calculating and storing twiddle factors. */ int ip,k,kk,l,incr,iter,i,j; float Tr,Ti; ip=1; kk=(N>>1); incr=2 ; for(iter=0; iter
nguon tai.lieu . vn