📄 dft_dsp.c
字号:
// dft_DSP.c
// compute the fft and remove the complex mirror.
#include "receiver.h"
#include <math.h>
#include <stdio.h>
#include <C:/ti/c6700/dsplib/include/dspf_sp_cfftr2_dit.h>
#include "bit_rev.h"
//#pragma DATA_ALIGN(input, 8); // this has to be done in the main function
#pragma DATA_ALIGN(w,8);
//define the twiddle coefficients used to compute dft
float w[2 * 128] =
{
1.000000, 0.000000, 0.000000, 1.000000, 0.707107, 0.707107, -0.707107, 0.707107,
0.923880, 0.382683, -0.382683, 0.923880, 0.382683, 0.923880, -0.923880, 0.382683,
0.980785, 0.195090, -0.195090, 0.980785, 0.555570, 0.831470, -0.831470, 0.555570,
0.831470, 0.555570, -0.555570, 0.831470, 0.195090, 0.980785, -0.980785, 0.195090,
0.995185, 0.098017, -0.098017, 0.995185, 0.634393, 0.773010, -0.773010, 0.634393,
0.881921, 0.471397, -0.471397, 0.881921, 0.290285, 0.956940, -0.956940, 0.290285,
0.956940, 0.290285, -0.290285, 0.956940, 0.471397, 0.881921, -0.881921, 0.471397,
0.773010, 0.634393, -0.634393, 0.773010, 0.098017, 0.995185, -0.995185, 0.098017,
0.998795, 0.049068, -0.049068, 0.998795, 0.671559, 0.740951, -0.740951, 0.671559,
0.903989, 0.427555, -0.427555, 0.903989, 0.336890, 0.941544, -0.941544, 0.336890,
0.970031, 0.242980, -0.242980, 0.970031, 0.514103, 0.857729, -0.857729, 0.514103,
0.803208, 0.595699, -0.595699, 0.803208, 0.146730, 0.989177, -0.989177, 0.146730,
0.989177, 0.146730, -0.146730, 0.989177, 0.595699, 0.803208, -0.803208, 0.595699,
0.857729, 0.514103, -0.514103, 0.857729, 0.242980, 0.970031, -0.970031, 0.242980,
0.941544, 0.336890, -0.336890, 0.941544, 0.427555, 0.903989, -0.903989, 0.427555,
0.740951, 0.671559, -0.671559, 0.740951, 0.049068, 0.998795, -0.998795, 0.049068,
0.999699, 0.024541, -0.024541, 0.999699, 0.689541, 0.724247, -0.724247, 0.689541,
0.914210, 0.405241, -0.405241, 0.914210, 0.359895, 0.932993, -0.932993, 0.359895,
0.975702, 0.219101, -0.219101, 0.975702, 0.534998, 0.844854, -0.844854, 0.534998,
0.817585, 0.575808, -0.575808, 0.817585, 0.170962, 0.985278, -0.985278, 0.170962,
0.992480, 0.122411, -0.122411, 0.992480, 0.615232, 0.788346, -0.788346, 0.615232,
0.870087, 0.492898, -0.492898, 0.870087, 0.266713, 0.963776, -0.963776, 0.266713,
0.949528, 0.313682, -0.313682, 0.949528, 0.449611, 0.893224, -0.893224, 0.449611,
0.757209, 0.653173, -0.653173, 0.757209, 0.073565, 0.997290, -0.997290, 0.073565,
0.997290, 0.073565, -0.073565, 0.997290, 0.653173, 0.757209, -0.757209, 0.653173,
0.893224, 0.449611, -0.449611, 0.893224, 0.313682, 0.949528, -0.949528, 0.313682,
0.963776, 0.266713, -0.266713, 0.963776, 0.492898, 0.870087, -0.870087, 0.492898,
0.788346, 0.615232, -0.615232, 0.788346, 0.122411, 0.992480, -0.992480, 0.122411,
0.985278, 0.170962, -0.170962, 0.985278, 0.575808, 0.817585, -0.817585, 0.575808,
0.844854, 0.534998, -0.534998, 0.844854, 0.219101, 0.975702, -0.975702, 0.219101,
0.932993, 0.359895, -0.359895, 0.932993, 0.405241, 0.914210, -0.914210, 0.405241,
0.724247, 0.689541, -0.689541, 0.724247, 0.024541, 0.999699, -0.999699, 0.024541
};
// input in normal order, output in bit reversed
// order, coefficient table in bit-reversed
// order
#define FFT_SIZE 256
void dft_DSP(float *in, float *out) {
// we compute only once this value
float inv_size_fft=_rcpsp(16); //sqrtf(FFT_SIZE));
int i;
// compute the fft
DSPF_sp_cfftr2_dit(in, w, FFT_SIZE);
// re reverse the output
bit_rev(in, 2*FFT_SIZE>>1);
// remove the complex mirror and scale
for (i=0;i<NR_OF_CHANNELS*2;i++)
{
out[i]=in[i+2+6]*inv_size_fft;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -