At present, most audio signal processors are not only large in size but also expensive, and are difficult to be popularized in some special aspects. Embedded system analyzers are small and reliable, so the development of audio analysis instruments based on special function microcontrollers is the basis of speech recognition and has great practical significance. The principle of signal analysis is to convert the signal from the time domain to the frequency domain, so that the unclear characteristics of the original signal become obvious, which is convenient for analysis and processing. For audio signals, their main characteristic parameters are amplitude spectrum and power spectrum. The working process of the audio signal analyzer is: limiting amplification of audio signals, analog-to-digital conversion, fast Fourier transform (FFT, conversion from time domain to frequency domain), eigenvalue extraction; from the amplitude spectrum of the audio signal, the power spectrum of the audio signal is obtained.
1 Hardware Design
"Smart Home" is also called smart house. The home network intelligent control system uses advanced computer technology, communication technology and embedded technology to connect various devices in the home into a system through the home network. The composition of the entire smart home system is shown in Figure 1. In this system, the monitoring and control of certain household electrical appliances requires the analysis of audio signals.
This design uses Microchip's D
SPIC30F6014A microcontroller as the core processor. This chip is a combination of MCU technology and DSP technology. It not only includes the control function of 16-bit MCU, but also integrates the high-speed computing technology of DSP. It is actually a digital microprocessor that can easily realize various functions of audio signal analysis. The block diagram of the audio system is shown in Figure 2, including several parts such as power module, prefabricated circuit, A/D conversion module, DSP module, LCD display module, etc. The specific design and implementation functions of each module and interface are as follows:
(1) Power supply module: It adopts a DC three-terminal regulated power supply design. After voltage reduction, rectification, filtering and voltage stabilization, 220 V AC power is converted into the ±5 V and ±12 V power supply voltages required by the system.
(2) Prefabricated circuit: To ensure that the input bandwidth is within the audio range, the front-end DC bias circuit uses an OP07 amplifier. The first-stage adder adds the input signal to a 2.5 V voltage value, and the second-stage inverter transfers the signal to a 0-5 V range that can be processed by the A/D converter. Because the 50 Ω resistor at the input end is grounded, the system input impedance is approximately 50 Ω.
(3) A/D conversion module: Because there is only one audio signal input, only AN6 is used among the 16 analog input pins of the 12-bit configurable A/D module. During initialization, this pin is configured as an analog input pin. At the same time, because the processed audio signal voltage is 0 to 5 V, the reference voltage of the A/D module is set to 0 V and 5 V. The conversion output rate is as high as 200 KSPS.
(4) DSP module: This digital microprocessor is a modified Harvard structure design that can perform real-time analysis with high resolution. The DSP module is called through Microchip's MPLAB C30 C compiler, which provides 49 DSP processing functions to complete all digital signal processing.
(5) LCD display module: used to intuitively display spectrum waveform.
(6) ICD2 debug interface: Microchip's ICD2 in-circuit debugger is selected, and an ICD2 debug interface is reserved for this purpose.
(7) RC oscillator: This microcontroller can operate in four modes: external clock input, external RC input, internal fast RC oscillator, internal low power (RC) oscillator, and post divider used in low power consumption. This design uses the internal fast RC oscillator, which can provide a 7.37 MHz clock. Since the audio signal needs to be processed in real time, the post divider is not used. [page]
2 Software Design
The main loop of the audio system is shown in Figure 3.
(1) After sampling and A/D conversion are completed, the A/D enable flag is cleared to obtain a discrete digital signal.
(2) Call the period determination function to analyze the periodicity of the signal.
(3) Call the FFT transformation function to perform fast Fourier transform on the discrete signal to achieve the transformation from time domain to frequency domain.
(4) Display the spectrum of the input signal.
(5) Calculate the power spectrum of the signal and calculate the maximum power.
(6) Display the power spectrum and maximum power of the signal.
2.1 A/D Sampling
Theoretical analysis: Due to the 12-bit A/D module, the quantization unit is 1/212. Since the frequency resolution △f = 100 Hz and the number of FFT sub-sample points N = 512, the sampling frequency fs = 51 200 Hz (fs ≤ N△f) and the sampling period Ts = 1/51 200 s (sampling period minus sampling time + conversion time). Since the oscillation frequency is 7.37 MHz, the instruction period TCY = (1/7.37) × 4 = 0.5 μs.
Actual control: The conversion time is 14 TAD (for correct A/D conversion, TAD = 333.33 ns). Therefore, if the A/D automatic sampling time is configured to be 6 TAD and the A/D conversion clock is 16TCY, the total A/D conversion time is 0.092 ms and the sampling frequency is 10.87 kHz.
The A/D module works in the system clock source and automatic conversion mode, and enters an interrupt after each conversion. A structure with a sampling point number should be defined in the program to store the data collected by the A/D. Each structure includes a real part and an imaginary part. In the interrupt service subroutine, the digital quantity collected by the A/D module is stored in the real part of the structure, and a total of sampling point conversions are performed. The flow of the interrupt service subroutine is shown in Figure 4.
2.2 Period determination
The frequency components of audio signals are not only numerous, but also non-periodic. The measurement period can be in the time domain or in the frequency domain. However, since the frequency domain measurement of periodicity requires that certain frequency points have regular zero points or near zero points, it is impossible to correctly analyze the periodicity of more complex signals with more frequency components and more uniform and low power distribution. Therefore, for the periodicity determination of the signal, the period determination function should be called directly before the FFT transformation of the signal. The flow chart of the periodicity determination subroutine is shown in Figure 5. [page]
2.3 FFT Transformation
Since the amount of computation of direct Fourier transform is proportional to the square of the number of sub-sample points N, when N is large, the amount of computation is too large and is not suitable for implementation in embedded systems with limited resources. Therefore, the most commonly used radix 2 FFT algorithm is the one whose main idea is to decompose the N-point direct Fourier transform into multiple shorter direct Fourier transforms, and then use the periodicity and symmetry of the rotation factors to save system resources to a great extent.
The MPLAB C30 C compiler provides almost all digital signal processing software tools. Through the DSPIC30F series microprocessor, digital signal processing can be easily implemented by simply calling the library functions provided by Microchip. For the radix-2 FFT transform, its software flow chart is shown in Figure 6.
2.4 Feature value extraction
The quantities that play a decisive role in frequency domain analysis include sampling frequency and number of sampling points. Through FFT transformation, the discretized amplitude spectrum X(k) is obtained. The discretized amplitude value is first squared and then divided by the number of sub-sample points N to obtain the power value corresponding to the frequency point (power = X(k)*X(k)/N).
3 Conclusion
The main performance indicators of the system are: input impedance 50 Ω; input signal voltage range (peak-to-peak value) 100 mV~5 V; the frequency component range of the input signal is 200 Hz~10 kHz; the frequency resolution is 100 Hz (it can correctly measure the power value of the frequency component with a frequency difference of not less than 100 Hz in the measured signal); the total power of the input signal and the power of each frequency component, the sum of the power of each detected frequency component is not less than 95% of the total power value; the absolute value of the relative error of the power measurement of each frequency component is less than 10%, and the absolute value of the relative error of the total power measurement is less than 5%; the analysis data is refreshed at a period of 5 s, and the frequency components of the signal should be stored in sequence according to the power size and can be played back and displayed. At the same time, the total power of the signal and the frequency and power values of at least the first two frequency components are displayed in real time, and a pause button is set to keep the displayed data. Audio signal analysis based on DSP microcontroller technology has the characteristics of stable performance, simple circuit, fast speed, low cost and small size. It is suitable for embedded systems that require audio signal analysis and can be further promoted and applied in more fields, such as environmental monitoring, speech recognition, and control of intelligent systems.