 So what we can do with such signal? There is one very simple processing called Correlation and we can use it for determining the direction of the sound which is coming to the board. Physically our board looks like this. We have two microphones with a distance of 2.1 cm and if the speed of the sound is finite and it is roughly 340 m per second we can determine this angle so which direction the sound is coming to the board just by delay of the sound between one microphone and another microphone. So very simple mathematics will give us from the delay in time we can compute the delay in distance. With delay in distance we can easily compute the angle. There is nothing magic inside just the matter how do we measure the delay between two signals. Considering that the signal in left and right will be very very similar but not completely the same because both microphones can have roughly different amplification. Also there could be some noise around which is coming from another direction. There could be some reflections. So these signals will be very similar but not the same. So we need to know what is the delay between similar signals and how to do it with DSP. The cross correlation function is almost ideal to do that. So we are getting one signal which is left, second signal which is right and we are doing cross correlation function which is again nothing else than a lot of multiplications and a lot of summaries or additions together. And the result may look something like this but it depends on the signal which you get. In this slide it's maybe more self-explanatory. So if you do this equation you are actually this N means the delay between two signals. So for every N you get a result and the result depends on the delay. So for sure the biggest output of the cross correlation will be when the signal matches or when the signals match. And if there was initially a delay between these signals you need another delay to compensate it and if we are able to determine this delay to compensate it we got our delay between two signals and that's it. So to determine our delay you are just seeking for maximum in the result of cross correlation function. Okay nothing else. So to determine the angle we just use left and right put it to correlation function. Take the output which will be another array and search for maximum. If we have the maximum we have got the delay and that's it. So briefly two operations cross correlation and maximum find and that's it. And this is what we do in our software. So well if we have the delay then we can simply acquire the angle through this very simple equation. So we can run it now in the STM-42. So our demo is based on few flags. In the main loop after extraction of the left and right signal we are checking few flags and doing something. So these flags are also visible in the live watch window. So you can change the behavior of the software without recompiling it just changing the value in the live watch window here. Well out of the box you should get the do correlation flag set to one and the others set to zero. But only this part of the while loop or on the main loop is executed. If this flag is set I'm just calling the correlate function and that's it. So this is the function from the CMC's library. So running the correlation function as a user all I need to do is to call one function from the library and that's it. So particularly easy from user perspective or programmer perspective. As the argument it takes left and right array and this is the output. So once the software goes through this function I have my correlation function computed. And after the break point just by simple loop I search for the maximum. And my maximum is set to this max correlation index. So well you can remove the break point leave it running. And actually this index is shown on the LCD screen as well. On the first line there is the delay is a line which shows normally zero. But if you talk to the board from left side or right side it should show minus one or plus one. Please open the Sala process two and run it by F5. And you should get the same result as before but another window should appear with the cross correlation result. On the top we just download the correlation result from STM32 and show it on the screen. On the bottom I took the left and right channels and I compute the correlation in the PC so by the silo correlation function. If everything works well you should see the same behavior of the cross correlation function. The only difference can be the amplitude. You see 100 something and 5 million something in the PC. This is because the STM32 the CMC library function is truncated every result needs to fit into 16-bit value. We are working with 16-bit numbers. So every intermediate result must fit into 16-bit value so it's truncated every single addition. While here we are keeping the full scale of all the numbers. So we don't need to take care so much about the scale but what is important is the maximum. And where the maximum is. So if you had the maximum here the signal would be very left. If it would be on the left side it would be very right. So this is how this works. Typically if you don't know if your algorithm is working well or not. You should always make the copy of your result. Show it, compare it with the simulation and only then you can say if it's working or not. Well in this case we are able to measure quite huge delay in a lot of samples. But in our case because the microphones are very close to each other. In reality we have seen that delay can be only minus one or plus one. If the sound was slower it could be better but not in our case. So this example is very nice to show cross correlation as it is. But we have seen that the CPU's each is 10% or around at least on the screen I have 10.6. And this is because you need to compute the whole bunch of the data. Which if we are expecting the delay minus one to plus one it's not really necessary. This is just more to explain how the cross correlation function is working. So in practice if you really want to make this sound direction elaboration. It's enough to have 32 samples or 64 samples to really get the delay in quite small amount of data. And you can change it then in the source code. And you could see that the CPU load will decrease much far below 1%. If you also examine a little bit the script. So we kept the same we plotted left and right signal. And then I also plot the STM correlation which is loaded from the hex file generated by our IR. And then I compute the correlation by CELAP. So here it's extremely easy. One function, two arguments, I got the result and I plot it below the previous one. And what I do is also that I compute the delay which in CELAP is very easy. I just call function max and it will give me the index of the maximum. So then in the console you have the variable browser something like a watch window. And this delay here is minus one which I computed by CELAP. And I also computed the delay of the correlation generated by STM32. It's also minus one. So in this particular case we have seen that the simulation works pretty well. And here we come to the limit of the fixed point. So you see that if there was nothing set around the time when I was hitting the breakpoint. You see that the signals are very small. Well, this is the correlation function. But the signals left and right. Let's see what were the values. Well, hardly 60. We are speaking about 16 bit format. So 60 where the boundaries are 32,000 something. So very, very small numbers at this time. And if we multiply small numbers what we get even smaller number. So the cross correlation function will look like this. We hardly reach 10 in amplitude. So here we can demonstrate very nicely the limit of the fixed point. The result is pretty poor compared to what you get if you compute in never ending numbers in PC. So even from the small numbers you can get quite nice result if you don't truncate all the time. So here again for audio signals if you want to make it working for loud signals and small signals. It would be better maybe to use the float point. So again this is quite useful to visualize that you can immediately see that there is something wrong. And you need to think about what is wrong and all the consequences. So what we have seen the delay works quite well. We are able to see the angle, but the angle is only equals to 90 degrees or plus minus 90 degrees. Why? Because the sampling rate is 16 kHz and the speed of sound at 16 kHz is exactly 2.1 cm. So it's not by chance that we put it by 2.1 cm. If you decrease the correlation samples. So how many samples you use as the input for the cross correlation? You can use 16, 32, 64. Well with 16 we have seen that the detection is not always the best one because you cannot estimate all the frequencies. Then it depends really on the input signal. So you can use 32, 64. It works quite well. Still keeping the CPU load much much smaller than if we are working over the full bunch of the data every time. Now we have seen the cross correlation. So how we use it in real life? With the cross correlation this is the easiest one. You have one function from the library. You run it, you get the result. That's all you need. Very convenient for the user. Just one, maybe one comment. If you look for the documentation there is already a reference on the online but also offline. And it is quite well described in the comments. So you get all the description what it does. And for all the functions you see that the suffix is showing the numbers or the number format you are targeting. So all the functions exist with variance underscore q8, q15, q31 and float 32. So the cross correlation function is very easy to use. You just put arguments of the inputs and you got the output. Let's have a look on the filtering maybe. So for the filtering the easiest one to deal with is the fair filter. So finite inputs response. Actually it's very similar to the correlation but it just works over the history of the data. Because it has some history it needs to have a handle which is pointing to this history. Some previous state of the signals. So for the filters and FFT you need to initialize them first. Later on when we look into the code before my main loop I'm initializing the filters and the FFT instance. So working with the filters is as easy as with correlation but you just need to initialize it before this handle. And then you just pass the source and you pass the pointer to the destination and how long is your filter. And that's pretty much all you need to do to perform a filtering. So we can have a look on the filtering. Let's have a look or let's take an the easiest example is a low pass filter. I think we have developed a filter with one kilohertz cutoff frequency. So you were once you can enable one of those filters at a time in the life watch window. So you don't need to recompile anything in the life watch. You just enable do filter IR or do filter fear and the main loop will change the behavior so it will filter also the signals. Then you can hear the change of the sound in the headphones. So it should be much more there should be much less frequencies in the output. And you can check the CPU load how much does it take to compute such filters.