Audio Filtering Using the MAXQ2000

Publisher:风暴使者Latest update time:2023-07-03 Source: elecfansKeywords:MAXQ2000 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Abstract: The MAXQ2000, with its integrated multiply-accumulate unit (MAC) and single-cycle core, is well suited for use as a general-purpose microcontroller (µC). The performance and I/O peripherals of the MAXQ2000 make it suitable for a wide variety of applications: alarm clocks, handheld medical devices, digital readers, and other applications that require low power, high performance, and a large number of I/Os. The MAXQ2000, with its integrated MAC, has entered the realm of DSP (µC) applications.

How much performance can the MAXQ2000's MAC achieve? This application note uses an audio filter as an example to explain this question and quantify the performance supported by the MAXQ2000.

Software and Hardware Requirements

This application note demonstrates a simple audio filter. The audio data is a pre-recorded audio recording of the author reading "The pipe began to rust while new". This is not randomly selected, but contains the appropriate frequency combination to test the effect of the filter (http://www.cs.columbia.edu/~hgs/audio/harvard.html). The audio recording can be replaced with any suitable length of 8kHz recording, but it is not necessary.

The hardware required for this application note includes the MAXQ2000 evaluation board and a simple circuit to implement the computer speaker interface.

The available MAXQ2000 evaluation board is the best tool to understand the performance of the MAXQ2000. It includes an LCD panel and a set of LEDs. All I/O pins of the MAXQ2000 are accessible through the evaluation board. The MAX1407 ADC / DAC integrated on the evaluation board can be used for audio output.

The second part of the hardware required can be easily implemented on a circuit breadboard. The circuit used for the demonstration is shown in Figure 1. It connects to the MAXQ2000 EV kit at J7 using a 1 x 8 female header that needs to be connected to any ground potential (TP1 on the MAXQ2000 EV kit can be used). The speaker connector can be of any type, but a 3.5mm stereo jack is shown to facilitate connection to common computer speakers. Note that the two input channels are connected in parallel, as our demonstration uses only one audio channel (mono) . Figure 1. Additional Hardware Required for Audio Playback ...

Figure 1. Additional hardware required for audio playback


Run the Demo

The buttons on the MAXQ2000 EV kit are used to select filters and play the filtered audio samples. Use button SW4 to select the filter, and the filter name will be displayed on the LCD (HI for highpass , LO for lowpass, BP for bandpass, ALL for allpass). Use button SW5 to play the audio through the selected filter. The filter can be switched during playback.

Design a simple FIR filter

This article uses a Java ™ applet to easily generate new filters. Rather than using standard windowing techniques to generate filter parameters, filters are simply "designed" by placing zeros on a pole-zero plot, as shown in Figure 2. The applet places zeros anywhere on the coordinate plane and automatically updates the parameters of the FIR filter required for the demonstration. Note that the demonstration only supports all-zero filters. Supporting IIR filters is not difficult and is explained in detail in the Supporting IIR Filters section. Figure 2. Using a Pole-Zero Plot to Generate a Simple FIR Filter The linear equation for a general filter is: y(n) + bKy(k) = aJx(j) where k is the order of the filter's feedback portion and j is the order of the filter's feedforward portion. An IIR filter can be simply represented by: y(n) = 0.5y(n-1) + x(n) - 0.8x(n-1) Some filters are classified as FIR filters and do not include a feedback portion. In other words, the y component is not included in the filter characteristic equation: y(n) = aJx(j) y(n) = x(n) - 0.2x(n - 1) + 0.035x(n - 3) In any case, the filter can be reduced to a characteristic equation, which is essentially a weighted average of past inputs and outputs. The filter design is to generate the Aj and Bk values. To efficiently calculate the filter output, you need hardware that can multiply and add signed numbers quickly, which is the MAXQ2000's multiply-accumulate unit.

Figure 2. Using a pole-zero plot to create a simple FIR filter.

















Implementing a filter using a multiply-accumulate (MAC) unit

The applet in the previous section calculates the filter parameters by specifying the zero coordinates in the graph. However, the calculation results are floating point numbers, while the MAC is a pure 16-bit integer operation. To solve this problem, this demonstration uses a fixed point numerical system, where bits 0 to 15 of the parameter are the value to the right of the decimal point (the 16th bit represents the sign polarity). After the operation is completed, the 48-bit result in the MAC accumulator is shifted to remove the remainder.

This solution is a trade-off between accuracy and speed. In many cases, the error produced by this method is negligible. For diagnostic purposes, the applet can display three curves of the calculated filter. The first curve shows the operation of the ideal filter using 64-bit floating point numbers. This curve is labeled "Ideal Transform" in Figure 2.

Figure 3 plots the remaining curves generated by the applet. The first curve shows the effect of filtering using 16-bit fixed point numbers. In many cases, the error is not obvious. The last curve is an error indicator, showing the ideal frequency response divided by the actual frequency response. Ideally, this is a straight line with Y = 1. Figure 3. 16-bit filter in action and with rounding errors (visually no errors) For simplicity, the applet generates the floating-point parameters required by the MAXQ® filter, so new filters can be implemented simply by cutting and pasting them into the filter source file (data.asm file). The applet also generates two other values, the filter order (number of parameters) and the shift amount, so the application can shift the final result appropriately. The data appears in the text box at the bottom of the applet and may be presented in the following ways:

Figure 3. Actual effect of 16-bit filter and rounding error (visually no error)


Zeroes: dc16
    dc16 12, 11, 0x1000, 0x26d3, 0x1e42, 0xf9a3, 0xecde, 0xff31, 0xa94,
         0x2ae, 0xfd0c, 0xff42, 0xde
Shift amount: 12

Implementing filters using MAXQ assembly language

To achieve the best performance and to perform accurate performance analysis, the actual filter is implemented in assembly language so that the exact number of cycles required to produce one output can be calculated and the performance of other data settings can be estimated.

The MAX1407 contains a 12-bit ADC . Since the input data is 16 bits wide, the filter produces a 16-bit result. Although the 4 least significant bits (LSBs) are not used in this application, the performance can still be analyzed normally for 16-bit calculations and outputs (CD-quality audio is 16 bits).

In this example, the filter parameters are stored in a table in the code area. After a filter is selected, the application finds the appropriate filter, reads the number of shifts and taps, and then prepares to begin digital filtering. The following code applies the filter parameters:

    move MCNT, #22h ; signed, mult-accum, clear regs first

zeroes_filterloop:
    move A[0], DP[0] ; let's see if we are out of data
    cmp #W:rawaudiodata ; compare to the start of the audio data
    lcall UROM_MOVEDP1INC ; get next filter coefficient
    move MA, GR ; multiply filter coefficient...
    lcall UROM_MOVEDP0DEC ; get next filter data
    move MB, GR ; multiply audio sample...
    jump e, zeroes_outofdata; stop if at the start of the audio data
    djnz LC[0], zeroes_filterloop

zeroes_outofdata:
    move A[2], MC2; get MAC result HIGH
    move A[1], MC1; get MAC result MID
    move A[0], MC0; get MAC result LOW

Before executing this code, LC[0] is loaded with the number of filter taps, DP[0] is loaded with the current filter input byte address, and DP[1] is loaded with the filter parameter starting address. DP[1] processes the filter parameters in incrementing fashion, and DP[0] processes the input data in decrementing fashion (most recently input data is processed first).

Since the MAC operates in a single cycle, the processing code is relatively small. MCNT is set to 22h to represent the use of signed integers. In the main loop, consecutive writes to MA and then MB trigger the multiply-accumulate operation, with the result ready on the next clock cycle. Since the accumulator is 48 bits (the result of the multiplication is 32 bits), there will be no overflow (unless there are 64,000 taps in the filter!).

performance

This application processes mono 16-bit audio data and produces an 8kHz output, which does not fully utilize the microcontroller's capabilities. Since the filter is written in assembly language, an expression can be used to easily calculate the number of cycles required to calculate a FIR filter of length N. This expression can then be used to calculate the maximum filtering rate using the algorithm

listed above. The functions used to generate audio samples can be divided into three parts: initialization, filter calculation loop, and result correction. In this example, initialization requires 38 cycles, filter calculation requires 17 cycles per filter parameter, and result correction requires 9 + (6 x S) cycles, where S is the number of shifts. Typically, a shift of 12 results in 81 cycles of result correction. Therefore, 119 + (17 x N) cycles are required to produce a filtered output. At 20MHz, the MAXQ2000 can run a 100-tap filter at nearly 11kHz, which is already quite good voice quality.

Now let's go back and re-analyze the application to simplify it further. We will focus on the filter loop because it takes up the most cycles and is the most tedious.

Several key changes can be made to the loop code to improve efficiency. Note that we use audio samples that were prerecorded and stored in the code area. Because the MAXQ uses Harvard architecture, searching the code space takes more time than searching the data space. The functions called UROM_MOVEDP1INC and UROM_MOVEDP0DEC require five cycles each to execute (two cycles for LCALL and three cycles inside the function). If the filter is stored in RAM and processes real-time input data stored in RAM, only two cycles each (one cycle to select the pointer and one cycle to read it) are required. If 256 words of RAM are used for the filter, a circular buffer can be implemented using BP[Offs] to store the input data. These changes reduce the loop time from 17 cycles to 11. The filter loop looks like this (the required cycle number is listed first in the comments):

[1] [2]
Keywords:MAXQ2000 Reference address:Audio Filtering Using the MAXQ2000

Previous article:Video surveillance adapter circuit
Next article:Quick Start: Driving a 16-Segment LED Display with the MAX6954

Latest Embedded Articles
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号