/*======================================================*/ /* K-K transformation program HP version K.Kobayshi 1996. 8. 26 */ /*======================================================*/ #include #include #include #include /** important!! **/ #include #define N 32768 #define SWAP(a,b) tempr=(a);(a)=(b);(b)=tempr void four1(data,nn,isign) float data[]; int nn,isign; { int n,mmax,m,j,istep,i; double wtemp,wr,wpr,wpi,wi,theta; float tempr,tempi; n=nn << 1; j=1; for (i=1;i i) { SWAP(data[j],data[i]); SWAP(data[j+1],data[i+1]); } m=n >> 1; while (m >= 2 && j > m) { j -= m; m >>= 1; } j += m; } mmax=2; while (n > mmax) { istep=2*mmax; theta=6.28318530717959/(isign*mmax); wtemp=sin(0.5*theta); wpr = -2.0*wtemp*wtemp; wpi=sin(theta); wr=1.0; wi=0.0; for (m=1;m> 1; n2=n+2; for (j=2;j<=m;j++) { wr=(wtemp=wr)*wpr-wi*wpi+wr; wi=wi*wpr+wtemp*wpi+wi; y1=0.5*(y[j]+y[n2-j]); y2=(y[j]-y[n2-j]); y[j]=y1-wi*y2; y[n2-j]=y1+wi*y2; sum += wr*y2; } realft(y,m,1); y[2]=sum; for (j=4;j<=n;j+=2) { sum += y[j]; y[j]=sum; } if (isign == -1) { even=y[1]; odd=y[2]; for (j=3;j<=n-1;j+=2) { even += y[j]; odd += y[j+1]; } enf0=2.0*(even-odd); sumo=y[1]-enf0; sume=(2.0*odd/n)-sumo; y[1]=0.5*enf0; y[2] -= sume; for (j=3;j<=n-1;j+=2) { y[j] -= sumo; y[j+1] -= sume; } } } /*imtre.c*/ main(argc,argv) int argc; char **argv; { float a[N],b[N],x,y; int i,j,m; FILE *ifp,*ofp,*fopen(); char fname[25]; if(argc!=3){ printf("\n%s [infile] [outfile] \n\n",argv[0]); exit(0); } if((ifp=fopen(argv[1],"r"))==NULL){ printf("This file (%s) can not open !!\n",argv[1]); exit(0); } if((ofp=fopen(argv[2],"w"))==NULL){ printf("This file (%s) can not open !!\n",argv[2]); exit(0); } printf("Enter data number "); scanf("%d",&m); for ( i=1; i <= m; ++i) { fscanf(ifp,"%g %g", &a[i], &b[i]); } for(i=m+1;i<=N;++i){ a[i]=0.0; b[i]=0.0; } fclose(ifp); sinft(b,N); for (i=1; i <= N; ++i) { b[i]*=2.0/N; } cosft(b,N,1); for ( i=1; i<=m; ++i) { fprintf(ofp, "%g %g\n",a[i],-1*b[i]); } printf("finished!!\n"); fclose(ofp); }