The FIR filter of audio signal based on FPGA (Matlab+modelsim verification)

Source: Internet
Author: User

1 Design Content

This design is based on FPGA audio signal fir Low-pass filter, according to requirements, using MATLAB to read WAV audio files and add noise signal, FFT analysis, FIR filter processing, and analysis of the effect of filtering. Through the analysis of MATLAB to verify the filtering effect, the audio signal of the superimposed noise signal is output to TXT file. Then use the Matlab language to write the filter module and test module, through the Modelsim software to read the TXT file data, the data into the filter module, and finally the results of the filter output to TXT file, and finally use MATLAB to process the results from the TXT file read, display, The processing effect of FIR filter designed by FFT analysis with Verilog.

2 Design Principle 2.1 speech signal Overview

Language is created by human beings and is one of the essential characteristics of human beings that are distinguished from other Earth's life. Human language communication process can be regarded as a complex communication process, in order to obtain easy to analyze and processing of the voice source, the airborne sound waves must be transmitted to contain voice information and recorded the physical properties of the analog (or digital) electrical signals, namely voice signals, Therefore, the speech signal becomes the expression form or the carrier of the speech.

The intersection of phonetics and digital signal processing forms the speech signal processing. Speech signal processing is based on phonetics and digital signal processing, a comprehensive discipline for the analysis, storage, transmission, identification and synthesis of speech signal model.

In this design, the audio signal from the WAV audio file is read with MATLAB for analysis and processing.

2.2 Digital Filter principle

If the input and output of the filter are discrete time signals, then the unit impulse response H (n) of the filter is also necessarily discrete, this filter is called the Digital Filter (DF). A digital filter is essentially a computational process-a calculation or convolution calculation of a difference equation used to describe the relationship between input and output of a discrete system. The essence of digital filter is the discrete time linear time invariant system realized by a finite precision algorithm, in order to complete the process of filtering the signal. It is an important branch of digital signal processing, with good stability, high precision, flexibility, small size, light weight and many other advantages.

Classification of time characteristics based on unit impulse response H (n)

(1) Infinite impulse response (IIR) digital filter

(2) Finite impulse response (FIR) digital filter

In this design, the FIR low-pass filter is selected to filter the audio signal.

In the FIR filter response (FIR) system, the Unit Impulse response H (n) is a finite long sequence, and the system function H (z) has no pole on the finite z-plane, and there is no feedback branch in its operation structure, that is, there is no loop. If the length of H (n) is n, then its system functions and difference equations generally have the following form:

The results of FIR filter are as follows: Direct type, cascade type, linear phase type.

In the design of linear phase type, the main characteristic of FIR filter is that it can have linear phase characteristics. The so-called linear phase characteristic refers to the linear relationship between the phase shift and the frequency of sine wave produced by the filter on different frequency sine waves. Therefore, the signal in the filter pass through the filter, in addition to the phase shift characteristics of the slope determined by the delay, you can really retain all the signal in the pass band. This is important and needs to be used in many applications.

When the system's unit sampling response H (n) satisfies the following symmetry conditions, the

Even symmetry condition: H (N) =h (n-1-n) 0<n<n-1

Odd symmetry condition: H (N) =-h (n-1-n) 0<n<n-1

The phase frequency characteristics of the system are linear. Its symmetry center is (N-1)/2. Linear phase type can be used less than direct type (N-1)/2 multiplier. For cases where n is even and odd, A is n=7 and B is n=6.

Figure 1 N is an even and odd FIR filter structure

3. Design Ideas

This design is divided into two parts, one is the design verification and audio signal extraction of MATLAB, the other is the design of FIR filter based on Verilog on Modelsim platform and the writing of Testbench.

MATLAB design verification and audio signal extraction: in MATLAB, [Y,fs,bits]=wavread (' Blip ', [N1 N2]), for reading speech, the sampled value is placed in Vector y, FS represents the sampling frequency (Hz), and bits represents the number of sample bits. [N1 N2] represents the value of the read value from the N1 point to the N2 point. This function is used to read the WAV audio signal, then FFT analysis the signal, and then overlay a 6K sine wave signal on the original audio signal, and perform FFT analysis.

In this process, the audio signal superimposed on the noise signal is written to the TXT file as the signal source of the Modelsim platform, and the FIR tap parameters are extracted for Verilog to write the FIR filter.

On the Modelsim platform, using Verilog to write a linear phase of the FIR filter, and then write Testbench code, testbench the main function is to provide clock, reset, signal source, while the processing of the FIR module read out and write to the TXT file.

Finally, the results of Modelsim processing are analyzed by MATLAB and compared with the results of MATLAB processing.

Specific processes such as:

Figure 2 The flow of this design

4. Design process 4.1 matlab platform 4.1.1 Matlab Read audio file

In Matlab, [Y,fs,bits]=wavread (' Blip ', [N1 N2]) is used for reading speech, the sampled value is placed in Vector y, FS represents the sampling frequency (Hz), and bits represents the number of sample bits. [N1 N2] represents the value of the read value from the N1 point to the N2 point.

The sampling frequency is 100K and the number of read points is 4,096 signals.

4.1.2 Superimposed noise signal

A sine wave with a frequency of 6K, a point of 4096 and a amplitude of 0.003 is superimposed, and the signal before and after the overlay is analyzed by FFT.

Because the amplitude of the audio signal is very small, because the FPGA processing integer more convenient, so it is necessary to enlarge the audio signal of the superimposed noise, and then convert the negative number to a positive integer, and finally write to the TXT file.

Write the TXT file as follows:

Figure 3 TXT file for audio signal

At the same time, in order to use this signal source as a signal source inside the FPGA, it is necessary to write the signal data to the MIF file, and then call a ROM module to store this data. The code for writing voice signal data to MIF files in MATLAB is as follows:

The resulting MIF file data is as follows:

Figure 4 MIF File

4.1.3 Fir Filter

The FIR filter used in this design is 8 order, the sampling frequency is 100K, and the frequency is 6K.

In MATLAB, the FIR1 function is used to extract the tap system, then the tap coefficient and audio signal with noise are convolution, and then the results of FIR processing are analyzed by FFT.

The coefficient of tap is extracted as follows:

Since the coefficients of extraction are floating-point numbers, it is necessary to shift the coefficients, as integers are used in the FIR filter of FPGA design, and then reverse-shift the results of the processing to get the correct results.

The converted coefficients are as follows:

4.1.4 Analysis Filter Effect

The signal after the stack noise and fir processing is analyzed by FFT, and the comparison is shown:

4.1

4.2 Modelsim and quartusii platform 4.2.1 Fir module writing

The FIR module in this design is mainly divided into the signal source module and the FIR Filter module, the signal source module uses ROM to store the voice signal with the noise signal, the storage bit width is 8bit, the depth is 4096. Since there is a certain number of m4k blocks embedded in the FPGA with Altera, these modules can be called directly to store signals.

The signal data stored in the MIF file in the ROM module is as follows:

Figure 5 The data in the ROM module

The linear phase structure of the FIR filter is designed to reduce the number of multipliers by half, this design uses 4 multipliers, because the FPGA embedded a certain number of hardware multipliers, which can be directly called these multipliers to the tap parameters and signal data multiplication operation, To reduce the invocation of logical units and to reduce a certain delay.

The tap parameters are 19, 65, 170, 256, which are obtained by moving the matlab output parameter to the left by 10 bits.

The structure of the filter is as follows:

Since the tap factor is shifted to the left by 10 bits, you need to move the result to the right by 10 bits after getting the final processing result, as follows:

The FIR module top layer is designed as follows:

4.2.2 Testbench Writing

The main function of Testbench is to read the signal data in the TXT file, as the signal source of the FIR Filter module, and provide the clock and reset signal for the FIR filter module, and finally write the FIR Filter module data into TXT file.

5 analysis and Verification 5.1 QUARTUS II design

After the design completes each module and the top-level encapsulation, compiles the synthesis.

Figure 6 Composite results

The RTL view of the overall design is as follows:

Figure 7 RTL View

The CLK signal is 100K and also the sampling signal of the FIR module.

Analysis of simulation results of 5.2 Modelsim

Modelsim simulation results are as follows, wherein Data_in is read from the TXT file superimposed noise of the voice signal, fir_data after the FIR filter processing output signal, due to the frequency of 6K, from which it can be seen that most of the noise signal has been filtered out, In order to better analyze the results of processing, the results of FIR processing are written to TXT file, and then using MATLAB for FFT analysis.

Figure 8 Modelsim Simulation Waveform

The results of the FIR processing output are as follows:

Figure 9 Modelsim Simulation Results Data output

5.3 Matlab Design Analysis Verification

Using MATLAB to display the original speech signal, voice signal superimposed noise, fir filter signal is shown below, from the can be seen, the use of 8-order FIR filter can better filter out the noise signal.

Figure 10 o'clock Domain graph comparison

In order to better analyze the spectrum of the signal, the original voice signal, voice signal superimposed noise, fir filter signal after the frequency spectrum as follows, the comparison can be more determined to obtain, through the FIR filter, 6K above the signal is basically filtered out, because the 10K noise signal frequency function is relatively large, FIR filters have fewer orders, and the 10K noise signal is still not completely filtered, although this can be completely filtered by increasing the order.

Figure 11 Spectrum comparison

The data of Modelsim simulation result is read out by MATLAB, and the processed speech signal is displayed and compared with the original speech signal.

Fig. 12 Comparison of speech signals of original speech and Modelsim simulation

The original speech signal, the signal after FIR filtering with Matlab, and the speech signal after Modelsim simulation are analyzed and compared by FFT, the results are as follows:

Fig. 13 Comparison of signal spectrum between superimposed noise and Modelsim simulation

Comparison between MATLAB filtering effect and Modelsim simulation effect

Through the above analysis, verification, using Verilog design fir filter can realize the predetermined function, can over 6K noise signal is basically filtered out, because the 10K noise signal amplitude is large, so to complete filtering can increase the order of FIR filter.

The FIR filter of audio signal based on FPGA (Matlab+modelsim verification)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.