A Versatile Audio Processor
by HB9BTL-Markus in Circuits > Electronics
594 Views, 7 Favorites, 0 Comments
A Versatile Audio Processor
We all know the situation: Deep down in the QRM we are chasing a rare station, but our homemade receiver lacks the selectivity to isolate the desired signal from the interference. A DSP-filter with its razor-sharp edges would now be a great add-on.
Years ago, digital signal processors were expensive devices that needed even more expensive fast external memory. The development tools and programmers were not suitable for the limited budget of the common ham either. Fortunately, this is no longer true. Today, a powerful DSP with ample program and data memory, all the necessary interfaces and a handful of timers costs less than a juicy meal at your favorite fast food restaurant. An integrated development environment with a full-blown C-compiler can be downloaded for free.
This all led to my decision to develop a versatile audio processor with the following specifications:
- A low-cost digital signal processor with nearly 70 million instructions per second, 512 kByte flash program memory and 52 kByte of data memory.
- A low power stereo codec with an integrated headphone amplifier samples the signals with a resolution of up to 24 bits. The sampling rate can be configured to be 8, 32, 48 or 96 kHz.
- Two rotary encoders, three buttons and a graphical liquid crystal display serve as a simple user interface.
The possibilities are almost limitless. You can use this device to process the stereo signal of your hi-fi system or to build the signal processing part of an SDR receiver. Maybe you use it as a simple audio oscilloscope or spectrum analyzer. Or on stage to distort the sound of your electrical guitar. In this article, we will describe how to use it as an adjustable filter for processing the audio signal of a receiver. An automatic notch filter that suppresses sinusoidal interferences is also implemented.
Why Digital Signal Processing?
What is wrong with good old analog signal processing? Nothing at all, on the contrary. Analog signal processing is the right choice in many applications. But when it comes to processing audio signals, digital signal processing shows its strengths.
- No high tolerance components are required to build filters with stunning performance.
- Sensitivity to temperature, aging and drift is minimal.
- The filters are completely reproducible, identical circuits behave identically. As a rule, no adjustment is required.
- Many functions cannot be realized with analog filters or only with considerable difficulty. These include filters with linear phase response, adaptive filters or the calculation of spectra.
- With today's technology, it is possible to implement digital filters with small dimensions, high reliability and low costs.
However, there are also issues that need to be considered when working with digital filters where sampling values are processed instead of analog signals. These samples are obtained by sampling the analog signal in an A-to-D converter. In order to avoid loss of information, the sampling rate of the converter must be chosen sufficiently high, whereby the sampling theorem states that the sampling rate must be at least twice as high as the highest frequency in the signal. To ensure this, an analog low-pass filter (called anti-aliasing filter) must be inserted before the converter to eliminate all high frequencies of the input signal. Likewise, a low-pass filter (called reconstruction filter) must be added after the D-to-A converter to smooth the somewhat angular signal at the output of the converter by removing all high frequency components.
In our application we process speech signals which can be cut off at 3.5 kHz without losing information. Therefore, we choose a sampling rate of 8 kHz. The good news is that the necessary anti-aliasing and reconstruction filters are already integrated in the codec chip.
Hardware
The block diagram in Figure 1 reveals that the system consists of two parts. A main board containing both the digital signal processor and the codec and a second board that contains the user interface, consisting of the graphical LCD, three buttons and two rotary encoders.
Both the signal processor and the codec require only a handful of external components. All clock signals are derived from a single crystal oscillator integrated in the codec. Its frequency (12.288 MHz) is a little unusual, but can be explained by the fact that the desired sampling rates (8, 32, 48 or 96 kHz) can be derived from it. The codec TLV320AIC23B is responsible for converting analog audio signals into digital samples and vice versa. It can be configured by the signal processor via an I2C interface. The audio samples are transferred back and forth via an I2S interface which consists of a bit clock, a frame clock and two data signals, one for each direction. Both the entire signal processing and the functions of the user interface take place in the signal processor, a dsPIC33EP512MC806. It features a digital signal controller core that can handle up to 70 million instructions per second and contains all the necessary on-chip peripherals. At a sample rate of 8 kHz, this allows more than 8000 instructions to be executed per sample - more than enough for most audio applications. Finally, the main board also contains two voltage regulators, one each for the analog and digital supply voltage of 3.3 volts. Thus, the circuit can be powered with any voltage between 5 and 9 volts. A Schottky diode at the input prevents a disaster when the polarity of the input voltage is reversed.
On the user interface board, text and graphics can be displayed on a monochrome graphic display with a resolution of 102x64 pixels. The signal processor sends the necessary data to the control board via a serial interface (SPI – serial peripheral interface). The user can utilize two rotary encoders to control various parameters. Choices can also be made by pressing one of the three available push buttons or by pushing one of the rotary encoders.
Framework
Before we can start processing audio data, all interfaces as well as the codec and display must be properly configured. For this purpose, quite a lot of registers must be loaded with correct values. This is the task of the framework software. Once this is done, the codec starts the acquisition of the audio data. The framework software also ensures that the input data from the codec will automatically by stored into one of two input buffers and data from one of two output buffers will automatically be written to the codec (cf. Figure 2). The user does not need to worry about how the data gets into the input buffer and how the output buffer data is sent to the D-to-A converter, direct memory access (DMA) will take care of this.
If the user wants to write his own signal processing algorithm, he can basically concentrate on the function user_processData(). Each time a new block of input data is acquired, this function is called and provides the user with a block of input samples and a pointer to the beginning of the current output buffer. The block of input data can subsequently be processed, and the result stored in the output buffer. Fortunately, an extensive library of signal processing functions is available for this purpose.
Tasks not related to signal processing can be performed in the user_mainLoop() function, which is called continuously in a loop as long as no signal blocks need to be processed. Here, for example, the control elements can be polled, and appropriate measures can be taken.
Application
So, what can be done with the described hardware and firmware? There are a lot of possibilities, but we used it to process the output signal of a receiver, either with a bandpass filter or a combination of high and low pass filters. We wanted to be able to select the center frequency and bandwidth of the bandpass filter or the cut-off frequencies of the high pass and low pass filters almost continuously. As an example of an adaptive filter we implemented an automatic notch filter capable of autonomously suppressing sinusoidal interference signals. Finally, the spectrum of the input signal is continuously displayed. This allows you to see at a glance where the desired cw signal or where an unwanted interferer is hidden.
To use the system, all you need to do is connect the input marked “Line In” to the receiver's output. An active loudspeaker can be connected to the output marked Line Out. Alternatively, headphones can be plugged directly into the headphone output. A few seconds after connecting a supply voltage, you should see the contents shown in Figure 3 on the display. However, it is possible that the contrast of the screen may not be satisfactory at the first startup. You can fix this by holding down the left-hand encoder during power-on. A menu appears that allows you to set and save the contrast. Figure 3 depicts the content of the display during normal operation. The bandpass filter has been selected and is activated. With the rotary encoder, the center frequency can be changed between 300Hz and 3600Hz in increments of 50Hz. The other encoder is used to select the bandwidth between 100Hz and 600Hz. The bar below the spectrum display shows the passband of the filter. Pressing the button marked FLTR switches the band-pass filter on and off.
A push on the right encoder toggles from the bandpass filter to a combination of high and low pass filters. In this operating mode, the cut-off frequencies can be controlled by turning the encoders. A notch filter can be added with the NTCH button. This will automatically suppress all narrowband interferers.
A longer push on the left encoder opens the configuration menu. There you can choose whether the spectrum of the right or the left channel is displayed, and which window and averaging method for the FFT is used. Other menu pages allow you to adjust the gain factors of the input channel or headphone amplifier or the contrast of the display. Adjusting the input gain is particularly important, otherwise the codec can be overloaded, resulting in strong non-linear distortions. But don’t worry, in this case an OVERFLOW message will appear at the bottom of the display reminding you to either adjust the level of the input signal or the gain of the codec.
Development Tools
To program the digital signal processor or even to develop own software for it, three things are needed:
- an integrated development environment (IDE), which provides a unified, integrated environment for developing software for microcontrollers. For the dsPIC used in the project, the program MPLAB X IDE is suitable, which can be downloaded free of charge for various operating systems from the website of the manufacturer Microchip. Experience has shown that there are hardly any problems with its installation. However, it may be necessary to adjust the DPI scaling on Windows computers with a high screen resolution. To do this, right-click on the program icon and select Properties → Compatibility → Settings to have the system perform the scaling.
- a C compiler, which translates the source code written in the C programming language into code that can be executed by the processor. We can find such a compiler under the name MPLAB XC16 (Attention: not XC8 or XC32!) on the website www.microchip.com/mplab/compilers. The free version allows only a minimal selection of optimization levels, but this is sufficient for many purposes. For our application, the memory model must be set to "Large" in the MPLAB X IDE under Production → Set Project Configurations → Customize → xc16-gcc → Option categories: Memory model → Code model: Large.
- a programming device, with which the code is finally stored in the program memory of the processor. An inexpensive variant is the MPLAB PICkit 4 In-Circuit Debugger or its predecessor PICkit 3. This is connected on the one hand to a USB interface of the computer and on the other hand to the programming interface of the audio processor, whereby when using the PICkit 4, connections 7 and 8 remain empty on the PICkit.
Conclusions
During the past few months, the presented audio processor has served as a valuable addition to some simple home-made receivers. With the help of the extremely selective and flexible filters, QSO could be made that would not otherwise have been possible due to interference or excessive noise. Weak CW signals that were surrounded by strong signals could easily be decoded. SSB signals disturbed by strong carrier signals benefited from the automatic notch filter, which reliably removes such interference and the bandwidth could be optimally chosen by the low and high pass filter. A very useful feature is the visualization of the spectrum on the display. This makes it easy to identify weak signals and disturbances.
But the possibilities of the presented circuit are by no means fully exhausted. There is still plenty of free memory and computing power to implement more and advanced features. Therefore, the existing software will be released as open source in the hope that further functionalities and applications will be developed by the ham community.
Project Documents
You can find a lot more data (software, PCB files, pictures, circuit diagram, BOM) here.