Design of digital filter in MATLAB and its implementation on DSP

Publisher:喜悦的38号Latest update time:2012-07-14 Source: 单片机及嵌入式系统应用 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

introduction

With the advent of the information age and the digital world, digital signal processing has become an extremely important discipline and technical field. Digital signal processing has been widely used in many fields such as communication, voice, image, automatic control, radar, military, aerospace, medical and household appliances. In digital signal processing applications, digital filters are very important and have been widely used.

1 Design of digital filter

1.1 Basic steps in digital filter design

Digital filters can be divided into two types according to the time domain characteristics of their impulse response functions, namely infinite impulse response (IIR) filters and finite impulse response (FIR) filters. The characteristic of IIR filters is that they have impulse responses of infinite duration. This type of filter generally needs to be implemented using a recursive model, so it is sometimes also called a recursive filter. The impulse response of the FIR filter can only last for a certain period of time. In engineering practice, it can be implemented recursively or non-recursively. There are many methods for designing digital filters, such as bilinear transformation method, window function design method, interpolation approximation method, Chebyshev approximation method, etc. With the continuous improvement of MATLAB software, especially MATLAB's signal processing workbox, not only has the computer-aided design of digital filters become possible, but the design can also be optimized.

The basic steps in digital filter design are as follows:

(1) Determine the indicators

Before designing a filter, the technical indicators of the filter must be determined according to the actual needs of the project. In many practical applications, digital filters are often used to implement frequency selection operations. Therefore, the form of the indicator generally gives the amplitude and phase response in the frequency domain. The amplitude indicator is mainly given in two ways. The first is an absolute indicator. It provides requirements for the amplitude response function and is generally used in the design of FIR filters. The second indicator is a relative indicator. It gives requirements in the form of decibel values. In engineering practice, this indicator is the most popular. For the phase response indicator form, it is usually hoped that the system has a linear phase in the passband. The use of linear phase response indicators for filter design has the following advantages: ① It only contains real number algorithms and does not involve complex number operations; ② There is no delay distortion, only a fixed number of delays; ③ For a filter with a length of N (the order is N-1), the calculation amount is on the order of N/2. Therefore, the design of the filter in this article takes the design of a linear phase FIR filter as an example.

(2) Approximation

After determining the technical indicators, a target digital filter model can be established. Usually, an ideal digital filter model is used. After that, a practical filter model is designed using the digital filter design method to approximate the given target.

(3) Performance analysis and computer simulation

The result of the above two steps is to obtain a filter described by differential or system function or impulse response. Based on this description, its frequency characteristics and phase characteristics can be analyzed to verify whether the design results meet the index requirements; or the designed filter can be implemented by computer simulation and then the filtering results can be analyzed to make a judgment.

1.2 MATLAB Design of Filter

(1) MATLAB

MATLAB is a high-performance visual language and software environment for scientific computing. It integrates numerical analysis, matrix operations, signal processing and graphic display to form a user-friendly interface. Its signal processing toolbox contains a variety of classic and modern digital signal processing technologies. It is an excellent tool for algorithm research and auxiliary design. When designing digital filters, MATLAB is usually used for auxiliary design and simulation.

(2) MATLAB design of FIR filter

The following introduces the specific design method by taking the design of linear phase FIR filter as an example.

Linear phase FIR filters are usually designed using the window function method. The basic idea of ​​designing FIR filters using the window function method is to select the filter length N and the window function ω (n) based on the given filter technical indicators so that it has the narrowest main lobe and the smallest side lobe. The core is to determine the finite length unit impulse response sequence h (n) by adding a window from the given frequency characteristics. There are 6 commonly used window functions in engineering, namely rectangular window, Bartlett window, Hanning window, Hamming window, Blackman window and Kaiser window. [page]

Assume that the actual project needs to design a linear phase bandpass FIR filter with the following indicators:

fn=[1000,1375,3625,4000];

a=[0,1,0];

dev=[0.0005,0.05,0.0005];

The minimum attenuation of the stop band is 60dB. If the sampling frequency fs=10kHz, the Kaiser window is selected according to the minimum attenuation of the stop band. The required digital filter can be quickly designed by using MATLAB's order function and FIR filter design function. The two design functions are as follows:

[N,Wn,beta,ftype]=kaiserord(fn,a,dev,fs);

b=fir1(n,Wn,ftype,Kaiser(n+1,beta);

Finally, the filter analysis function freqz is used to analyze the amplitude-frequency characteristics and phase-frequency characteristics of the designed filter, and the graphical display function plot is used to display them, as shown in Figure 1. As can be seen from Figure 1, the design results meet the index requirements. 2 Implementation method of digital filter

There are generally several ways to implement digital filters.

① Use adders, multipliers, and delay devices to design special filtering circuits.

② Design and implement it by adding a dedicated acceleration processor to a general-purpose computer system.

③Implemented with general-purpose programmable DSP chip.

④ Use a dedicated DSP chip to implement. In some special occasions, the required signal processing speed is extremely high, which is difficult to achieve with a general-purpose DSP chip. This chip implements the corresponding filtering algorithm in hardware inside the chip without programming.

⑤Use FPGA/CPLD to design and implement.

Among the above methods, the disadvantage of the second method is that it is slow and can generally be used to simulate DSP algorithms. The first and fourth methods are highly specialized and their applications are greatly limited. The third and fifth methods can both be programmed to implement various digital filters, but the third method is easy to program because it has dedicated instructions to implement filtering operations, while the fifth method is more difficult to program.

3 DSP Implementation of Digital Filter

DSP is a real-time, fast microprocessor that is particularly suitable for implementing various digital signal processing operations. Due to its rich hardware resources, improved Harvard structure, high-speed data processing capabilities and powerful instruction system, it is widely used in various fields such as communications, aviation, aerospace, radar, industrial control, networks and household appliances. DSP is divided into fixed-point and floating-point. The following takes the fixed-point DSP chip as an example to discuss several key issues in the implementation of FIR filters. These issues discussed have practical reference and application value in DSP system design.

3.1 Fixed-point number calibration

In fixed-point DSP chips, fixed-point numbers are used for numerical calculations, and their operands are generally represented by integers. The maximum representation range of an integer depends on the word length given by the DSP chip, which is generally 16 bits or 24 bits. Obviously, the longer the word length, the larger the range of numbers that can be represented and the higher the precision. In the implementation of the filter, the numbers to be processed by the DSP may be integers, decimals, or mixed decimals; however, when the DSP executes arithmetic instructions, it does not know whether the data currently processed is an integer or a decimal, and it cannot point out where the decimal point is. Therefore, when programming, it is necessary to specify where the decimal point of a number is located, which is calibration. Through calibration, the decimal point can be determined at different positions of a 16-bit number, thereby representing a decimal with different ranges and different precisions. For example: in Q15, 1080H=0.12890625; in Q0, 1080H=4224.

When using fixed-point DSP, how to choose the appropriate Q value is a key issue. In terms of the processing process of DSP operations, the variables actually involved in the operation are variables, some of which are unknown, and some of which change their values ​​continuously during the operation process, but they all have a certain dynamic range as a physical parameter in an actual engineering environment. As long as the dynamic range is determined, the Q value is also determined. Therefore, before programming, we must first find out the range of variation of all variables involved in the operation through careful and rigorous analysis, fully estimate the various situations that may occur in the operation, and then determine which calibration standard to use to ensure that the operation results are correct and reliable. Here, the theoretical analysis method and statistical analysis method discussed determine the maximum absolute value of the variable |max|, and then determine the Q value based on |max|. However, unexpected situations in the DSP operation process are unavoidable, and even if statistical analysis is used, it is impossible to cover all situations. Therefore, some judgment and protection measures should be taken in the fixed-point operation process (especially in fixed-point addition). In addition, a large number of operations in digital signal processing are multiplication and accumulation, and pure integer or pure decimal operations should be used as much as possible, that is, all variables are represented in Q0 or Q15 format. The advantage of this is that it is simple to operate and easy to program. Only when pure integer or pure decimal operations cannot meet the dynamic range and precision requirements of the variable, mixed decimal representation is used for fixed-point operations.

3.2 Error Problem

Because when using fixed-point DSP to implement, all data are fixed-length, and all operations are fixed-point operations, so there will be a finite word length effect. The errors generated mainly include: quantization error caused by digital-to-analog conversion, error caused by coefficient quantization, and rounding error in the operation process. When using fixed-point DSP, errors are inevitable, but some methods can be used to reduce the errors. For example, two storage units can be used to represent a number, and double-word operations can be used during operations; the filter coefficients can be represented by double words as needed, or only half of the coefficients can be represented by double words, depending on the needs. In addition, the quantization errors introduced by FIR digital filters and IIR digital filters are different. FIR digital filters mainly use non-recursive structures, so they are stable in finite precision operations; while IIR digital filters are recursive structures, and the poles must be within the unit circle of the z plane to be stable. The rounding process in the operation of this structure sometimes causes parasitic oscillations. In addition to the finite word length effect, the errors introduced by different structures are also different. In actual design, attention should be paid to the error problem in implementation. When choosing different structures, the errors they introduce should be considered, and fixed-point simulation should be performed using a high-level language to compare the size of the errors under different structures so as to make a reasonable choice.

3.3 Circular Addressing

Circular addressing is an addressing method often used in DSP. This addressing method can implement circular operations on a specific storage area. Circular addressing can be understood as implementing a sliding window. When new data is introduced, it will overwrite the old data, so that the window contains the latest data to be processed. Circular addressing is extremely important in FIR, convolution and other operations in digital signal processing. [page]

In TI's DSP, circular addressing is implemented as follows.

① Set the BK (register block size) value to determine the size of the circular addressing buffer, which can also be regarded as the period of the loop.

② Set the bottom address of the buffer. Note that its lower N bits are zero, where N is the minimum N value that satisfies equation (1).

2 N>BK (1)

③Use auxiliary registers to indirectly address the circular buffer.



3.4 Implementation Example

According to the FIR filter designed above, considering the actual needs of the project (precision requirements) and the convenience of using fixed-point DSP chips, Q15 calibration is selected. To this end, the input data and the coefficients of the filter must be normalized. The normalization of the input data can be achieved by setting the reference level of the A/D conversion. The normalization of the filter coefficients only requires taking the maximum value of the coefficients, and then using this maximum value to remove the coefficients.

Since an N (assuming N is an even number) order FIR filter has coefficient symmetry, its output equation can be written as:

y(n)=ao[x(n)+x(n-N+1)]+a1[x(n-1)+x(n-N+2)]+…+aN/2-1[X (nN/2+1)+x(nN/2)] (2)

According to formula (2), the following implementation algorithm can be established:

① Open two circular buffers in the data storage, the New circular buffer stores new data, and the O1d circular buffer stores old data. The length of the circular buffer is N/2.

② Set the circular buffer pointer, AR2 points to the latest data in the New buffer, and AR3 points to the oldest data in the O1d buffer.

③Set the coefficient table in the program memory.

④ (AR2) + (AR3) → AH (high bit of accumulator A); (AR2) -1 → AR2; (AR3) -1 → AR3.

⑤ Clear accumulator B and repeat the following operation N/2 times: (AH)*coefficient ai+(B)→B, coefficient pointer (PAR) increases by 1, (AR2)+(AR3)→AH, AR2 and AR3 decrease by 1.

⑥Save and output the results (the results are in BH).

⑦ Correct the data pointers so that AR2 and AR3 point to the latest data in the New buffer and the oldest data in the O1d buffer respectively.

⑧ Replace the oldest data in the O1d buffer with the oldest data in the New buffer. The O1d buffer pointer is reduced by 1.

⑨ Input a new data to replace the oldest data in the New buffer.

Repeat steps ④ to 9.

According to the above algorithm, the program was compiled [4, 5], and the simulation and debugging were carried out on CCS5000. The input data and output spectrum were analyzed, and the results are shown in Figure 2 and Figure 3. It can be seen from the figure that the filter achieves the target requirements.

Finally, the program was transplanted into the interrupt service program of MCBSP0 of Wenting's TMS320VC5409 evaluation board, and the resulting executable file was loaded onto the evaluation board for operation. The analog signal is input from the analog input port of the TMS320VC5409 evaluation board, and is converted into a digital signal at a sampling frequency of 8kHz by the TLC320A/D conversion chip, and then input into the DSP. After filtering, the analog quantity is output through the D/A. The results show that the program can realize real-time filtering of analog signals with a sampling rate of 8kHz.

Conclusion

Digital filters are widely used. Running MATLAB language, it is easy to design filters with strict requirements (such as linear phase, etc.). To implement filters with fixed-point DSP, several key issues such as DSP calibration, error, and circular addressing must be considered. The example in this article is to show that DSP can be used to easily implement real-time filtering of analog signals, and the sampling frequency used is not high. If DSP uses a higher clock, its processing speed will be faster and will be able to meet the real-time filtering of digital signals with higher sampling rates.

Reference address:Design of digital filter in MATLAB and its implementation on DSP

Previous article:In-circuit programming of DSP external Flash memory through JTAG port
Next article:Design of hierarchical distributed management system based on DSP chip

Recommended ReadingLatest update time:2024-11-16 20:39

DSP programming skills--Detailed explanation of cmd files
   The cmd file is used to indicate how each data, symbol, etc. is divided into each segment and the storage space used by each segment when linking each target file after compilation. Many people are afraid of cmd files and find it difficult to understand the meaning of each segment, especially when there is no p
[Embedded]
Design of DSP Multi-SPI Port Communication Based on CPLD
introduction At present, various communication methods are widely used in electrical automation control devices to complete the information transmission between the upper and lower controllers, the lower controllers and the control chip, and realize the corresponding control functions; the design and implementa
[Embedded]
Design of DSP Multi-SPI Port Communication Based on CPLD
Design of Universal Controller for LCD Based on DSP
Introduction During the debugging and development of power electronic devices, it is necessary to frequently change the relevant control parameters, and at the same time, it is necessary to monitor the power waveform at each key point during the operation of the device in real time. In current power electronic
[Industrial Control]
Design of Universal Controller for LCD Based on DSP
FFT spectrum analyzer based on LabVIEW and DSP technology
1 Concept and characteristics of virtual instruments Virtual instruments are an important application of virtual technology in the field of instrumentation. It is a new achievement that is born out of the close integration of the increasingly developed computer hardware, software and bus technology with the
[Test Measurement]
FFT spectrum analyzer based on LabVIEW and DSP technology
Real-time image processing system based on dual DSP
    Abstract: This paper introduces a real-time image processing system based on dual DSP. The system uses two pieces of TMS320C6201 as the system computing center, and obtains the greatest flexibility in the system architecture through the reconfigurable FPGA computing system.     Keywords: real-time image proc
[Embedded]
Design of communication circuit between DSP and Bluetooth module UART port
  As a low-cost, low-power, short-range wireless communication technology, Bluetooth technology is widely used in personal networks in fixed and mobile device communication environments, with data rates up to 1Mb/s; it uses frequency hopping/time division multiplexing technology and can perform point-to-point and poin
[Embedded]
Design of communication circuit between DSP and Bluetooth module UART port
Design of a high-frequency and high-voltage power supply for electrostatic precipitator based on DSP
At present, more than 95% of the dust removal equipment in my country's coal-fired power plants use electrostatic precipitators, and industrial frequency power supplies are generally used in electrostatic precipitators. However, the spark control characteristics of industrial frequency power supplies are poor, the spa
[Embedded]
Design of a high-frequency and high-voltage power supply for electrostatic precipitator based on DSP
Implementation of Embedded Synchronous Controller Based on DSP and FPGA
Abstract: Aiming at the problems of dynamics and stability in the synchronous control of multiple units of printing and dyeing equipment, a design scheme of embedded synchronous controller based on DSP and FPGA is proposed. As the core of operation control, DSP is responsible for the implementation of control algo
[Embedded]
Implementation of Embedded Synchronous Controller Based on DSP and FPGA
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号