fft_T.cpp
上传用户:jtjnyq9001
上传日期:2014-11-21
资源大小:3974k
文件大小:5k
源码类别:

3G开发

开发平台:

Visual C++

  1. //
  2. //  File = dc_fft.cpp
  3. //
  4. #include <iostream> 
  5. #include <fstream>
  6. #include <complex>
  7. #include "dit_pino_T.h"
  8. #include "fft_T.h"
  9. #include "cbitrev_T.h"
  10. using namespace std;
  11. //======================================================
  12. template< class T>
  13. void IFFT(  complex<T>* sample_spectrum,
  14.             complex<T>* time_signal,
  15.             int num_samps )
  16. {
  17.     int i;
  18.     for(i=0; i<num_samps; i++){
  19.         time_signal[i] = sample_spectrum[i];
  20.     }
  21.     ComplexBitReverse<T>(time_signal, num_samps);
  22.     IfftDitPino<T>(time_signal, num_samps);
  23.     return;
  24. }
  25. //======================================================
  26. template <class T>
  27. void FFT(   complex<T>* time_signal,
  28.             complex<T>* sample_spectrum,
  29.             int num_samps )
  30. {
  31.     int i;
  32.     for(i=0; i<num_samps; i++){
  33.         sample_spectrum[i] = time_signal[i];
  34.     }
  35.     ComplexBitReverse<T>(sample_spectrum,num_samps);
  36.     FftDitPino<T>(sample_spectrum, num_samps);
  37.     return;
  38. }
  39. //======================================================
  40. template <class T>
  41. void FFT(   complex<double>* time_signal,
  42.             complex<T>* sample_spectrum,
  43.             int num_samps,
  44.             int fft_len )
  45. {
  46.     int i;
  47.     for(i=0; i<num_samps; i++){
  48.         sample_spectrum[i] = time_signal[i];
  49.     }
  50.     for(i=num_samps; i<fft_len; i++){
  51.         sample_spectrum[i] = float_complex(0.0,0.0);
  52.     }
  53. #ifdef _FFT_SIGNAL_DUMP
  54.     ofstream time_sig_file("wind_sig.txt", ios::out);
  55.     for(i=0; i<fft_len; i++){
  56.         time_sig_file << i << ", " << real(sample_spectrum[i]) << endl;
  57.     }
  58.     time_sig_file.close();
  59. #endif
  60.     ComplexBitReverse<T>(sample_spectrum, fft_len);
  61.     FftDitPino<T>(sample_spectrum, fft_len);
  62.     return;
  63. }
  64. //======================================================
  65. template <class T>
  66. void FFT(   complex<float>* time_signal,
  67.             complex<T>* sample_spectrum,
  68.             int num_samps,
  69.             int fft_len )
  70. {
  71.     int i;
  72.     for(i=0; i<num_samps; i++){
  73.         sample_spectrum[i] = time_signal[i];
  74.     }
  75.     for(i=num_samps; i<fft_len; i++){
  76.         sample_spectrum[i] = complex<T>(0.0,0.0);
  77.     }
  78. #ifdef _FFT_SIGNAL_DUMP
  79.     ofstream time_sig_file("wind_sig.txt", ios::out);
  80.     for(i=0; i<fft_len; i++){
  81.         time_sig_file << i << ", " 
  82.                       << real(sample_spectrum[i]) << endl;
  83.     }
  84.     time_sig_file.close();
  85. #endif
  86.     ComplexBitReverse<T>(sample_spectrum, fft_len);
  87.     FftDitPino<T>(sample_spectrum, fft_len);
  88.     return;
  89. }
  90. //======================================================
  91. template <class T>
  92. void FFT(   double* time_signal,
  93.             complex<T>* sample_spectrum,
  94.             int num_samps,
  95.             int fft_len )
  96. {
  97.     int i;
  98.     for(i=0; i<num_samps; i++){
  99.         sample_spectrum[i] = 
  100.                          complex<T>(time_signal[i],0.0);
  101.     }
  102.     for(i=num_samps; i<fft_len; i++){
  103.         sample_spectrum[i] = complex<T>(0.0,0.0);
  104.     }
  105. #ifdef _FFT_SIGNAL_DUMP
  106.     ofstream time_sig_file("wind_sig.txt", ios::out);
  107.     for(i=0; i<fft_len; i++){
  108.         time_sig_file << i << ", " 
  109.                     << real(sample_spectrum[i]) << endl;
  110.     }
  111.     time_sig_file.close();
  112. #endif
  113.     ComplexBitReverse<T>(sample_spectrum, fft_len);
  114.     FftDitPino<T>(sample_spectrum, fft_len);
  115.     return;
  116. }
  117. //======================================================
  118. template <class T>
  119. void FFT(   float* time_signal,
  120.             complex<T>* sample_spectrum,
  121.             int num_samps,
  122.             int fft_len )
  123. {
  124.     int i;
  125.     for(i=0; i<num_samps; i++) {
  126.         sample_spectrum[i] = complex<T>(time_signal[i],0.0);
  127.     }
  128.     for(i=num_samps; i<fft_len; i++) {
  129.         sample_spectrum[i] = complex<T>(0.0,0.0);
  130.     }
  131. #ifdef _FFT_SIGNSL_DUMP
  132.     ofstream time_sig_file("wind_sig.txt", ios::out);
  133.     for(i=0; i<fft_len; i++) {
  134.         time_sig_file << i << ", " << real(sample_spectrum[i]) << endl;
  135.     }
  136.     time_sig_file.close();
  137. #endif
  138.     ComplexBitReverse<T>(sample_spectrum, fft_len);
  139.     FftDitPino<T>(sample_spectrum, fft_len);
  140.     return;
  141. }
  142. //======================================================
  143. template <class T> 
  144. void FFT( complex<T>* signal,
  145.           int num_samps )
  146. {
  147.  ComplexBitReverse<T>(signal, num_samps);
  148.  FftDitPino<T>(signal, num_samps);
  149.  return;
  150. }
  151. //======================================================
  152. template void IFFT<double>( std::complex<double>* sample_spectrum,
  153.                     std::complex<double>* time_signal,
  154.                     int num_samps );
  155. template void FFT<double>( std::complex<double>* time_signal,
  156.                     std::complex<double>* sample_spectrum,
  157.                     int num_samps );
  158. template void FFT<double>( std::complex<float>* time_signal,
  159.                             std::complex<double>* sample_spectrum,
  160.                             int num_samps,
  161.                             int fft_len );
  162. template void FFT<double>( double* time_signal,
  163.                             std::complex<double>* sample_spectrum,
  164.                             int num_samps,
  165.                             int fft_len );
  166. template void FFT<double>( float* time_signal,
  167.                             std::complex<double>* sample_spectrum,
  168.                             int num_samps,
  169.                             int fft_len );