您的位置 首页 国产IC

用51单片机完成音频信号的频谱显现

思路:外来音频信号经过51单片机,在单片机中进行频谱分析,并将结果显示在LCD(12864或1602)上要求:频谱显示如同千千静听播放音乐时的频谱

思路:外来音频信号通过51单片机,在单片机中进行频谱分析,并将成果显现在LCD(12864或1602)上

要求:频谱显现好像千千静听播映音乐时的频谱显现

期望各位高手能给出具体的解决方案,感谢。。。。。。
51做FFT有些困难,能够运用增强型(RAM)的51机子进行

参阅程序:

#include
#define uchar unsigned char
#define uint unsigned int
#define channel 0x01 //设置AD通道为 P1.1
//———————————————————————

sbit SDA_R=P1^2;
sbit SDA_R_TOP=P1^3;
sbit SDA_G=P1^4;
sbit SDA_G_TOP=P1^5;
sbit STCP=P1^6;
sbit SHCP=P1^7;
//———————————————————————
//———————————————————————————————————————-
//扩大128倍后的sin整数表(128)
code char SIN_TAB[128] = { 0, 6, 12, 18, 24, 30, 36, 42, 48, 54, 59, 65, 70, 75, 80, 85, 89, 94, 98, 102,

105, 108, 112, 114, 117, 119, 121, 123, 124, 125, 126, 126, 126, 126, 126, 125, 124, 123, 121, 119, 117, 114, 112,

108, 105, 102, 98, 94, 89, 85, 80, 75, 70, 65, 59, 54, 48, 42, 36, 30, 24, 18, 12, 6, 0, -6, -12, -18, -24, -30,

-36, -42, -48, -54, -59, -65, -70, -75, -80, -85, -89, -94, -98, -102, -105, -108, -112, -114, -117, -119, -121,

-123, -124, -125, -126, -126, -126, -126, -126, -125, -124, -123, -121, -119, -117, -114, -112, -108, -105, -102,

-98, -94, -89, -85, -80, -75, -70, -65, -59, -54, -48, -42, -36, -30, -24, -18, -12, -6 };

//扩大128倍后的cos整数表(128)
code char COS_TAB[128] = { 127, 126, 126, 125, 124, 123, 121, 119, 117, 114, 112, 108, 105, 102, 98, 94,

89, 85, 80, 75, 70, 65, 59, 54, 48, 42, 36, 30, 24, 18, 12, 6, 0, -6, -12, -18, -24, -30, -36, -42, -48, -54, -59,

-65, -70, -75, -80, -85, -89, -94, -98, -102, -105, -108, -112, -114, -117, -119, -121, -123, -124, -125, -126, –

126, -126, -126, -126, -125, -124, -123, -121, -119, -117, -114, -112, -108, -105, -102, -98, -94, -89, -85, -80,

-75, -70, -65, -59, -54, -48, -42, -36, -30, -24, -18, -12, -6, 0, 6, 12, 18, 24, 30, 36, 42, 48, 54, 59, 65, 70,

75, 80, 85, 89, 94, 98, 102, 105, 108, 112, 114, 117, 119, 121, 123, 124, 125, 126, 126 };

//采样存储序列表
code char LIST_TAB[128] = { 0, 64, 32, 96, 16, 80, 48, 112,
8, 72, 40, 104, 24, 88, 56, 120,
4, 68, 36, 100, 20, 84, 52, 116,
12, 76, 44, 108, 28, 92, 60, 124,
2, 66, 34, 98, 18, 82, 50, 114,
10, 74, 42, 106, 26, 90, 58, 122,
6, 70, 38, 102, 22, 86, 54, 118,
14, 78, 46, 110, 30, 94, 62, 126,
1, 65, 33, 97, 17, 81, 49, 113,
9, 73, 41, 105, 25, 89, 57, 121,
5, 69, 37, 101, 21, 85, 53, 117,
13, 77, 45, 109, 29, 93, 61, 125,
3, 67, 35, 99, 19, 83, 51, 115,
11, 75, 43, 107, 27, 91, 59, 123,
7, 71, 39, 103, 23, 87, 55, 119,
15, 79, 47, 111, 31, 95, 63, 127
};

uchar COUNT=0,COUNT1=0,ADC_Count=0,LINE=15,G,T;
uchar i,j,k,b,p;
int Temp_Real,Temp_Imag,temp; // 中心暂时变量
uint TEMP1;
int xdata Fft_Real[128];
int xdata Fft_Image[128]; // fft的虚部
uchar xdata LED_TAB2[64]; //记载 漂浮物 是否需求 中止一下
uchar xdata LED_TAB[64]; //记载赤色柱状
uchar xdata LED_TAB1[64]; //记载 漂浮点

void Delay(uint a)
{
while(a–);
}

void FFT()
{ //uchar X;
for( i=1; i<=7; i++) /* for(1) */
{
b=1;
b <<=(i-1); //碟式运算,用于核算 隔多少行核算 例如 榜首极 1和2行核算,,第二级
for( j=0; j<=b-1; j++) /* for (2) */
{
p=1;
p <<= (7-i);
p = p*j;
for( k=j; k<128; k=k+2*b) /* for (3) 基二fft */
{
Temp_Real = Fft_Real[k]; Temp_Imag = Fft_Image[k]; temp = Fft_Real[k+b];
Fft_Real[k] = Fft_Real[k] + ((Fft_Real[k+b]*COS_TAB[p])>>7) + ((Fft_Image[k+b]*SIN_TAB[p])>>7);
Fft_Image[k] = Fft_Image[k] – ((Fft_Real[k+b]*SIN_TAB[p])>>7) + ((Fft_Image[k+b]*COS_TAB[p])>>7);
Fft_Real[k+b] = Temp_Real – ((Fft_Real[k+b]*COS_TAB[p])>>7) – ((Fft_Image[k+b]*SIN_TAB[p])>>7);
Fft_Image[k+b] = Temp_Imag + ((temp*SIN_TAB[p])>>7) – ((Fft_Image[k+b]*COS_TAB[p])>>7);
// 移位.避免溢出. 成果已经是本值的 1/64
Fft_Real[k] >>= 1;
Fft_Image[k] >>= 1;
Fft_Real[k+b] >>= 1;
Fft_Image[k+b] >>= 1;

}
}
}
// X=((((Fft_Real[1]* Fft_Real[1]))+((Fft_Image[1]*Fft_Image[1])))>>7);
Fft_Real[0]=Fft_Image[0]=0; //去掉直流重量
// Fft_Real[63]=Fft_Image[63]=0;
for(j=0;j<64;j++)
{
TEMP1=((((Fft_Real[j]* Fft_Real[j]))+((Fft_Image[j]*Fft_Image[j])))>>1);//求功率
if(TEMP1>1)TEMP1–;
else TEMP1=0;
if(TEMP1>31)TEMP1=31;
if(TEMP1>(LED_TAB[j]))LED_TAB[j]=TEMP1;
if(TEMP1>(LED_TAB1[j]))
{ LED_TAB1[j]=TEMP1;
LED_TAB2[j]=18; //提顿速度=12
}
}
}

声明:本文内容来自网络转载或用户投稿,文章版权归原作者和原出处所有。文中观点,不代表本站立场。若有侵权请联系本站删除(kf@86ic.com)https://www.86ic.net/bandaoti/ic/254100.html

为您推荐

联系我们

联系我们

在线咨询: QQ交谈

邮箱: kf@86ic.com

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

返回顶部