2025年DSP TMS320C6657中FFT函数的调用与具体使用方法

DSP TMS320C6657中FFT函数的调用与具体使用方法首先明确一点 C6678 中 FFT 的函数形式为 N length of FFT in complex samples ptr x pointer to complex data input ptr w pointer to complex twiddle factor ptr y

大家好,我是讯享网,很高兴认识大家。

首先明确一点,C6678中FFT的函数形式为:
在这里插入图片描述
讯享网

N : length of FFT in complex samples ptr_x : pointer to complex data
input ptr_w : pointer to complex twiddle factor ptr_y : pointer to
complex output data brev : pointer to bit reverse table containing 64
entries n_min : should be 4 if N can be represented as Power of 4
else, n_min should be 2 offset : index in complex samples of sub-fft
from start of main fft n_max : size of main fft in complex
samples(可令n_max=N)

其中,64位bit反位表brev为: unsigned char brev[64] = { 0x00, 0x20, 0x10, 0x30,
0x08, 0x28, 0x18, 0x38, 0x04, 0x24, 0x14, 0x34, 0x0c, 0x2c, 0x1c,
0x3c, 0x02, 0x22, 0x12, 0x32, 0x0a, 0x2a, 0x1a, 0x3a, 0x06, 0x26,
0x16, 0x36, 0x0e, 0x2e, 0x1e, 0x3e, 0x01, 0x21, 0x11, 0x31, 0x09,
0x29, 0x19, 0x39, 0x05, 0x25, 0x15, 0x35, 0x0d, 0x2d, 0x1d, 0x3d,
0x03, 0x23, 0x13, 0x33, 0x0b, 0x2b, 0x1b, 0x3b, 0x07, 0x27, 0x17,
0x37, 0x0f, 0x2f, 0x1f, 0x3f };

旋转矩阵(旋转因子)ptr_w为: void tw_fft_gen (float *w, int n) { int i, j, k; for
(j = 1, k = 0; j <= n >> 2; j = j << 2) { for (i = 0; i < n >> 2; i +=
j) {
#ifdef _LITTLE_ENDIAN w[k] = (float) sin (2 * PI * i / n); w[k + 1] = (float) cos (2 * PI * i / n); w[k + 2] = (float) sin (4 * PI * i / n);
w[k + 3] = (float) cos (4 * PI * i / n); w[k + 4] = (float) sin (6 *
PI * i / n); w[k + 5] = (float) cos (6 * PI * i / n);
#else w[k] = (float) cos (2 * PI * i / n); w[k + 1] = (float) -sin (2 * PI * i / n); w[k + 2] = (float) cos (4 * PI * i / n); w[k + 3] = (float) -sin (4 * PI * i / n); w[k + 4] = (float) cos (6 * PI * i /
n); w[k + 5] = (float) -sin (6 * PI * i / n);
#endif k += 6; } } }

将下载好的库“dsplib_c66x_3_1_0_0”复制到CCS的安装路径下

2.添加头文件路径 右键点击工程–>Properties–>Build–>c6000 Compiler–>Include Options 在这里插入图片描述

3.添加库文件和库文件路径 右键点击工程–>Properties–>Build–>C6000 Linker–>File Search Path添加库文件和库文件路径
在这里插入图片描述

完成以上的准备工作后便可进行DSPF_sp_fftSPxSP函数的调用了。

在DSPC6657上的实际测试程序

#include <stdio.h> #include <stdlib.h> #include <c6x.h> #include <math.h> #include <dsplib.h> #define FFT_NUM 1024 //单次FFT变换数据个数 #define Double_FFT_NUM FFT_NUM * 2 //单次FFT变换数据个数的两倍 #define PI 3. //圆周率 float sin_data[1024] = { 
    1.000, 0.951, 0.809, 0.588, 0.309, 0.000, -0.309, -0.588, -0.809, -0.951, -1.000, -0.951, -0.809, -0.588, -0.309, -0.000, 0.309, 0.588, 0.809, 0.951, 1.000, 0.951, 0.809, 0.588, 0.309, -0.000, -0.309, -0.588, -0.809, -0.951, -1.000, -0.809, -0.588, -0.309, 0.000, 0.309, 0.588, 0.809, 0.951, 1.000, 0.951, 0.809, 0.588, 0.309, 0.000, -0.309, -0.588, -0.809, -0.951, -1.000, -0.951, -0.809, -0.588, -0.309, 0.000, 0.309, 0.588, 0.809, 0.951, 1.000, 0.951, 0.809, 0.309, -0.000, -0.309, -0.588, -0.809, -0.951, -1.000, -0.951, -0.809, -0.588, -0.309, 0.000, 0.309, 0.588, 0.809, 0.951, 1.000, 0.951, 0.809, 0.588, 0.309, -0.000, -0.309, -0.588, -0.809, -0.951, -1.000, -0.951, -0.809, -0.588, -0.309, 0.309, 0.588, 0.809, 0.951, 1.000, 0.951, 0.809, 0.588, 0.309, -0.000, -0.309, -0.588, -0.809, -0.951, -1.000, -0.951, -0.809, -0.588, -0.309, 0.000, 0.309, 0.588, 0.809, 0.951, 1.000, 0.951, 0.809, 0.588, 0.309, -0.000, -0.309, -0.809, -0.951, -1.000, -0.951, -0.809, -0.588, -0.309, 0.000, 0.309, 0.588, 0.809, 0.951, 1.000, 0.951, 0.809, 0.588, 0.309, -0.000, -0.309, -0.588, -0.809, -0.951, -1.000, -0.951, -0.809, -0.588, -0.309, 0.000, 0.309, 0.588, 0.809, 1.000, 0.951, 0.809, 0.588, 0.309, 0.000, -0.309, -0.588, -0.809, -0.951, -1.000, -0.951, -0.809, -0.588, -0.309, 0.000, 0.309, 0.588, 0.809, 0.951, 1.000, 0.951, 0.809, 0.588, 0.309, 0.000, -0.309, -0.588, -0.809, -0.951, -1.000, -0.809, -0.588, -0.309, 0.000, 0.309, 0.588, 0.809, 0.951, 1.000, 0.951, 0.809, 0.588, 0.309, -0.000, -0.309, -0.588, -0.809, -0.951, -1.000, -0.951, -0.809, -0.588, -0.309, -0.000, 0.309, 0.588, 0.809, 0.951, 1.000, 0.951, 0.809, 0.309, 0.000, -0.309, -0.588, -0.809, -0.951, -1.000, -0.951, -0.809, -0.588, -0.309, 0.000, 0.309, 0.588, 0.809, 0.951, 1.000, 0.951, 0.809, 0.588, 0.309, -0.000, -0.309, -0.588, -0.809, -0.951, -1.000, -0.951, -0.809, -0.588, -0.309, 0.309, 0.588, 0.809, 0.951, 1.000, 0.951, 0.809, 0.588, 0.309, 0.000, -0.309, -0.588, -0.809, -0.951, -1.000, -0.951, -0.809, -0.588, -0.309, 0.000, 0.309, 0.588, 0.809, 0.951, 1.000, 0.951, 0.809, 0.588, 0.309, -0.000, -0.309, -0.809, -0.951, -1.000, -0.951, -0.809, -0.588, -0.309, -0.000, 0.309, 0.588, 0.809, 0.951, 1.000, 0.951, 0.809, 0.588, 0.309, 0.000, -0.309, -0.588, -0.809, -0.951, -1.000, -0.951, -0.809, -0.588, -0.309, 0.000, 0.309, 0.588, 0.809, 1.000, 0.951, 0.809, 0.588, 0.309, -0.000, -0.309, -0.588, -0.809, -0.951, -1.000, -0.951, -0.809, -0.588, -0.309, 0.000, 0.309, 0.588, 0.809, 0.951, 1.000, 0.951, 0.809, 0.588, 0.309, -0.000, -0.309, -0.588, -0.809, -0.951, -1.000, -0.809, -0.588, -0.309, 0.000, 0.309, 0.588, 0.809, 0.951, 1.000, 0.951, 0.809, 0.588, 0.309, -0.000, -0.309, -0.588, -0.809, -0.951, -1.000, -0.951, -0.809, -0.588, -0.309, -0.000, 0.309, 0.588, 0.809, 0.951, 1.000, 0.951, 0.809, 0.309, 0.000, -0.309, -0.588, -0.809, -0.951, -1.000, -0.951, -0.809, -0.588, -0.309, 0.000, 0.309, 0.588, 0.809, 0.951, 1.000, 0.951, 0.809, 0.588, 0.309, -0.000, -0.309, -0.588, -0.809, -0.951, -1.000, -0.951, -0.809, -0.588, -0.309, 0.309, 0.588, 0.809, 0.951, 1.000, 0.951, 0.809, 0.588, 0.309, 0.000, -0.309, -0.588, -0.809, -0.951, -1.000, -0.951, -0.809, -0.588, -0.309, 0.000, 0.309, 0.588, 0.809, 0.951, 1.000, 0.951, 0.809, 0.588, 0.309, -0.000, -0.309, -0.809, -0.951, -1.000, -0.951, -0.809, -0.588, -0.309, -0.000, 0.309, 0.588, 0.809, 0.951, 1.000, 0.951, 0.809, 0.588, 0.309, -0.000, -0.309, -0.588, -0.809, -0.951, -1.000, -0.951, -0.809, -0.588, -0.309, -0.000, 0.309, 0.588, 0.809, 1.000, 0.951, 0.809, 0.588, 0.309, 0.000, -0.309, -0.588, -0.809, -0.951, -1.000, -0.951, -0.809, -0.588, -0.309, 0.000, 0.309, 0.588, 0.809, 0.951, 1.000, 0.951, 0.809, 0.588, 0.309, 0.000, -0.309, -0.588, -0.809, -0.951, -1.000, -0.809, -0.588, -0.309, 0.000, 0.309, 0.588, 0.809, 0.951, 1.000, 0.951, 0.809, 0.588, 0.309, -0.000, -0.309, -0.588, -0.809, -0.951, -1.000, -0.951, -0.809, -0.588, -0.309, 0.000, 0.309, 0.588, 0.809, 0.951, 1.000, 0.951, 0.809, 0.309, -0.000, -0.309, -0.588, -0.809, -0.951, -1.000, -0.951, -0.809, -0.588, -0.309, 0.000, 0.309, 0.588, 0.809, 0.951, 1.000, 0.951, 0.809, 0.588, 0.309, -0.000, -0.309, -0.588, -0.809, -0.951, -1.000, -0.951, -0.809, -0.588, -0.309, 0.309, 0.588, 0.809, 0.951, 1.000, 0.951, 0.809, 0.588, 0.309, 0.000, -0.309, -0.588, -0.809, -0.951, -1.000, -0.951, -0.809, -0.588, -0.309, -0.000, 0.309, 0.588, 0.809, 0.951, 1.000, 0.951, 0.809, 0.588, 0.309, -0.000, -0.309, -0.809, -0.951, -1.000, -0.951, -0.809, -0.588, -0.309, -0.000, 0.309, 0.588, 0.809, 0.951, 1.000, 0.951, 0.809, 0.588, 0.309, -0.000, -0.309, -0.588, -0.809, -0.951, -1.000, -0.951, -0.809, -0.588, -0.309, -0.000, 0.309, 0.588, 0.809, 1.000, 0.951, 0.809, 0.588, 0.309, -0.000, -0.309, -0.588, -0.809, -0.951, -1.000, -0.951, -0.809, -0.588, -0.309, 0.000, 0.309, 0.588, 0.809, 0.951, 1.000, 0.951, 0.809, 0.588, 0.309, -0.000, -0.309, -0.588, -0.809, -0.951, -1.000, -0.809, -0.588, -0.309, 0.000, 0.309, 0.588, 0.809, 0.951, 1.000, 0.951, 0.809, 0.588, 0.309, -0.000, -0.309, -0.588, -0.809, -0.951, -1.000, -0.951, -0.809, -0.588, -0.309, 0.000, 0.309, 0.588, 0.809, 0.951, 1.000, 0.951, 0.809, 0.309, 0.000, -0.309, -0.588, -0.809, -0.951, -1.000, -0.951, -0.809, -0.588, -0.309, -0.000, 0.309, 0.588, 0.809, 0.951, 1.000, 0.951, 0.809, 0.588, 0.309, 0.000, -0.309, -0.588, -0.809, -0.951, -1.000, -0.951, -0.809, -0.588, -0.309, 0.309, 0.588, 0.809, 0.951, 1.000, 0.951, 0.809, 0.588, 0.309, 0.000, -0.309, -0.588, -0.809, -0.951, -1.000, -0.951, -0.809, -0.588, -0.309, 0.000, 0.309, 0.588, 0.809, 0.951, 1.000, 0.951, 0.809, 0.588, 0.309, 0.000, -0.309, -0.809, -0.951, -1.000, -0.951, -0.809, -0.588, -0.309, 0.000, 0.309, 0.588, 0.809, 0.951, 1.000, 0.951, 0.809, 0.588, 0.309, -0.000, -0.309, -0.588, -0.809, -0.951, -1.000, -0.951, -0.809, -0.588, -0.309, 0.000, 0.309, 0.588, 0.809, 1.000, 0.951, 0.809, 0.588, 0.309, -0.000, -0.309, -0.588, -0.809, -0.951, -1.000, -0.951, -0.809, -0.588, -0.309, 0.000, 0.309, 0.588, 0.809, 0.951, 1.000, 0.951, 0.809, 0.588, 0.309, -0.000, -0.309, -0.588, -0.809, -0.951, -1.000, -0.809, -0.588, -0.309, 0.000, 0.309, 0.588, 0.809, 0.951, 1.000, 0.951, 0.809, 0.588, 0.309, 0.000, -0.309, -0.588, -0.809, -0.951, -1.000, -0.951, -0.809, -0.588, -0.309, -0.000, 0.309, 0.588, 0.809, 0.951, 1.000, 0.951, 0.809, 0.309, 0.000, -0.309, -0.588, -0.809, -0.951, -1.000, -0.951, -0.809, -0.588, -0.309, 0.000, 0.309, 0.588, 0.809, 0.951, 1.000, 0.951, 0.809, 0.588, 0.309, -0.000, -0.309, -0.588, -0.809, -0.951, -1.000, -0.951, -0.809, -0.588, -0.309, 0.309, 0.588, 0.809, 0.951, 1.000, 0.951, 0.809, 0.588, 0.309, 0.000, -0.309, -0.588, -0.809, -0.951, -1.000, -0.951, -0.809, -0.588, -0.309, 0.000, 0.309, 0.588, 0.809, 0.951, 1.000, 0.951, 0.809, 0.588, 0.309, -0.000, -0.309, -0.809, -0.951, -1.000, -0.951, -0.809, -0.588, -0.309, 0.000, 0.309, 0.588, 0.809, 0.951, 1.000, 0.951, 0.809, 0.588, 0.309, -0.000, -0.309, -0.588, -0.809, -0.951, -1.000, -0.951, -0.809, -0.588, -0.309, 0.000, 0.309, 0.588, 0.809, 1.000, 0.951, 0.809, 0.588, 0.309, 0.000, -0.309, -0.588, -0.809, -0.951, -1.000, -0.951, -0.809, -0.588, -0.309, -0.000, 0.309, 0.588, 0.809, 0.951, 1.000, 0.951, 0.809, 0.588, 0.309, -0.000, -0.309, -0.588, -0.809, -0.951, -1.000, -0.809, -0.588, -0.309, 0.000, 0.309, 0.588, 0.809, 0.951, 1.000, 0.951, 0.809, 0.588, 0.309, -0.000, -0.309, -0.588, -0.809, -0.951, -1.000, -0.951, -0.809, -0.588, -0.309, 0.000, 0.309, 0.588, 0.809, 0.951, 1.000, 0.951, 0.809 }; //bit reverse table containing 64 entries 64位bit反位表 ,倒置数组 unsigned char brev[64] = { 
    0x00, 0x20, 0x10, 0x30, 0x08, 0x28, 0x18, 0x38, 0x04, 0x24, 0x14, 0x34, 0x0c, 0x2c, 0x1c, 0x3c, 0x02, 0x22, 0x12, 0x32, 0x0a, 0x2a, 0x1a, 0x3a, 0x06, 0x26, 0x16, 0x36, 0x0e, 0x2e, 0x1e, 0x3e, 0x01, 0x21, 0x11, 0x31, 0x09, 0x29, 0x19, 0x39, 0x05, 0x25, 0x15, 0x35, 0x0d, 0x2d, 0x1d, 0x3d, 0x03, 0x23, 0x13, 0x33, 0x0b, 0x2b, 0x1b, 0x3b, 0x07, 0x27, 0x17, 0x37, 0x0f, 0x2f, 0x1f, 0x3f }; // data array float fft_output[Double_FFT_NUM]; //FFT变换输出数据 float fft_input[Double_FFT_NUM]; //FFT变换输入数据 float twiddle[Double_FFT_NUM]; //旋转矩阵(因子)(复数) //旋转因子(复数) void tw_fft_gen (float *w, int n) { 
    int i, j, k; for (j = 1, k = 0; j <= n >> 2; j = j << 2) { 
    for (i = 0; i < n >> 2; i += j) { 
    #ifdef _LITTLE_ENDIAN w[k] = (float) sin (2 * PI * i / n); w[k + 1] = (float) cos (2 * PI * i / n); w[k + 2] = (float) sin (4 * PI * i / n); w[k + 3] = (float) cos (4 * PI * i / n); w[k + 4] = (float) sin (6 * PI * i / n); w[k + 5] = (float) cos (6 * PI * i / n); #else w[k] = (float) cos (2 * PI * i / n); w[k + 1] = (float) -sin (2 * PI * i / n); w[k + 2] = (float) cos (4 * PI * i / n); w[k + 3] = (float) -sin (4 * PI * i / n); w[k + 4] = (float) cos (6 * PI * i / n); w[k + 5] = (float) -sin (6 * PI * i / n); #endif k += 6; } } } //FFT变换 void fft() { 
    int8_t radix = 0; uint32_t i=0; //generate FFT twiddle factors tw_fft_gen(twiddle, FFT_NUM); // if FFT_NUM can be represented as Power of 4, radix=4, else radix=2 if(FFT_NUM & 0x) { 
    radix = 4; } else { 
    radix = 2; } FILE *fpWrite=fopen("E:\\DSP-c66\\FFT_CCS_matlab_Demo.zip\\CCS\\SIN_FFT_data.txt","w"); // 将实数输入转化为复数输入 for(i = 0; i < FFT_NUM; i++) { 
    fft_input[2 * i] = (float)sin_data[i]; fft_input[2 * i + 1] = (float)0.0; } // fast fourier transform - FFT变换 DSPF_sp_fftSPxSP(FFT_NUM, (float *)fft_input, (float *)twiddle, (float *)fft_output, brev, radix, 0, FFT_NUM); printf("FFT done\n"); // output FFT data for(i=0;i<Double_FFT_NUM;i++) { 
    fprintf(fpWrite,"%lf\n ",fft_output[i]); } printf("write down done\n"); fclose(fpWrite); } int main(void) { 
    fft(); return 0; } 

讯享网

matlab可视化结果,对比DSP和MATLAB的运算结果:

讯享网clc clear all close all Fs = 1000; %采样率 data_length=1024; n = 2^nextpow2(data_length); Y=zeros(1,data_length); data=load('E:\DSP-c66\FFT_CCS_matlab_Demo.zip\CCS\SIN_FFT_data.txt'); %DSP运算结果 data=data'; for j=1:data_length j1=2*j; Y(j)=data(1,j1-1)+data(1,j1)*1i; end Y=abs(Y); Y = Y(1,1:n/2+1-100 ); F_resolution_1=(Fs/n).*(0:n/2-100 ); figure; plot(F_resolution_1,Y,'b');grid on hold on title('经CCS FFT变换后(正频域)'); T = 1/Fs; % Sampling period L = 1024; % Length of signal t = (0:L-1)*T; % Time vector x = cos(2*pi*50*t); % First row wave count = 1; x_length = length(x); figure subplot(2,1,1); plot(t(1:100),x(1,1:100));grid on hold on title(['原始信号']); n = 2^nextpow2(L); Y_fft = abs(fft(x,n)); Y_fft = Y_fft(1,1:n/2+1 ); F_resolution_2=(Fs/n).*(0:n/2 ); subplot(2,1,2); plot(F_resolution_2,Y_fft,'b');grid on hold on title(['经matlab FFT变换后']) fid=fopen('D:\sinx.txt','wt');%打开文件 for j=1:x_length if(count <= 31) fprintf(fid,'%.3f, ',x(j));%输出 count = count + 1; else fprintf(fid,'\n');%输出 count = 1; end end fclose(fid); %关闭fid标示符的文件 
小讯
上一篇 2025-03-11 22:24
下一篇 2025-03-21 15:02

相关推荐

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/74443.html