// file: clpc_cal_5.cc // // this function computes the dft coefficients of a signal // // system include file // #include #include // local include file // #include "global_constants.h" #include "calculate_lpc_constants.h" #include "calculate_lpc.h" // function: calculate_dft_cc // // arguments: // float**& dft_spect_coeffs_a: (output) buffer contains the dft of // the signal // float* signal_window_a: (input) buffer of signal // int samples_per_win_a: (input) number of samples per window // int num_chans_a: (input) number of channels // int dft_order_a: (input) type of window // int debug_mode_a: (input) debug level // // return: an int to indicate status // // this function calculates the dft of a signal using the equation below: // x(k) = sum ( x(n) * exp (-j * 2 * pi * k * n / N) ) n = 0 .. N-1 // // where k is the current sample ranging from 0 .. N-1 // and N is the order of the DFT // // int calculate_dft_cc (float**& dft_spect_coeffs_a, float* signal_window_a, int samples_per_win_a, int num_chans_a, int dft_order_a, int debug_mode_a) { int dft_samples = dft_order_a * num_chans_a; int signal_samples = samples_per_win_a * num_chans_a; float* temp_window = new float[dft_samples]; // pad signal with 0s if dft order is larger than window // for (int sample = 0; sample < dft_samples; sample++) { if (sample < signal_samples) { temp_window[sample] = signal_window_a[sample]; } else { temp_window[sample] = 0; } } for (int chan = 0; chan < num_chans_a; chan++) { for (int index = 0; index < dft_order_a; index++) { float twiddle_factor_rl = 0; float twiddle_factor_img = 0; int samp = 0; for (int sample = chan; sample < dft_samples; sample += num_chans_a) { float expn = 2.0 * M_PI * samp * index / dft_order_a; twiddle_factor_rl += temp_window[sample] * cos(expn); twiddle_factor_img -= temp_window[sample] * sin(expn); samp++; } dft_spect_coeffs_a[chan][index] = sqrt((twiddle_factor_rl * twiddle_factor_rl) + (twiddle_factor_img * twiddle_factor_img)); } } if (debug_mode_a > DEBUG_FULL) { for (int chan = 0; chan < num_chans_a; chan++) { for (int index = 0; index < dft_order_a; index++) { fprintf(stdout, "chan %d :: dft coeff [%d] = %.6f\n", chan, index, dft_spect_coeffs_a[chan][index]); } } fprintf(stdout, "\n"); } // delete scratch space // if (temp_window != (float*)NULL) { delete [] temp_window; temp_window = (float*)NULL; } // exit gracefully // return TRUE; }