FFT在单片机上的实现 下载本文

河南科技大学毕业设计(论文)

FFT在单片机上的实现

摘 要

音频信号分析仪是一种可广泛见于各种音响、调音和录音设备上的,能实时地采样及分析输入的音频信号的频谱,并将其显示在显示屏上的设备,使人在聆听音乐时能对音乐的高低频能有直观的了解。本文所介绍的即是这样一个音频信号分析系统。系统的硬件由信号调理、控制处理器、显示模块三部分组成。

信号调理电路使信号可输入300mV~3V的交流音频信号。这里只对单路信号处理:当电压较低时使用LM324运放获得增益,对超过12800Hz的信号进行滤波处理。另外设置输出音频接口以便监听。

控制处理器采用51内核1T单片机STC12C60A5S2,晶振频率为32.768MHz。该单片机自带8路10位高速ADC,这里只用1路ADC的高8位。对信号连续采32个点进行浮点型FFT运算。一次完整采样的时间为1.25ms,最高采样频率为25600Hz,分辨频率为800Hz~12800Hz,分16级。

显示部分主体为1602液晶显示屏,其具有2行×16列的8×5点显示点阵。16分频谱将分别以柱高形式显示在显示屏上。程序中设置了频率下落效果以使观感更好。另设置了对比度调节电阻,使屏幕对比度可调。

关 键 词:FFT 单片机 音频 频谱

I

河南科技大学毕业设计(论文)

THE REALIZATION OF FFT IN THE

MICROCONTROALER

ABSTRACT

Audio signal analyzer is a kind of device which can be widely found in various of audio, mixing and recording devices, and can sampling and analysis of the spectrum of the input have an intuitive audio signal and displays it on the display in real-time, people can are listening to Music for music when high frequency understanding. What presented in this article is just such an audio signal analysis system. The hardware of the system are formed with three parts: the signal conditioner, the control processor and the display module.

Signal conditioning circuit makes the signal of 300mV ~ 3V AC audio signal available for inputting. In this system,we only process with single-channel signal: When the voltage is lower the system uses LM324 op amp to gain voltage, and as to signals more than 12800Hz it filters them. In addition the system sets an output audio interface for monitoring.

The control processor of the system is the 51 cores 1T MCU STC12C60A5S2, with 32.768MHz crystal frequency. The device comes with 8-channel &10-bit high-speed ADC, where only one channel ADC high 8. The signal collected 32 points in consecutive floating-point FFT operation. A complete sampling time is 1.25ms, the maximum sampling frequency is 25600Hz, and the distinguish frequency is 800Hz ~ 12800Hz, with 16 levels.

The main display section is 1602 LCD screen, which has 2 rows × 16 columns - 8 × 5 dot display matrix. 16 points to the column height spectrum will be displayed on the display. The process of setting of the frequency drop in the perception of better effect. There is also contrast adjustment resistor, which makes the screen contrast adjustable.

KEY WORDS:FFT,MCU,AUDIO SPECTRUM

II

河南科技大学毕业设计(论文)

目 录

第1章 绪论 ...................................................................................... 1 §1.1 研究的背景及意义 ................................. 1 §1.1.1 课题研究背景 ................................ 1 §1.1.2 课题研究意义 ................................ 1 §1.2 课题发展的状况 ................................... 1 §1.3 设计任务 ......................................... 2 第2章 系统方案设计 ....................................................................... 3 §2.1 系统方案设计 ..................................... 3 §2.2 系统硬件的选择 ................................... 3 §2.2.1 处理器的比较与选择 .......................... 3 §2.2.2 采样模块的确定 .............................. 4 §2.2.3 显示器件的比较和选择 ........................ 4 第3章 系统硬件设计 ....................................................................... 5 §3.1 单片机STC12C5A60S2 ............................. 5 §3.1.1 单片机STC12C5A60S2功能简介 ................. 5 §3.1.2 单片机STC12C5A60S2引脚图 ................... 6 §3.1.2 单片机的最小系统 ............................ 6 §3.2 显示屏LCD1602 .................................. 7 §3.2.1 LCD1602简介 ................................ 7 §3.2.2 LCD1602的硬件连接 ......................... 8 §3.3.1 LM324电压增益与偏移电路 ................... 9 §3.3.2 滤波电路 ................................... 10 第4章 系统软件设计 ..................................................................... 11 §4.1 系统软件总体设计 ................................ 11 §4.2 系统软件详细设计 ................................ 12 §4.2.1 系统的准备和初始化 ......................... 12 §4.2.2 AD采样子程序 ............................. 13 §4.2.3 蝶形运算的FFT算法 ......................... 15

III

河南科技大学毕业设计(论文)

§4.2.4 显示子程序 ................................. 17 第5章 系统调试 ............................................................................. 20 §5.1 信号电压调试 .................................... 20 §5.2 单频率信号测试 .................................. 20 §5.2.1 实际频率分度测试 ........................... 21 §5.2.1 频率混叠和滤波效果 ......................... 22 §5.3 实际使用效果 .................................... 22 结 论 .............................................................................................. 24 参考文献 .......................................................................................... 25 致 谢 .............................................................................................. 26 附 录 .............................................................................................. 27 一、主程序代码 ...................................... 27 二、原理图 .......................................... 35

IV