`#include <stdio.h>
#include <math.h>
#include <mathlib.h>
#include <dsplib.h>
#include <string.h>
#define PI 3.14159
#define F_TOL (1e-6)
#define Tn 1024
#define Fs 1000.0
float Input[2*Tn+4];
float CFFT_In[2*Tn+4];
float CFFT_InOrig[2*Tn+4];
float CFFT_InvOut[2*Tn+4];
float CTemp[2*Tn+4];
float Cw[2*Tn];
float Cmo[Tn+2];
unsigned char brev[64] =
{
0x0, 0x20, 0x10, 0x30, 0x8, 0x28, 0x18, 0x38,
0x4, 0x24, 0x14, 0x34, 0xc, 0x2c, 0x1c, 0x3c,
0x2, 0x22, 0x12, 0x32, 0xa, 0x2a, 0x1a, 0x3a,
0x6, 0x26, 0x16, 0x36, 0xe, 0x2e, 0x1e, 0x3e,
0x1, 0x21, 0x11, 0x31, 0x9, 0x29, 0x19, 0x39,
0x5, 0x25, 0x15, 0x35, 0xd, 0x2d, 0x1d, 0x3d,
0x3, 0x2b, 0x1b, 0x3b, 0xb, 0x2b, 0x1b, 0x3b,
0x7, 0x2f, 0x1f, 0x3f, 0xf, 0x2f, 0x1f, 0x3f,
};
void tw_gen(float *w, int n) {
int i, j, k;
double theta1, theta2, theta3;
for (j = 1, k = 0; j <= n >> 2; j = j << 2) {
for (i = 0; i < n >> 2; i += j) {
theta1 = 2 * PI * i / n;
w[k] = (float)cos(theta1);
w[k + 1] = (float)sin(theta1);
theta2 = 4 * PI * i / n;
w[k + 2] = (float)cos(theta2);
w[k + 3] = (float)sin(theta2);
theta3 = 6 * PI * i / n;
w[k + 4] = (float)cos(theta3);
w[k + 5] = (float)sin(theta3);
k += 6;
}
}
}
void FFTTest() {
unsigned int i;
for(i=0;i<Tn;i++)
Input[i]=5*sin(2*PI*150*(i/Fs))+15*sin(2*PI*350*(i/Fs));
unsigned char rad;
if(Tn==16 || Tn==64 || Tn==256 || Tn==1024 || Tn==4096 || Tn==16384 || Tn==65536)
rad=4;
else if(Tn==8 || Tn==32 || Tn==128 || Tn==512 || Tn==2048 || Tn==8192 || Tn==32768)
rad=2;
else
{
printf("Tn的值不合适\n");
return;
}
for (i=0;i<2*Tn;i++)
CFFT_In[i]=0.0;
for(i=0; i<Tn; i++)
{
CFFT_In[2*i]=Input[i];
CFFT_In[2*i+1]=0;
}
memcpy(CFFT_InOrig,CFFT_In,2*Tn*sizeof(float));
tw_gen(Cw, Tn);
float CFFT_Out[2*Tn];
DSPF_sp_fftSPxSP(Tn,CFFT_In,Cw,CFFT_Out,brev,rad,0,Tn);
for(i=0;i<Tn;i++)
{
Cmo[i]=sqrt(CFFT_Out[2*i]*CFFT_Out[2*i]+CFFT_Out[2*i+1]*CFFT_Out[2*i+1]);
Cmo[i]=Cmo[i]*2/Tn;
}
memcpy(CTemp,CFFT_Out,2*Tn*sizeof(float));
DSPF_sp_ifftSPxSP(Tn, CFFT_In, Cw, CFFT_Out, brev, rad, 0, Tn);
memcpy(CFFT_InvOut, CFFT_Out, 2*Tn*sizeof(float));
// 输出检测结果
printf("FFT 输出检测:\n");
unsigned char Flag = 0;
for (i=0; i<Tn; i++) {
if (fabs(CFFT_InOrig[i] - CFFT_InvOut[i]) > F_TOL) {
Flag = 1;
break;
}
}
if (Flag == 1)
printf("失败!\n");
else
printf("成功!\n");
}
int main() {
printf("FFT 测试开始\n");
FFTTest();
printf("FFT 测试完成\n");
return 0;
}`
![6P}ZDVA(T9TA1_8H2(RX.png
调用过dsplib和mathlib库,只要运行到FFTTEST的函数 就会报错,不清楚是调用错误还是仿真不支持。
报错:Can't find a source file at "/tmp/TI_MKLIB429RQi/SRC/boot.c"
Locate the file or edit the source lookup path to include its location.
控制台报错:TMS320C64X+_0: Error: Illegal opcode (40252766) at pc = 0x80014094 Illegal opcode at pc = 0x80014094
(TMS320C64X+_0:是默认名字,实际还是C6748的没有不匹配)
更多回帖