how_to_use_fft.c

来自「this file is even FFT, max point is 8192」· C语言 代码 · 共 59 行

C
59
字号
#include "stdio.h"
#include <stdlib.h>

#define OFDM_TOTAL_CARRIER 8192

#ifndef NMAX
#define NMAX 8192
#define NMAXSQRT 64
#endif

typedef float fft_type;

void cdft(int, int, fft_type *, int *, fft_type *);

void test_cdft()
{
   int i, fft_length;
	int ip[NMAXSQRT + 2];
   fft_type w[NMAX * 5 / 4];
   fft_type *ofdm_data;

	FILE *fid1, *fid2;
//====== Initialization =======
   ip[0] = 0; // initial 
   fft_length = OFDM_TOTAL_CARRIER*2;
   ofdm_data = malloc(fft_length * sizeof(fft_type));
//====== End of Initialization =======




//===== assign input of fft
	for(i=0;i<fft_length;i++){
      ofdm_data[i] = i;
	}

   if( (fid1=fopen("fft_input.txt","w")) == (FILE *)NULL ){
      printf("Could not open file \n");
	}
	else{
      for(i=0;i<fft_length;i++){
         fprintf(fid1, "%f\n", ofdm_data[i]);
		}
	}

//====== compute FFT
   cdft(fft_length, -1, ofdm_data, ip, w); 

	
	if( (fid2=fopen("fft_output.txt","w")) == (FILE *)NULL ){
      printf("Could not open file \n");
	}
	else{
      for(i=0;i<fft_length;i++){
         fprintf(fid2, "%f\n", ofdm_data[i]);
		}
	}

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?