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
  • Sensor Arrays e.g. Baby Monitors, Radio Telescopes, Near/Far field
  • Closed/Open Loop Control e.g. Speed, Position, Temperature, Height, Level, Angle, etc
  • Modern Digital Communications


DSP Component Basics

DSP components with an arrow facing away from the component represent a memory block or buffer that can be accessed by one or more other DSP components. The number of values that can be stored and the type of values that can be stored are available via the component properties.

DSP Input Buffer.jpg


DSP components with an arrow facing towards the component represent a reference to the memory block created by another DSP component. The link is controlled via the component properties.

DSP Output Reference.jpg


Once DSP components are linked together a line is drawn between the components.

DSP Components Linked.jpg


The colour of the link line indicates the type of data that is being stored in the buffer.

Colour Buffer Type Range
Black Byte 0 to 255
Red Unsigned Int 0 to 65,535
Orange Signed Int -32,768 to 32,767
Green Unsigned Long 0 to 4,294,967,295
Blue Signed Long -2,147,483,648 to 2,147,483,647
Purple Float 32-bit approximation of a real number


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
Data Queue to Bits Allows an data buffer to be split into bits and sent a bit at a time
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
Quadrature Generator Generates two output waveforms I (cosine) and Q (sine)
Waveform Generator Generates cyclic or randomised waveform data
DSP Outputs
Bits to Data Queue Captures data a bit at a time and stores into a data buffer
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

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 Fast Fourier Transform (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.