#include "MSP430X14X.h"
#include "math.h"
#include "OCMJ4X8C.h"
#include"MSP430KEY.h"
#include"df_timera.h"
#define num_point 128 //取样点数
#define num_grade 7 //蝶形运算阶数
const float tab_sin[256]={
0, 0.0245, 0.0491, 0.0736, 0.0980, 0.1224, 0.1467, 0.1710, 0.1951,
0.2191, 0.2430, 0.2667, 0.2903, 0.3137, 0.3369, 0.3599, 0.3827, 0.4052,
0.4276, 0.4496, 0.4714, 0.4929, 0.5141, 0.5350, 0.5556, 0.5758, 0.5957,
0.6152, 0.6344, 0.6532, 0.6716, 0.6895, 0.7071, 0.7242, 0.7410, 0.7572,
0.7730, 0.7883, 0.8032, 0.8176, 0.8315, 0.8449, 0.8577, 0.8701, 0.8819,
0.8932, 0.9040, 0.9142, 0.9239, 0.9330, 0.9415, 0.9495, 0.9569, 0.9638,
0.9700, 0.9757, 0.9808, 0.9853, 0.9892, 0.9925, 0.9952, 0.9973, 0.9988,
0.9997, 1.0000, 0.9997, 0.9988, 0.9973, 0.9952, 0.9925, 0.9892, 0.9853,
0.9808, 0.9757, 0.9700, 0.9638, 0.9569, 0.9495, 0.9415, 0.9330, 0.9239,
0.9142, 0.9040, 0.8932, 0.8819, 0.8701, 0.8577, 0.8449, 0.8315, 0.8176,
0.8032, 0.7883, 0.7730, 0.7572, 0.7410, 0.7242, 0.7071, 0.6895, 0.6716,
0.6532, 0.6344, 0.6152, 0.5957, 0.5758, 0.5556, 0.5350, 0.5141, 0.4929,
0.4714, 0.4496, 0.4276, 0.4052, 0.3827, 0.3599, 0.3369, 0.3137, 0.2903,
0.2667, 0.2430, 0.2191, 0.1951, 0.1710, 0.1467, 0.1224, 0.0980, 0.0736,
0.0491, 0.0245, 0.0000,-0.0245,-0.0491,-0.0736,-0.0980,-0.1224,-0.1467,
-0.1710,-0.1951,-0.2191,-0.2430,-0.2667,-0.2903,-0.3137,-0.3369,-0.3599,
-0.3827,-0.4052,-0.4276,-0.4496,-0.4714,-0.4929,-0.5141,-0.5350,-0.5556,
-0.5758,-0.5957,-0.6152,-0.6344,-0.6532,-0.6716,-0.6895,-0.7071,-0.7242,
-0.7410,-0.7572,-0.7730,-0.7883,-0.8032,-0.8176,-0.8315,-0.8449,-0.8577,
-0.8701,-0.8819,-0.8932,-0.9040,-0.9142,-0.9239,-0.9330,-0.9415,-0.9495,
-0.9569,-0.9638,-0.9700,-0.9757,-0.9808,-0.9853,-0.9892,-0.9925,-0.9952,
-0.9973,-0.9988,-0.9997,-1.0000,-0.9997,-0.9988,-0.9973,-0.9952,-0.9925,
-0.9892,-0.9853,-0.9808,-0.9757,-0.9700,-0.9638,-0.9569,-0.9495,-0.9415,
-0.9330,-0.9239,-0.9142,-0.9040,-0.8932,-0.8819,-0.8701,-0.8577,-0.8449,
-0.8315,-0.8176,-0.8032,-0.7883,-0.7730,-0.7572,-0.7410,-0.7242,-0.7071,
-0.6895,-0.6716,-0.6532,-0.6344,-0.6152,-0.5957,-0.5758,-0.5556,-0.5350,
-0.5141,-0.4929,-0.4714,-0.4496,-0.4276,-0.4052,-0.3827,-0.3599,-0.3369,
-0.3137,-0.2903,-0.2667,-0.2430,-0.2191,-0.1951,-0.1710,-0.1467,-0.1224,
-0.0980,-0.0736,-0.0491,-0.0245};
//float tab_dftR[num_point]; //输入的波形数据,兼作输出数据的实部
float tab_dftI[num_point]; //输出数据的虚部
//float tab_power[num_point]; //模,频率对应的功率谱
float result[num_point]; //AD转换结果
float power_t=0; //时域总功率
float power_f=0; //频域总功率
unsigned int data1;
unsigned int data2;
unsigned char disp1[16];
unsigned char disp2[16];
unsigned int num_B=0;
unsigned int mem[num_point];
//以下为液晶显示信息
unsigned char Text[]=
{
"宜宾学院 "
"请按E 键开始 "
"音频信号分析仪 "
"按R 键返回 "
};
unsigned char Start[]=
{
"按E 键采集信号 "
"按R 键返回 "
"进行FFT 分析 "
"系统会在5S后返回"
};
unsigned char Sure[]=
{
"请按确定键把FFT "
"每按一次显示 "
"的功率谱分布显示"
"一个功率值 "
};
unsigned char spectrum[]=
{
" 频谱分析 "
" "
" "
" "
};
void InitSys();//系统初始化
void fft(float dataR[num_point],float dataI[num_point]); //FFT变换
void get_power_t(float result[num_point]);//计算时域功率,一定要放于void FFT前,否则result数据被覆盖
void get_power(float result[num_point],float dataI[num_point]); //求模
void AD_timeB();
void AdcConvert(unsigned char *Numeral,unsigned int result);
void sort(float* mod,unsigned int* count_in);//大到小的排序
void display(float result[num_point]);
//static unsigned int length;
void main( void )
{
unsigned char key[2],LCD_data[16];
unsigned int count,freq_count;
unsigned long data1,data2;
float data3;
signed long Chan_data;
unsigned int count_index[num_point/2];
WDTCTL = WDTPW + WDTHOLD; //关闭看门狗
for(unsigned int p0=0;p0<num_point/2;p0++)
count_index[p0]=p0;//0-127无符号数序列 频率的参考倍数
InitSys();
start:
count=0;
chn_disp (Text);//输出实验人信息
while(1)
{
key[0]=GetKeyZhi(&key[1]);
if(key[0]==0x84)
break;
LPM3;
}
clrram();
chn_disp(Start);
while(1)
{
key[0]=GetKeyZhi(&key[1]);
if(key[0]==0x88) //返回
goto start;
if(key[0]==0x84)
break;
LPM3;
}
clrram();
AD_timeB(); //定时器控件AD转换
while(1)
{
if(num_B==num_point)
{
ADC12CTL0&=~ENC;
TBCTL&=~(BIT5+BIT4);
break;
}
}
for(unsigned int q4=0;q4<num_point;q4++)
{
Chan_data=mem[q4]; //signed long mem为最初12位无符号采样结果
Chan_data -=0x7FF;
Chan_data *=5;
result[q4] =((float)Chan_data)/4095;//AD转换结果 result=(mem-0x7FF)*5/4095
}
get_power_t(result);
fft(result,tab_dftI);
get_power(result,tab_dftI);
clrram();
chn_disp(Sure);
while(1)
{
key[0]=GetKeyZhi(&key[1]);
if(key[0]==0x88)
goto start;
if(key[0]==0x84)
clrram();
delay(500);
break;
}
clrram();
Clear_GDRAM();
chn_disp(spectrum);
display(result);// 显示频谱
sort(result,count_index); //排序
while(count!=101) //频率为10k
{
key[0]=GetKeyZhi(&key[1]);
if(key[0]==0x88)
goto start;
if(key[0]==0x84)
{
clrram();
Clear_GDRAM();
freq_count =count_index[count]*100; //频率=0
data3=result[count];
data1=(unsigned int)data3; //模,频率对应的整数功率谱
data3=data3-data1; //误差
data2=(unsigned int)(data3*10000); //误差的10000倍(精度小数点后4位有效数字)
Convert(LCD_data,data1,data2,freq_count);
line_disp(LCD_data,0x80);
count++;
freq_count =count_index[count]*100; //频率=
data3=result[count];
data1=(unsigned int)data3;
data3=data3-data1;
data2=(unsigned int)(data3*10000);
Convert(LCD_data,data1,data2,freq_count);
line_disp(LCD_data,0x90);
count++;
freq_count =count_index[count]*100; //200
data3=result[count];
data1=(unsigned int)data3;
data3=data3-data1;
data2=(unsigned int)(data3*10000);
Convert(LCD_data,data1,data2,freq_count);
line_disp(LCD_data,0x88);
count++;
freq_count =count_index[count]*100; //=300
data3=result[count];
data1=(unsigned int)data3;
data3=data3-data1;
data2=(unsigned int)(data3*10000);
Convert(LCD_data,data1,data2,freq_count);
line_disp(LCD_data,0x98);
count++;
}
}
}
void get_power_t(float result[num_point])
{
unsigned int i;
for(i=0;i<num_point;i++)
power_t=power_t+result[i]*result[i]/num_point;
}
/*********************************************************
FFT转换
*********************************************************/
void fft(float dataR[num_point],float dataI[num_point])
{
int i,L,j,k,b,p,q,xx,pow1,pow2;
float TR,TI,temp;
/***********following code invert sequence********/
for(i=0;i<num_point;i++)
{
pow1=1;pow2=num_grade-1;
while(pow2>0)
{pow1=pow1*2;pow2--;}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
电子设计大赛中MSP430写的FFT变换程序(总共128个点).zip (54个子文件)
1
FFT
FFT7.dep 5KB
OCMJ4X8C.h 926B
OCMJ4X8C.c 9KB
FFT7.ewp 44KB
Backup of FFT7.ewd 12KB
df_timera.h 190B
MSP430KEY.h 281B
FFT.C 2KB
FFT7.ewd 13KB
FFT.H 386B
Backup of FFT7.ewp 44KB
df_timera.c 1KB
MSP430KEY.c 5KB
main.c 14KB
FFT7.eww 158B
Debug
List
Obj
FFT7.pbd 384B
MSP430KEY.r43 17KB
main.r43 73KB
df_timera.r43 6KB
OCMJ4X8C.r43 41KB
Exe
FFT7.d43 48KB
settings
FFT7.dni 996B
FFT7.cspy.bat 2KB
FFT7.wsdt 3KB
FFT7.dbgdt 4KB
电子设计大赛中MSP430写的FFT变换程序(总共128个点)
FFT
FFT7.dep 4KB
OCMJ4X8C.h 926B
OCMJ4X8C.c 9KB
FFT7.ewp 47KB
Backup of FFT7.ewd 12KB
df_timera.h 190B
MSP430KEY.h 281B
FFT.C 2KB
FFT7.ewd 17KB
FFT.H 386B
Backup of FFT7.ewp 44KB
df_timera.c 1KB
MSP430KEY.c 5KB
main.c 14KB
FFT7.eww 158B
Debug
List
Obj
FFT7.pbd 544B
MSP430KEY.r43 17KB
df_timera.pbi 632B
MSP430KEY.pbi 632B
OCMJ4X8C.pbi 630B
main.r43 73KB
main.pbi 622B
df_timera.r43 6KB
OCMJ4X8C.r43 41KB
Exe
FFT7.d43 48KB
settings
FFT7.dni 996B
FFT7.cspy.bat 3KB
FFT7.wsdt 4KB
FFT7.dbgdt 4KB
共 54 条
- 1
资源评论
N201871643
- 粉丝: 1253
- 资源: 2669
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功