DSP

From Flowcode Help
Jump to navigationJump to search

What is DSP

DSP or Digital Signal Processing is a way of processing data in way that provides some kind of additional functionality. DSP usually takes the form of an input, a process on the input and an output corresponding to the process. As microcontrollers are generally quite fast devices it is the act of repeating the process at high speed that allows us to perform the task in hand.


These are all examples of DSP systems at work:

  • Audio effects e.g. Echo, Reverb, Guitar Distortion, etc
  • Signal Filtering
  • Frequency Spectrum Analysis
  • Baby Monitors
  • Radio Telescopes
  • Control e.g. Speed, Position, Temperature, Height, Level, Angle, etc
  • Modern Digital Communications

DSP Components

More detailed explanations, examples and help can be found for each of the DSP components by following the links provided below.

DSP Inputs
Input ADC 2d
Input CSV 2d
Input Digital 2d
Input Digital Pin 2d
Waveform Generator 2d
DSP Outputs
Level 2d
Output CSV 2d
Output DAC 2d
Output Digital 2d
Output Digital Pin 2d
Output PWM 2d
DSP Operators
Adder 2d
Averager 2d
Deinterlace 2d
Delay 2d
Fast Fourier Transform (FFT) 2d
Filter 2d
Interlace 2d
Kalman Filter 2d
Math 2d
Median 2d
Multiplex 2d
Offset 2d
On/Off Control 2d
PID Control 2d
Rectifier 2d
Scale 2d
Simulated Control Load 2d


Input

The DSP Input component is used to pass data from another source into the DSP system. This data could come from an analogue source, a external sensor on an SPI or I2C bus, a data file, the possibilities are endless.

Output

The DSP Output component is used to pass data to another source from the DSP system. This data could go to an digital to analogue converter, a external device on an SPI or I2C bus, a data file, the possibilities are endless.

Frequency Generator

The DSP Frequency Generator component is used to pass fixed waveform data into the DSP system. This data is generated by the component depending on the component's various properties. The waveform data is stored into ROM in the embedded target to allow the RAM memory to be retained for the DSP buffers and other system variables.

Delay

The DSP Delay component is used to create an additional buffered delay. Useful for a wide variety of task such as filtering, phase synchronising, echo effects etc.

Scale

The DSP Scale component is used to alter the data in a buffer by allowing a scale or offset to be applied.

Level

The DSP Level component is used to detect peaks, troughs and averages in the data contained in a buffer. This comes with a decay property which allows you to maintain record values long after they have left the contents of the buffer.

Sum

The DSP Sum component is used to allow two buffers to be merged into one using several different techniques such as addition, subtraction, take the max, take the min etc.

Filter

The DSP Filter component is used to attenuate unwanted frequencies from the data in a buffer leaving the buffer full of only the frequencies we are interested in.

FFT

The DSP FFT component is used to convert a time based signal into a frequency based spectrum by dishing out the frequencies present in the buffer into a number of frequency bins.

Component Macros

A typical DSP system will use a timer interrupt macro to maintain a steady rate on which everything happens. The timer interrupt will do things like any analogue sampling and may also call the DSP component functions in order. Based on this methodology we have created two variants of most of the DSP component macros in the form of Function and FunctionArray. These allow two different ways of working with the DSP component. These methods can be mixed and matched as necessary to allow your program to run at the optimum speed and throughput.


Single

The Function type macros allow a single value in the DSP buffer to be processed. Behind the scenes this performs the hardware macro functionality on the next buffer value.


The tick based functions are designed to operate inside the interrupt function at sample rate. This allows your DSP code to utilize more of the system runtime but means you have less time for other functions such as refreshing a display. Because you are only processing a single value in a buffer rather then an entire buffer the function code is much shorter. This also has a second impact that there is a minimal delay in data being held in the buffer before being processed. The location inside the buffer is automatically tracked for you by the master buffer index.

DSP8.jpg


Array

The Array type macros allow the entire DSP buffer to be processed at once. Behind the scenes this involves a loop and we cycle through all of the values in the buffer performing the macro function. Some components such as the DSP FFT only have the Array version of the macro as the FFT calculations can only work with a buffer full of data.


The standard array based functions are designed to process a complete buffer in one operation. Care should be taken that the processing time is no longer then a single interrupt period.

DSP6.jpg


This method gives you free time between interrupts where other functions can be performed such as updating the GUI on a display. The longer the buffers, the more time you get between having to process the trigger code but the downside is that the trigger code will take more time to process.


For systems with higher sample rates where missing some data is not important the interrupt can be halted by disabling the timer interrupt within the trigger code and then re-enabling when you are done.

DSP7.jpg


If the processing time is longer then a single interrupt period and the interrupt is not disabled then you are likely to get corruption in the data buffer. You may be able to circumvent this by processing the buffers that may get corrupted by the interrupt first. Here you would have to ensure that the entire DSP operations are processed before the trigger mechanism is fired again or data corruption is inevitable. You can test this in your application by checking to see if the trigger variable has been set again at the end of the trigger code.


Combining Single and Array Calls

Both methods of DSP processing have upsides and downsides which cause problems and headaches when dealing with a finite amount of processing runtime and RAM. Before designing a entire DSP system it is important to play around with the individual components to get a feel for what is needed.


For example a system which performs a FFT and then plots the signal data onto a display needs to sample data regularly when populating the buffer so the tick method is ideal. When performing the FFT conversion and writing to the display we no longer need to have constant data and so the trigger approach can be used.


Alternatively an audio system producing an effect onto an output stream needs to have fairly high sample rates, constant data and minimal lag so the tick style approach is more suited.


The single style approach is similar to using the trigger style approach with a buffer size of one so really the design of the system is entirely up to what you feel most comfortable with and what best suits your application.