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 Inputs from an ADC enabled input pin
Input CSV Inputs data from a file
Input Digital Inputs generic digital data
Input Digital Pin Inputs from a digital input pin
Waveform Generator Generates cyclic or randomised waveform data
DSP Outputs
Level Monitors data statistics like peaks and troughs
Output CSV Outputs to a file
Output DAC Outputs to a DAC enabled output pin
Output Digital Outputs generic digital data
Output Digital Pin Outputs to a digital output pin
Output PWM Outputs to a PWM enabled output pin
DSP Operators
Adder Adds together two or more DSP signals
Averager Takes an average of two or more DSP signals
Deinterlace Breaks apart a single interlaced DSP signal into sub signals
Delay Adds a fixed or variable delay in the DSP signal
Fast Fourier Transform (FFT) Converts time based DSP signal data into Frequency based
Filter Provides digital filtering on a DSP signal
Interlace Combines multiple DSP signals into a single DSP signal
Kalman Filter Provides predictive digital filtering on a DSP signal
Math Mathematical operations with two DSP signals (+,-,/,* etc)
Median Provides median filtering on a DSP signal to get rid of spurious data samples
Multiplex Allows a number of DSP signals to be selected and switched between
Offset Adds a fixed or variable offset to a DSP signal
On/Off Control Provides simple on/off closed loop control
PID Control Provides P/PI/PID closed loop control
Rectifier Allows a DSP signal to be flipped below a certain threshold
Scale Applies a scaler to a DSP signal
Simulated Control Load Simulates an active load such as a heater or motor to allow simulation of closed loop systems


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.