TMS320F28335调用官方库进行FFT频谱分析
TMS320F28335调用官方库进行FFT频谱分析
移植
首先进入TI官网下载软件支持包,我们需要的FFT官方包就在这里边。
TMS320F28335 data sheet, product information and support | TI.com
下载完成后,解压。进入以下目录
C2000Ware_4_01_00_00_Software__all\C2000Ware_4_01_00_00\libraries\dsp\FPU\c28
里面只需要Include、source文件夹的内容,lib文件夹不需要,新版本库一律被集成到了rts2800 fpu32.ib这个库里面了。
Include:复制到你的工程中备用,将里面fpu64文件夹删除,fpu32文件夹里的除了f2837xd_filter文件夹全整理出来到include文件夹中。整理完如下:
source:同样复制到你的工程目录即可,删除里面的C28x_FPU_LIB_DEPRECATED文件夹和fpu64文件夹,并把fpu32文件夹内容整理出来。整理完如下
并且把fft文件夹里面带有TMU0后缀的汇编源码全部删除了
此时的你的CCS工程应该有如下文件树:
打开工程设置将头文件路径添加进去
因为只用到实傅里叶变化和实时计算旋转因子表,可以将fft文件夹中的cfft和table都删除了,此时fft文件夹应只有有如下源码文件
到这一步,官方的FFT源码移植完成了。
测试
测试可以直接使用官方的测试数据和代码进行测试,在下载软件包C2000Ware_4_01_00_00\libraries\dsp\FPU\c28\examples\fft\rfft_adc_f32 目录中可以找到
其中的dsp_rfft_adc.c 、golden.c、input.c 为测试FFT计算程序、正确数据、输入数据。
大致流程为输入的数据经过FFT计算后与正确数据进行比对。
在这里我提供一套我自己编写的测试程序。
以下是我编写的FFT相关参数,12位ADC、1000Hz采样频率、1024采样点,输入信号如下图:
RFFT.h
/*
* RFFT.h
*
* Created on: 2022年11月2日
* Author: Administrator
*/
#ifndef APP_RFFT_H_
#define APP_RFFT_H_
#include "DSP28x_Project.h"
#include <stdio.h>
#include <string.h>
#define RFFT_Analyse_MaxNum 20
typedef struct {
Uint16 Wave_Num;
float DC_Amp;
float Amp[RFFT_Analyse_MaxNum];
float freq[RFFT_Analyse_MaxNum];
float Phase[RFFT_Analyse_MaxNum];
} RFFT_Analyse_Struct;
void RFFT_ADC_Init();
void RFFT_ADC_Caculate();
float RFFT_Fractional_Frequency(float ratio);
void RFFT_Analyse(float *src);
float RFFT_Phase_Caculate(Uint16 index,float ratio);
Uint16 RFFT_Peak_Find(float *src ,Uint16 len,Uint16 *index); //幅度谱及其长度
#endif /* APP_RFFT_H_ */
RFFT.c
/*
* RFFT.c
*
* Created on: 2022年11月2日
* Author: Administrator
*/
#include "dsp.h"
#include "fpu_rfft.h"
#include "RFFT.h"
#include <math.h>
#include "complex.h"
#define Fs 1000
#define FFT_STAGES (10U) //迭代次数 =Log2(FFT_SIZE)
#define FFT_SIZE (1 << FFT_STAGES) //FFT计算点数
RFFT_F32_STRUCT rfft;
RFFT_ADC_F32_STRUCT rfft_adc;
RFFT_F32_STRUCT_Handle hnd_rfft = &rfft;
RFFT_ADC_F32_STRUCT_Handle hnd_rfft_adc = &rfft_adc;
RFFT_Analyse_Struct rfft_analyse;
//#pragma DATA_SECTION(FFT_input, "FFT_buffer");
#pragma DATA_SECTION(FFT_output, "FFT_buffer1");
#pragma DATA_SECTION(FFT_twiddleFactors, "FFT_buffer2");
#pragma DATA_SECTION(FFT_magnitude_phase, "FFT_buffer3");
//uint16_t FFT_input[FFT_SIZE];
extern uint16_t FFT_input[2U*FFT_SIZE];
float FFT_twiddleFactors[FFT_SIZE];
float FFT_output[FFT_SIZE];
float FFT_magnitude_phase[(FFT_SIZE >> 1) + 1];
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
float myabs;
void RFFT_ADC_Init()
{
RFFT_f32_setInputPtr(hnd_rfft, (float *)FFT_input);
RFFT_f32_setOutputPtr(hnd_rfft, FFT_output);
RFFT_f32_setStages(hnd_rfft, FFT_STAGES);
RFFT_f32_setFFTSize(hnd_rfft, FFT_SIZE);
RFFT_f32_setMagnitudePtr(hnd_rfft, FFT_magnitude_phase);
RFFT_f32_setPhasePtr(hnd_rfft, FFT_magnitude_phase);
RFFT_f32_setTwiddlesPtr(hnd_rfft, FFT_twiddleFactors);
RFFT_f32_sincostable(hnd_rfft);
RFFT_ADC_f32_setTailPtr(hnd_rfft_adc, &(hnd_rfft->OutBuf));
RFFT_ADC_f32_setInBufPtr(hnd_rfft_adc, FFT_input);
}
void RFFT_ADC_Caculate()
{
float* temp;
RFFT_adc_f32(hnd_rfft_adc);
RFFT_f32_mag(hnd_rfft);
temp=RFFT_f32_getMagnitudePtr(hnd_rfft);
RFFT_Analyse(temp);
}
float RFFT_Phase_Caculate(Uint16 index,float ratio)
{
complex p;
complex FFT_value;
p=(1-cexpf((2*M_PI*ratio/FFT_SIZE)*I));
p=p/ (1-cexpf((2*M_PI*ratio)*I));
FFT_value=FFT_output[index]+FFT_output[FFT_SIZE-index]*I;
p=FFT_value*p;
return (cargf(p)+M_PI/2);
}
Uint16 RFFT_Peak_Find(float *src ,Uint16 len,Uint16 *index) //幅度谱及其长度
{
Uint16 num=0;
Uint16 i;
float max_data=0;
float data1=0;
float data2=0;
float data3=0;
for (i=1;i<len;i++)
{
if(*(src+i)>max_data)
max_data=*(src+i);
}
for (i=1;i<len-1;i++)
{
data1=*(src+i-1);
data2=*(src+i);
data3=*(src+i+1);
if((data1<data2) && (data2>data3) && (data2 >max_data*0.1))
{
if(num<20)
{
*(index+num)=i;
num++;
}
else
return num;
}
}
return num;
}
float RFFT_Fractional_Frequency(float ratio)
{
Uint16 niter;
float K,f,a,b,y,yp;
f=0;
K=(M_PI/FFT_SIZE) * sin(M_PI/FFT_SIZE);
for(niter=0;niter<20;niter++)
{
a = sin(M_PI*f/FFT_SIZE);
b = sin(M_PI*(f-1)/FFT_SIZE);
y = ratio - a/b;
yp = K / (b*b);
f = MAX(-0.5, MIN(f - y/yp, 0.5));
}
return f;
}
void RFFT_Analyse(float *src)
{
Uint16 i;
float ratio;
float FFT_Value;
Uint16 peak_index[RFFT_Analyse_MaxNum];
memset(peak_index, 0U, RFFT_Analyse_MaxNum*sizeof(Uint16));
memset(rfft_analyse.freq, 0U, RFFT_Analyse_MaxNum*sizeof(float));
memset(rfft_analyse.Amp, 0U, RFFT_Analyse_MaxNum*sizeof(float));
memset(rfft_analyse.Phase, 0U, RFFT_Analyse_MaxNum*sizeof(float));
rfft_analyse.Wave_Num=RFFT_Peak_Find(src,FFT_SIZE/2,peak_index);
for(i=0;i<rfft_analyse.Wave_Num;i++)
{
FFT_Value=*(src+peak_index[i]);
ratio = (*(src+peak_index[i]+1))/FFT_Value;
if ((*(src+peak_index[i]+1)) > (*(src+peak_index[i]-1)))
ratio = -ratio;
ratio = RFFT_Fractional_Frequency(ratio);
rfft_analyse.freq[i] = (*(peak_index+i)-1+ratio)*Fs/FFT_SIZE;
rfft_analyse.Amp[i] = 2 *FFT_Value * fabsf(sin(M_PI*ratio/FFT_SIZE)/sin(M_PI*ratio));
rfft_analyse.Phase[i] = RFFT_Phase_Caculate(peak_index[i],ratio);
}
for(i=0;i<rfft_analyse.Wave_Num;i++)
{
rfft_analyse.Phase[i]=rfft_analyse.Phase[i]-rfft_analyse.Phase[0];
rfft_analyse.Phase[i]=rfft_analyse.Phase[i]*180/M_PI;
}
rfft_analyse.DC_Amp=*src/FFT_SIZE;
}
input.c
//#############################################################################
//! \file input.c
//! \brief Input Vector (512)
//! \author Vishal Coelho
//! \date 22-Aug-2016
//!
//
// Group: C2000
// Target Family: $DEVICE$
//
//#############################################################################
//
//
// $Copyright: Copyright (C) 2020 Texas Instruments Incorporated -
// http://www.ti.com/ ALL RIGHTS RESERVED $
//#############################################################################
#include <stdint.h>
#pragma DATA_SECTION(FFT_input, "FFT_buffer3")
// Matrix is 2 times its required sizeas it will be used to store
// 1024 floats at a later point
uint16_t FFT_input[2048] = {
3.077914e+03, 2.842787e+03, 2.357726e+03, 2.614976e+03,
2.258888e+03, 2.628179e+03, 2.054902e+03, 2.438736e+03,
1.750881e+03, 1.040492e+03, 3.077914e+03, 2.589702e+03,
1.876330e+03, 1.952391e+03, 1.479973e+03, 1.809179e+03,
1.275987e+03, 1.776151e+03, 1.269484e+03, 7.874067e+02,
3.077914e+03, 2.842787e+03, 2.357726e+03, 2.614976e+03,
2.258888e+03, 2.628179e+03, 2.054902e+03, 2.438736e+03,
1.750881e+03, 1.040492e+03, 3.077914e+03, 2.589702e+03,
1.876330e+03, 1.952391e+03, 1.479973e+03, 1.809179e+03,
1.275987e+03, 1.776151e+03, 1.269484e+03, 7.874067e+02,
3.077914e+03, 2.842787e+03, 2.357726e+03, 2.614976e+03,
2.258888e+03, 2.628179e+03, 2.054902e+03, 2.438736e+03,
1.750881e+03, 1.040492e+03, 3.077914e+03, 2.589702e+03,
1.876330e+03, 1.952391e+03, 1.479973e+03, 1.809179e+03,
1.275987e+03, 1.776151e+03, 1.269484e+03, 7.874067e+02,
3.077914e+03, 2.842787e+03, 2.357726e+03, 2.614976e+03,
2.258888e+03, 2.628179e+03, 2.054902e+03, 2.438736e+03,
1.750881e+03, 1.040492e+03, 3.077914e+03, 2.589702e+03,
1.876330e+03, 1.952391e+03, 1.479973e+03, 1.809179e+03,
1.275987e+03, 1.776151e+03, 1.269484e+03, 7.874067e+02,
3.077914e+03, 2.842787e+03, 2.357726e+03, 2.614976e+03,
2.258888e+03, 2.628179e+03, 2.054902e+03, 2.438736e+03,
1.750881e+03, 1.040492e+03, 3.077914e+03, 2.589702e+03,
1.876330e+03, 1.952391e+03, 1.479973e+03, 1.809179e+03,
1.275987e+03, 1.776151e+03, 1.269484e+03, 7.874067e+02,
3.077914e+03, 2.842787e+03, 2.357726e+03, 2.614976e+03,
2.258888e+03, 2.628179e+03, 2.054902e+03, 2.438736e+03,
1.750881e+03, 1.040492e+03, 3.077914e+03, 2.589702e+03,
1.876330e+03, 1.952391e+03, 1.479973e+03, 1.809179e+03,
1.275987e+03, 1.776151e+03, 1.269484e+03, 7.874067e+02,
3.077914e+03, 2.842787e+03, 2.357726e+03, 2.614976e+03,
2.258888e+03, 2.628179e+03, 2.054902e+03, 2.438736e+03,
1.750881e+03, 1.040492e+03, 3.077914e+03, 2.589702e+03,
1.876330e+03, 1.952391e+03, 1.479973e+03, 1.809179e+03,
1.275987e+03, 1.776151e+03, 1.269484e+03, 7.874067e+02,
3.077914e+03, 2.842787e+03, 2.357726e+03, 2.614976e+03,
2.258888e+03, 2.628179e+03, 2.054902e+03, 2.438736e+03,
1.750881e+03, 1.040492e+03, 3.077914e+03, 2.589702e+03,
1.876330e+03, 1.952391e+03, 1.479973e+03, 1.809179e+03,
1.275987e+03, 1.776151e+03, 1.269484e+03, 7.874067e+02,
3.077914e+03, 2.842787e+03, 2.357726e+03, 2.614976e+03,
2.258888e+03, 2.628179e+03, 2.054902e+03, 2.438736e+03,
1.750881e+03, 1.040492e+03, 3.077914e+03, 2.589702e+03,
1.876330e+03, 1.952391e+03, 1.479973e+03, 1.809179e+03,
1.275987e+03, 1.776151e+03, 1.269484e+03, 7.874067e+02,
3.077914e+03, 2.842787e+03, 2.357726e+03, 2.614976e+03,
2.258888e+03, 2.628179e+03, 2.054902e+03, 2.438736e+03,
1.750881e+03, 1.040492e+03, 3.077914e+03, 2.589702e+03,
1.876330e+03, 1.952391e+03, 1.479973e+03, 1.809179e+03,
1.275987e+03, 1.776151e+03, 1.269484e+03, 7.874067e+02,
3.077914e+03, 2.842787e+03, 2.357726e+03, 2.614976e+03,
2.258888e+03, 2.628179e+03, 2.054902e+03, 2.438736e+03,
1.750881e+03, 1.040492e+03, 3.077914e+03, 2.589702e+03,
1.876330e+03, 1.952391e+03, 1.479973e+03, 1.809179e+03,
1.275987e+03, 1.776151e+03, 1.269484e+03, 7.874067e+02,
3.077914e+03, 2.842787e+03, 2.357726e+03, 2.614976e+03,
2.258888e+03, 2.628179e+03, 2.054902e+03, 2.438736e+03,
1.750881e+03, 1.040492e+03, 3.077914e+03, 2.589702e+03,
1.876330e+03, 1.952391e+03, 1.479973e+03, 1.809179e+03,
1.275987e+03, 1.776151e+03, 1.269484e+03, 7.874067e+02,
3.077914e+03, 2.842787e+03, 2.357726e+03, 2.614976e+03,
2.258888e+03, 2.628179e+03, 2.054902e+03, 2.438736e+03,
1.750881e+03, 1.040492e+03, 3.077914e+03, 2.589702e+03,
1.876330e+03, 1.952391e+03, 1.479973e+03, 1.809179e+03,
1.275987e+03, 1.776151e+03, 1.269484e+03, 7.874067e+02,
3.077914e+03, 2.842787e+03, 2.357726e+03, 2.614976e+03,
2.258888e+03, 2.628179e+03, 2.054902e+03, 2.438736e+03,
1.750881e+03, 1.040492e+03, 3.077914e+03, 2.589702e+03,
1.876330e+03, 1.952391e+03, 1.479973e+03, 1.809179e+03,
1.275987e+03, 1.776151e+03, 1.269484e+03, 7.874067e+02,
3.077914e+03, 2.842787e+03, 2.357726e+03, 2.614976e+03,
2.258888e+03, 2.628179e+03, 2.054902e+03, 2.438736e+03,
1.750881e+03, 1.040492e+03, 3.077914e+03, 2.589702e+03,
1.876330e+03, 1.952391e+03, 1.479973e+03, 1.809179e+03,
1.275987e+03, 1.776151e+03, 1.269484e+03, 7.874067e+02,
3.077914e+03, 2.842787e+03, 2.357726e+03, 2.614976e+03,
2.258888e+03, 2.628179e+03, 2.054902e+03, 2.438736e+03,
1.750881e+03, 1.040492e+03, 3.077914e+03, 2.589702e+03,
1.876330e+03, 1.952391e+03, 1.479973e+03, 1.809179e+03,
1.275987e+03, 1.776151e+03, 1.269484e+03, 7.874067e+02,
3.077914e+03, 2.842787e+03, 2.357726e+03, 2.614976e+03,
2.258888e+03, 2.628179e+03, 2.054902e+03, 2.438736e+03,
1.750881e+03, 1.040492e+03, 3.077914e+03, 2.589702e+03,
1.876330e+03, 1.952391e+03, 1.479973e+03, 1.809179e+03,
1.275987e+03, 1.776151e+03, 1.269484e+03, 7.874067e+02,
3.077914e+03, 2.842787e+03, 2.357726e+03, 2.614976e+03,
2.258888e+03, 2.628179e+03, 2.054902e+03, 2.438736e+03,
1.750881e+03, 1.040492e+03, 3.077914e+03, 2.589702e+03,
1.876330e+03, 1.952391e+03, 1.479973e+03, 1.809179e+03,
1.275987e+03, 1.776151e+03, 1.269484e+03, 7.874067e+02,
3.077914e+03, 2.842787e+03, 2.357726e+03, 2.614976e+03,
2.258888e+03, 2.628179e+03, 2.054902e+03, 2.438736e+03,
1.750881e+03, 1.040492e+03, 3.077914e+03, 2.589702e+03,
1.876330e+03, 1.952391e+03, 1.479973e+03, 1.809179e+03,
1.275987e+03, 1.776151e+03, 1.269484e+03, 7.874067e+02,
3.077914e+03, 2.842787e+03, 2.357726e+03, 2.614976e+03,
2.258888e+03, 2.628179e+03, 2.054902e+03, 2.438736e+03,
1.750881e+03, 1.040492e+03, 3.077914e+03, 2.589702e+03,
1.876330e+03, 1.952391e+03, 1.479973e+03, 1.809179e+03,
1.275987e+03, 1.776151e+03, 1.269484e+03, 7.874067e+02,
3.077914e+03, 2.842787e+03, 2.357726e+03, 2.614976e+03,
2.258888e+03, 2.628179e+03, 2.054902e+03, 2.438736e+03,
1.750881e+03, 1.040492e+03, 3.077914e+03, 2.589702e+03,
1.876330e+03, 1.952391e+03, 1.479973e+03, 1.809179e+03,
1.275987e+03, 1.776151e+03, 1.269484e+03, 7.874067e+02,
3.077914e+03, 2.842787e+03, 2.357726e+03, 2.614976e+03,
2.258888e+03, 2.628179e+03, 2.054902e+03, 2.438736e+03,
1.750881e+03, 1.040492e+03, 3.077914e+03, 2.589702e+03,
1.876330e+03, 1.952391e+03, 1.479973e+03, 1.809179e+03,
1.275987e+03, 1.776151e+03, 1.269484e+03, 7.874067e+02,
3.077914e+03, 2.842787e+03, 2.357726e+03, 2.614976e+03,
2.258888e+03, 2.628179e+03, 2.054902e+03, 2.438736e+03,
1.750881e+03, 1.040492e+03, 3.077914e+03, 2.589702e+03,
1.876330e+03, 1.952391e+03, 1.479973e+03, 1.809179e+03,
1.275987e+03, 1.776151e+03, 1.269484e+03, 7.874067e+02,
3.077914e+03, 2.842787e+03, 2.357726e+03, 2.614976e+03,
2.258888e+03, 2.628179e+03, 2.054902e+03, 2.438736e+03,
1.750881e+03, 1.040492e+03, 3.077914e+03, 2.589702e+03,
1.876330e+03, 1.952391e+03, 1.479973e+03, 1.809179e+03,
1.275987e+03, 1.776151e+03, 1.269484e+03, 7.874067e+02,
3.077914e+03, 2.842787e+03, 2.357726e+03, 2.614976e+03,
2.258888e+03, 2.628179e+03, 2.054902e+03, 2.438736e+03,
1.750881e+03, 1.040492e+03, 3.077914e+03, 2.589702e+03,
1.876330e+03, 1.952391e+03, 1.479973e+03, 1.809179e+03,
1.275987e+03, 1.776151e+03, 1.269484e+03, 7.874067e+02,
3.077914e+03, 2.842787e+03, 2.357726e+03, 2.614976e+03,
2.258888e+03, 2.628179e+03, 2.054902e+03, 2.438736e+03,
1.750881e+03, 1.040492e+03, 3.077914e+03, 2.589702e+03,
1.876330e+03, 1.952391e+03, 1.479973e+03, 1.809179e+03,
1.275987e+03, 1.776151e+03, 1.269484e+03, 7.874067e+02,
3.077914e+03, 2.842787e+03, 2.357726e+03, 2.614976e+03,
2.258888e+03, 2.628179e+03, 2.054902e+03, 2.438736e+03,
1.750881e+03, 1.040492e+03, 3.077914e+03, 2.589702e+03,
1.876330e+03, 1.952391e+03, 1.479973e+03, 1.809179e+03,
1.275987e+03, 1.776151e+03, 1.269484e+03, 7.874067e+02,
3.077914e+03, 2.842787e+03, 2.357726e+03, 2.614976e+03,
2.258888e+03, 2.628179e+03, 2.054902e+03, 2.438736e+03,
1.750881e+03, 1.040492e+03, 3.077914e+03, 2.589702e+03,
1.876330e+03, 1.952391e+03, 1.479973e+03, 1.809179e+03,
1.275987e+03, 1.776151e+03, 1.269484e+03, 7.874067e+02,
3.077914e+03, 2.842787e+03, 2.357726e+03, 2.614976e+03,
2.258888e+03, 2.628179e+03, 2.054902e+03, 2.438736e+03,
1.750881e+03, 1.040492e+03, 3.077914e+03, 2.589702e+03,
1.876330e+03, 1.952391e+03, 1.479973e+03, 1.809179e+03,
1.275987e+03, 1.776151e+03, 1.269484e+03, 7.874067e+02,
3.077914e+03, 2.842787e+03, 2.357726e+03, 2.614976e+03,
2.258888e+03, 2.628179e+03, 2.054902e+03, 2.438736e+03,
1.750881e+03, 1.040492e+03, 3.077914e+03, 2.589702e+03,
1.876330e+03, 1.952391e+03, 1.479973e+03, 1.809179e+03,
1.275987e+03, 1.776151e+03, 1.269484e+03, 7.874067e+02,
3.077914e+03, 2.842787e+03, 2.357726e+03, 2.614976e+03,
2.258888e+03, 2.628179e+03, 2.054902e+03, 2.438736e+03,
1.750881e+03, 1.040492e+03, 3.077914e+03, 2.589702e+03,
1.876330e+03, 1.952391e+03, 1.479973e+03, 1.809179e+03,
1.275987e+03, 1.776151e+03, 1.269484e+03, 7.874067e+02,
3.077914e+03, 2.842787e+03, 2.357726e+03, 2.614976e+03,
2.258888e+03, 2.628179e+03, 2.054902e+03, 2.438736e+03,
1.750881e+03, 1.040492e+03, 3.077914e+03, 2.589702e+03,
1.876330e+03, 1.952391e+03, 1.479973e+03, 1.809179e+03,
1.275987e+03, 1.776151e+03, 1.269484e+03, 7.874067e+02,
3.077914e+03, 2.842787e+03, 2.357726e+03, 2.614976e+03,
2.258888e+03, 2.628179e+03, 2.054902e+03, 2.438736e+03,
1.750881e+03, 1.040492e+03, 3.077914e+03, 2.589702e+03,
1.876330e+03, 1.952391e+03, 1.479973e+03, 1.809179e+03,
1.275987e+03, 1.776151e+03, 1.269484e+03, 7.874067e+02,
3.077914e+03, 2.842787e+03, 2.357726e+03, 2.614976e+03,
2.258888e+03, 2.628179e+03, 2.054902e+03, 2.438736e+03,
1.750881e+03, 1.040492e+03, 3.077914e+03, 2.589702e+03,
1.876330e+03, 1.952391e+03, 1.479973e+03, 1.809179e+03,
1.275987e+03, 1.776151e+03, 1.269484e+03, 7.874067e+02,
3.077914e+03, 2.842787e+03, 2.357726e+03, 2.614976e+03,
2.258888e+03, 2.628179e+03, 2.054902e+03, 2.438736e+03,
1.750881e+03, 1.040492e+03, 3.077914e+03, 2.589702e+03,
1.876330e+03, 1.952391e+03, 1.479973e+03, 1.809179e+03,
1.275987e+03, 1.776151e+03, 1.269484e+03, 7.874067e+02,
3.077914e+03, 2.842787e+03, 2.357726e+03, 2.614976e+03,
2.258888e+03, 2.628179e+03, 2.054902e+03, 2.438736e+03,
1.750881e+03, 1.040492e+03, 3.077914e+03, 2.589702e+03,
1.876330e+03, 1.952391e+03, 1.479973e+03, 1.809179e+03,
1.275987e+03, 1.776151e+03, 1.269484e+03, 7.874067e+02,
3.077914e+03, 2.842787e+03, 2.357726e+03, 2.614976e+03,
2.258888e+03, 2.628179e+03, 2.054902e+03, 2.438736e+03,
1.750881e+03, 1.040492e+03, 3.077914e+03, 2.589702e+03,
1.876330e+03, 1.952391e+03, 1.479973e+03, 1.809179e+03,
1.275987e+03, 1.776151e+03, 1.269484e+03, 7.874067e+02,
3.077914e+03, 2.842787e+03, 2.357726e+03, 2.614976e+03,
2.258888e+03, 2.628179e+03, 2.054902e+03, 2.438736e+03,
1.750881e+03, 1.040492e+03, 3.077914e+03, 2.589702e+03,
1.876330e+03, 1.952391e+03, 1.479973e+03, 1.809179e+03,
1.275987e+03, 1.776151e+03, 1.269484e+03, 7.874067e+02,
3.077914e+03, 2.842787e+03, 2.357726e+03, 2.614976e+03,
2.258888e+03, 2.628179e+03, 2.054902e+03, 2.438736e+03,
1.750881e+03, 1.040492e+03, 3.077914e+03, 2.589702e+03,
1.876330e+03, 1.952391e+03, 1.479973e+03, 1.809179e+03,
1.275987e+03, 1.776151e+03, 1.269484e+03, 7.874067e+02,
3.077914e+03, 2.842787e+03, 2.357726e+03, 2.614976e+03,
2.258888e+03, 2.628179e+03, 2.054902e+03, 2.438736e+03,
1.750881e+03, 1.040492e+03, 3.077914e+03, 2.589702e+03,
1.876330e+03, 1.952391e+03, 1.479973e+03, 1.809179e+03,
1.275987e+03, 1.776151e+03, 1.269484e+03, 7.874067e+02,
3.077914e+03, 2.842787e+03, 2.357726e+03, 2.614976e+03,
2.258888e+03, 2.628179e+03, 2.054902e+03, 2.438736e+03,
1.750881e+03, 1.040492e+03, 3.077914e+03, 2.589702e+03,
1.876330e+03, 1.952391e+03, 1.479973e+03, 1.809179e+03,
1.275987e+03, 1.776151e+03, 1.269484e+03, 7.874067e+02,
3.077914e+03, 2.842787e+03, 2.357726e+03, 2.614976e+03,
2.258888e+03, 2.628179e+03, 2.054902e+03, 2.438736e+03,
1.750881e+03, 1.040492e+03, 3.077914e+03, 2.589702e+03,
1.876330e+03, 1.952391e+03, 1.479973e+03, 1.809179e+03,
1.275987e+03, 1.776151e+03, 1.269484e+03, 7.874067e+02,
3.077914e+03, 2.842787e+03, 2.357726e+03, 2.614976e+03,
2.258888e+03, 2.628179e+03, 2.054902e+03, 2.438736e+03,
1.750881e+03, 1.040492e+03, 3.077914e+03, 2.589702e+03,
1.876330e+03, 1.952391e+03, 1.479973e+03, 1.809179e+03,
1.275987e+03, 1.776151e+03, 1.269484e+03, 7.874067e+02,
3.077914e+03, 2.842787e+03, 2.357726e+03, 2.614976e+03,
2.258888e+03, 2.628179e+03, 2.054902e+03, 2.438736e+03,
1.750881e+03, 1.040492e+03, 3.077914e+03, 2.589702e+03,
1.876330e+03, 1.952391e+03, 1.479973e+03, 1.809179e+03,
1.275987e+03, 1.776151e+03, 1.269484e+03, 7.874067e+02,
3.077914e+03, 2.842787e+03, 2.357726e+03, 2.614976e+03,
2.258888e+03, 2.628179e+03, 2.054902e+03, 2.438736e+03,
1.750881e+03, 1.040492e+03, 3.077914e+03, 2.589702e+03,
1.876330e+03, 1.952391e+03, 1.479973e+03, 1.809179e+03,
1.275987e+03, 1.776151e+03, 1.269484e+03, 7.874067e+02,
3.077914e+03, 2.842787e+03, 2.357726e+03, 2.614976e+03,
2.258888e+03, 2.628179e+03, 2.054902e+03, 2.438736e+03,
1.750881e+03, 1.040492e+03, 3.077914e+03, 2.589702e+03,
1.876330e+03, 1.952391e+03, 1.479973e+03, 1.809179e+03,
1.275987e+03, 1.776151e+03, 1.269484e+03, 7.874067e+02,
3.077914e+03, 2.842787e+03, 2.357726e+03, 2.614976e+03,
2.258888e+03, 2.628179e+03, 2.054902e+03, 2.438736e+03,
1.750881e+03, 1.040492e+03, 3.077914e+03, 2.589702e+03,
1.876330e+03, 1.952391e+03, 1.479973e+03, 1.809179e+03,
1.275987e+03, 1.776151e+03, 1.269484e+03, 7.874067e+02,
3.077914e+03, 2.842787e+03, 2.357726e+03, 2.614976e+03,
2.258888e+03, 2.628179e+03, 2.054902e+03, 2.438736e+03,
1.750881e+03, 1.040492e+03, 3.077914e+03, 2.589702e+03,
1.876330e+03, 1.952391e+03, 1.479973e+03, 1.809179e+03,
1.275987e+03, 1.776151e+03, 1.269484e+03, 7.874067e+02,
3.077914e+03, 2.842787e+03, 2.357726e+03, 2.614976e+03,
2.258888e+03, 2.628179e+03, 2.054902e+03, 2.438736e+03,
1.750881e+03, 1.040492e+03, 3.077914e+03, 2.589702e+03,
1.876330e+03, 1.952391e+03, 1.479973e+03, 1.809179e+03,
1.275987e+03, 1.776151e+03, 1.269484e+03, 7.874067e+02,
3.077914e+03, 2.842787e+03, 2.357726e+03, 2.614976e+03,
2.258888e+03, 2.628179e+03, 2.054902e+03, 2.438736e+03,
1.750881e+03, 1.040492e+03, 3.077914e+03, 2.589702e+03,
1.876330e+03, 1.952391e+03, 1.479973e+03, 1.809179e+03,
1.275987e+03, 1.776151e+03, 1.269484e+03, 7.874067e+02,
3.077914e+03, 2.842787e+03, 2.357726e+03, 2.614976e+03,
2.258888e+03, 2.628179e+03, 2.054902e+03, 2.438736e+03,
1.750881e+03, 1.040492e+03, 3.077914e+03, 2.589702e+03,
1.876330e+03, 1.952391e+03, 1.479973e+03, 1.809179e+03,
1.275987e+03, 1.776151e+03, 1.269484e+03, 7.874067e+02,
3.077914e+03, 2.842787e+03, 2.357726e+03, 2.614976e+03,
};
// End of File
cmd文件:
/*
// TI File $Revision: /main/3 $
// Checkin $Date: July 9, 2008 14:12:45 $
//###########################################################################
//
// FILE: 28335_RAM_lnk.cmd
//
// TITLE: Linker Command File For IQmath examples that run out of RAM
//
// NOTE; The example project uses memory protected by the
// Code Security Module (CSM). Make sure the CSM is
// unlocked before you load the project. One quick way
// to do this on an erased device is to open a memory
// window to the CSM password locations. If these locations
// read back 0xFFFF (or non-zero), then the CSM is unlocked:
//
// Device Password locations
// 28335: 0x33FFF8 - 0x33FFFF
//
//###########################################################################
//
//
// $Copyright: Copyright (C) 2014-2022 Texas Instruments Incorporated -
// http://www.ti.com/ ALL RIGHTS RESERVED $
//###########################################################################
*/
MEMORY
{
PAGE 0 :
BEGIN : origin = 0x000000, length = 0x000002 /* Boot to M0 will go here */
BOOT_RSVD : origin = 0x000002, length = 0x00004E /* Part of M0, BOOT rom will use this for stack */
RAML0 : origin = 0x008000, length = 0x000800
RAML1L2 : origin = 0x008800, length = 0x004800
ZONE7A : origin = 0x200000, length = 0x00FC00 /* XINTF zone 7 - program space */
FLASHH : origin = 0x300000, length = 0x008000 /* on-chip FLASH */
FLASHG : origin = 0x308000, length = 0x008000 /* on-chip FLASH */
FLASHF : origin = 0x310000, length = 0x008000 /* on-chip FLASH */
FLASHE : origin = 0x318000, length = 0x008000 /* on-chip FLASH */
FLASHD : origin = 0x320000, length = 0x008000 /* on-chip FLASH */
FLASHC : origin = 0x328000, length = 0x008000 /* on-chip FLASH */
FLASHA : origin = 0x338000, length = 0x007F80 /* on-chip FLASH */
CSM_RSVD : origin = 0x33FF80, length = 0x000076 /* Part of FLASHA. Program with all 0x0000 when CSM is in use. */
CSM_PWL : origin = 0x33FFF8, length = 0x000008 /* Part of FLASHA. CSM password locations in FLASHA */
OTP : origin = 0x380400, length = 0x000400 /* on-chip OTP */
ADC_CAL : origin = 0x380080, length = 0x000009
IQTABLES : origin = 0x3FE000, length = 0x000b50 /* IQ Math Tables in Boot ROM */
IQTABLES2 : origin = 0x3FEB50, length = 0x00008c /* IQ Math Tables in Boot ROM */
FPUTABLES : origin = 0x3FEBDC, length = 0x0006A0 /* FPU Tables in Boot ROM */
ROM : origin = 0x3FF27C, length = 0x000D44 /* Boot ROM */
RESET : origin = 0x3FFFC0, length = 0x000002
VECTORS : origin = 0x3FFFC2, length = 0x00003E /* part of boot ROM */
PAGE 1 :
BOOT_RSVD : origin = 0x000002, length = 0x00004E /* Part of M0, BOOT rom will use this for stack */
RAMM0 : origin = 0x000050, length = 0x0003B0 /* on-chip RAM block M0 */
RAMM1 : origin = 0x000400, length = 0x000400 /* on-chip RAM block M1 */
RAML3 : origin = 0x00D000, length = 0x001000
RAML4 : origin = 0x00E000, length = 0x001000
RAML5 : origin = 0x00F000, length = 0x001000
ZONE7B : origin = 0x20FC00, length = 0x000400 /* XINTF zone 7 - data space */
FLASHB : origin = 0x330000, length = 0x008000 /* on-chip FLASH */
}
SECTIONS
{
FPUmathTables : > FPUTABLES, PAGE = 0, TYPE = NOLOAD
/* Setup for "boot to SARAM" mode:
The codestart section (found in DSP28_CodeStartBranch.asm)
re-directs execution to the start of user code. */
codestart : > BEGIN, PAGE = 0
#ifdef __TI_COMPILER_VERSION__
#if __TI_COMPILER_VERSION__ >= 15009000
.TI.ramfunc : {} LOAD = RAML0,
RUN = RAML0,
LOAD_START(_RamfuncsLoadStart),
LOAD_END(_RamfuncsLoadEnd),
RUN_START(_RamfuncsRunStart),
LOAD_SIZE(_RamfuncsLoadSize),
PAGE = 0
#else
ramfuncs : LOAD = RAML0,
RUN = RAML0,
LOAD_START(_RamfuncsLoadStart),
LOAD_END(_RamfuncsLoadEnd),
RUN_START(_RamfuncsRunStart),
LOAD_SIZE(_RamfuncsLoadSize),
PAGE = 0
#endif
#endif
.text : {*(.text)}>> RAML1L2|RAML0 PAGE = 0
.cinit : > RAML0, PAGE = 0
.pinit : > RAML0, PAGE = 0
.switch : > RAML0, PAGE = 0
.stack : > RAMM1, PAGE = 1
.ebss : > RAML3, PAGE = 1
.econst : > RAML3, PAGE = 1
.sysmem : > RAML3, PAGE = 1
.esysmem : > RAML3, PAGE = 1
.sysmem : > RAML3, PAGE = 1
FFT_buffer1 : > RAML4, PAGE = 1
FFT_buffer2 : > RAML4, PAGE = 1
FFT_buffer3 : > RAML5, PAGE = 1
FFT_buffer4 : > RAML5, PAGE = 1
.cio : > RAML3, PAGE = 1
ZONE7DATA : > ZONE7B, PAGE = 1
DMARAML4 : > RAML4, PAGE = 1
DMARAML5 : > RAML5, PAGE = 1
.reset : > RESET, PAGE = 0, TYPE = DSECT /* not used */
csm_rsvd : > CSM_RSVD PAGE = 0, TYPE = DSECT /* not used for SARAM examples */
csmpasswds : > CSM_PWL PAGE = 0, TYPE = DSECT /* not used for SARAM examples */
/* Allocate ADC_cal function (pre-programmed by factory into TI reserved memory) */
.adc_cal : load = ADC_CAL, PAGE = 0, TYPE = NOLOAD
}
/*
//===========================================================================
// End of file.
//===========================================================================
*/
main中调用
RFFT_ADC_Init();
RFFT_ADC_Caculate();
这两个函数即可完成测试。
打开调试窗口
rfft_analyse 加入调试窗口,点击运行即可看到计算结果
可以看到成功把input.c采集到的数据通过FFT将各次不同频率的分量提取出来了,结果和我们上面输入信号很相近。(input.c输入信号数据可以通过matlab借助dsp库编写生成数据,可参考C2000Ware_4_01_00_00\libraries\dsp\FPU\c28\reference\MATLAB中的FPU_DSP_runIFFT.m进行编写)
下图是相关程序的运行时间,1024点旋转因子表生成要650us(采样点数固定,该旋转因子表只需要生成一次),FFT计算大概要200us。
开放原子开发者工作坊旨在鼓励更多人参与开源活动,与志同道合的开发者们相互交流开发经验、分享开发心得、获取前沿技术趋势。工作坊有多种形式的开发者活动,如meetup、训练营等,主打技术交流,干货满满,真诚地邀请各位开发者共同参与!
更多推荐
所有评论(0)