 We will play a little bit with the DSP. So first of all, I will try to make short introduction into the theory. Then the main part of the session will be the hands-on. So we will show you how to really do some basic algorithms used in DSP, specifically with the ARM library CMSIS. So let's start with a few examples of the applications. So it doesn't need to be only audio, even though we will present it on the audio because it's very easy to do. So it's mp3 equalizers, hi-fi audios. We have also applications for voice coding, decoding, or even voice recognition systems. For hands-free systems, we have applications for noise cancellation, echo cancellation, and so on. But a part of the audio there is plenty of other applications. For example, managing any sensor data, you typically need to filter out if you have accelerometers, gyroscopes, and so on. You need to filter the signal which you are getting. Medical devices, the same for any signals which are coming from the medical devices. Motor control can use DSP algorithms and basically any industrial application. Whenever you have some series of data which can be treated as a signal, we can say that we are using a DSP. Well, very briefly what the DSP is. We can say that by DSP we are trying to do the same actions like we can do in analog world by the common parts, resistors, inductors, op-amps, comparators, where you can build some blocks like filters, addition, subtraction, active filters, generators, multipliers. All this you can transform to digital world and you can add much more. So again, you can use simple building blocks like absolute value compare, multiplication, addition and so on to build up more complex algorithms, filtering and much more like voice encoding recognition. So both of the domains analog and digital has some advantages but also some disadvantages and we will shortly see the advantages and disadvantages. So typical processing of signal in digital domain looks like that, that always you start from the analog value. It can be audio, it can be motion, it can be temperature, it can be whatever but usually you start from the analog value and you need to convert it to digital world. For this you usually use ADC if it's in terms of voltage but before you always need to have analog filter because of Shannon-Nikwis theorem and to avoid aliasing. Then you do the signal processing in the digital domain and then it depends if you want to convert back to the analog domain you need to use the AC and NAA filter analog filter anti-aliasing filter. So what are the advantages of DSP? It's clear that it's very flexible. You can change everything by software, you can change the algorithm, you can change the constant which is much easier than to replace resistors and capacitors on the PCB. The same for upgrades, it's highly linear. Well a lot of algorithms can fit into one chip so if you want to develop more functionalities you can still fit into one IC, better control or over accuracy. But okay I think everybody knows this but what are the limitations and this is not so widely known and we should also be aware about this and we will also see during our hands-on. So first of all you have the discrete time artifacts aliasing so you need to really be careful that you process only the signals with the given frequencies. If you exceed the frequencies you get the aliasing and these artifacts. What is even let's say more distracting is the finite word length effect or a computation noise. So even we are in digital domain we can by digital computation we can add a noise called by quantization noise or computation noise. So that you need to take care especially if you account with fixed numbers, fixed point numbers. Then you have the limitation of the processor speed so for every algorithm you need some CPU performance to work with so simply the processor cannot process everything. Okay sometimes the consumption is can be critical because the passive filter doesn't consume anything while whenever you put DSP inside or any processor you will consume some power and the clock and switching can cause interference. And still you need the analog for these conversions. Okay if you look more into what STM32 in general can offer in terms of DSP apart from the CPU itself how to acquire data you can use the built-in ADCs so we have up to three ADCs in a chip depends on which STM32 you select with many channels and we have 12-bit or 16-bit ADCs in our portfolio. Then if you have external sensors or you do external acquisition for sure we support many communication peripherals to acquire data already digitalized and we also have op-pamps and comparators to create the analog filters and Sigma Delta the modulator on some devices. Well then you do the processing and if you need to send out the data you can send over again any other peripherals communication peripherals or we have in built-in ADCs to directly convert to voltage. Well I was mentioning the liquid channel theorem so just briefly if you have a frequency of input signal you need to sample it at least twice fast otherwise if you if this is an input signal and you sample it only in these points the reconstructed sine wave would be completely different frequency so everybody knows and for to achieve this you always need to have an analog filter before acquiring the data. Okay so that was clear what is sometimes a little bit forgotten is this fixed point constraints and limitation. So be very careful if you have 8-bit 16-bit 32-bit data whatever length of the data always there is some at some point you will get the limit of the smallest LSB and if you count really with the small numbers and with audio it's very typical that there is a huge dynamic range from very loud to very very small signals. If you are somewhere counting with only somewhere there you can clearly see that if you multiply two numbers very small numbers you can very easily round to zero and you lose your signal completely. So in DSP usually we work with the fixed word numbers in these formats maybe you are familiar with that. So for example this Q15 this is classical 16-bit integer but we represent it as a number going from minus one to the two plus one almost plus one and zero in the middle so if you multiply these two numbers together you will never get above one but only below one and the more you multiply the more left side in the LSB part of the number you get and the more quantization noise you get. So be careful when you're using fixed point about this. Another problem with fixed point may appear when you are adding two numbers and then you can easily overflow the one plus minus one boundaries. So what may happen you can have two options like in normal arithmetics if you add let's say one plus one you overflow to minus one which is here or you can apply a saturation arithmetics which means that you overflow but you are saturated to one. Both of these approaches brings a lot of distortion but in this case much less and STM32 or Cortex M4 and M7 support this arithmetics so you can select before you do the computation if you want to use the saturated arithmetics or not saturated arithmetics. By default all the instructions are using non-saturated arithmetics like you know if you count with the counter from 0 to 255 if it's 8-bit then you overflow to 0. So you need to be aware about these two limitations of the fixed point when you do any computation. And now we go to the real DSP. So what are the most frequently used DSP functions? I have selected few of them it's the filtering either it's a finite impulse response filter or infinite impulse response filter, FFT or correlation convolution this is the nasty mathematics around but if you look into the equations all the time there is a multiplication of two vectors together and summary of all these multiplications. So what is the outcome that whatever you do in DSP you need heavily to use multiplications and accumulations.