It's a high - tech laboratory. The nurse opens the door not with her hands, but her voice, saying "Open door". The MCU takes a second to register the sound, approves it, and opens the door of the laboratory. The nurse puts her index finger on a measurement board, and on the screen it shows ("60 beats per minute"), she just measured her heart rate. She logs the data in her computer and sends it to a server over wireless network. To ease off a hard day of work, she plays her favorite song on the mp3 player, and takes a couple minutes to relax.
All the technologies involved here have the same process going on, can you guess what it is?
It's Digital Signal Processing (DSP).
Whenever engineers or scientist need to measure a certain occurrence in the world around us, the measuring is expressed by form of an analog signal. Using an analog to digital converter, we get a digital signal. But that's only the begginning of their work. In order for us to understand what the signal means, we need to process it. It is a complex process, but one that is done almost every day in high-tech environment. Scientists use it to measure natural phenomena (earthquakes, heartbeats, MRIs etc.), engineers use it to make a perfect machine (airplanes, robots), it's a process crucial in all of the mentioned applications.
Digital signal processing can be done on standard computers, but there are also specially designed processors for this type of problem, called digital signal processors (DSPs).
Digital Signal Processors
DSPs, like said before, are special microprocessors made for digital signal processing. They have a specific architecture, which is optimized for operations needed in order to do a digital signal processing. They often have a special memory architecture, which can fetch mutiple data at the same time, and thus provide more speed and efficiency to the CPU.
Processing of this data is usually done with a lot of mathematical calculations, so the DSP needs a fast memory and a capable enough CPU to do this. Also, DSPs usually cost a lot of energy. So be prepared to feed these monsters some power, they will need it!
The memory architecture of these processors is usually Harvard architecture or a modified von Neumann architecture. Operating systems which run on these processors frequently use multi-tasking to get their job done, however, they don't support memory protection or virtual memory, since they tend to increase latency.
MikroElektronika offers a variety of DSPs, from Microchip's DSPIC33 designed specifically for these types of usages, to ST's STM32 which have DSP capabilities.
Digital Signal Processing Algorithms
Domains
When doing DSP, engineers and scientists often talk about domains. Different domains are used for different types of signals, every domain filters the signal based on a certain criteria. The domains are usually some of the following: time domain, frequency domain, wavelet domain etc. Engineers choose the domain based on which particular data they are searching for.
Time and space domain
This is the most common approach in DSP, it usually consists of a linear transformation of a number of samples surrounding the current sample. An oscilloscope is one of the common tools for visualizing signals in real time. Different filters can be used for DSP in the time domain, these include : linear, casual, time-invariant, stable filter and finite impulse response (FIR).
Frequency domain
Converting a signal from the time domain to the frequency domain is usually done using a Fourier transformation. This transformation supplies the engineer with information of a magnitude and phase of each frequency. The engineer can then study the spectrum of frequency, and see which frequencies are present and which are missing.
Z-plane analysis
Digital filters can be analyzed in using Z-transforms. The z plane maps digital frequency (samples/second) to real and imaginary z components. This is useful for providing a visualization of the frequency response of a digital system or signal.
Wavelet
One of the most popular algorithms for transforming from time to frequency domain, a wavelet transform is any wavelet transform for which the wavelets are discretely sampled. It has an advantage over the Fourier transformation as it captures both frequency and location in time.
Numbers and formulas, what about code?
Okay, so all of those descriptions and links only lead to some abstract terms and mathematical formulas. How is that helpful? What about real implementation? Where is the source code?
Different engineers have different approaches, the amazing developers at the software department of MikroElektronika have written a DSP libraries for PIC32, dsPIC and STM.
Here's a short tutorial for an FFT on PIC32 written by our developers:
Let's say we have our input samples, coming from whichever source of signal you like:
int inputSamples[16] = { 0x4000, 0, 0x4000, 0, 0x4000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
These are 8 pairs of numbers, each pair has one Real and one Imaginary number.
Now we need to define twiddle factors for each pair:
const int Wn[8] = {0x7fff, 0, 0x5A82, 0xA57E, 0, 0x8000, 0xA57E, 0xA57E};
Since we have 8 pairs of samples, we have 8 twiddle factors. Each sample will be multiplied with the corresponding twiddle factor.
The third parameter which we need for FFT calculation is the level number, it is equal to the logarithm base 2 of the number of samples. Since we have 8 samples, log2(8) is 3.
unsigned int log2N = 3;
Now we can do our transformation, the function operates on an in-place buffer which uses the same buffer for input and output:
FFT(inputSamples, Wn, log2N);
Finally, we need to do a complex bit reversal, again on the same buffer:
BitReverseComplex(inputSamples, log2N);
And that's it, our signal has been digitally processed, we can now examine the signal better and find what we are looking for.
More examples of DSP can be found in the examples folder of our compilers in the folder "Digital Signal Processing".
Full source code can be found here.
As for other algorithms, GitHub is always a good choice.
In the end, the job of an engineer is to constantly create and improve, use the basics you've gathered here, expand your knowledge of digital signal processing, and develop your library. Space shuttles need better landing programs, medical devices need a better image processing algorithm, radio modules need better signal recognition, the world is counting on you!