STM32 Fast Fourier Transform (CMSIS DSP FFT) - Phil's Lab

  Рет қаралды 49,875

Phil’s Lab

Phil’s Lab

Күн бұрын

Пікірлер: 73
@PhilsLab
@PhilsLab Жыл бұрын
Note: For a peak detector, you of course don't actually need to compute the square-root of (real^2 + imag^2) (sqrt being fairly processing-heavy). I left it in for the sake of 'completeness'. Also keep in mind there are many things that can be optimised in this example. The main purpose of this video is simply to show how to incorporate CMSIS DSP libraries, and use certain FFT functions.
@negvorsa
@negvorsa Жыл бұрын
I was looking to find if any one noted that...but your pined comments break my research loop!!
@isaacclark9825
@isaacclark9825 Жыл бұрын
I love DSP content! Thanks for sharing. There is a CMSIS function that will calculate the complex magnitude from the FFT output. I understand that a peak detector does not need that optimization but folks who are playing around with the CMSIS libraries might want to give it a try.
@jithin_isaac
@jithin_isaac Жыл бұрын
@@isaacclark9825 Yes we can either use arm_cmplx_mag_f32() for a square-root magnitude or arm_complx_mag_squared_f32() for a non-square root value
@robc3863
@robc3863 Жыл бұрын
Curious to know why you didn't add CMSIS DSP using the CubeIDE MX Software Pack manager?
@acidangel162
@acidangel162 6 ай бұрын
There is another reason why you don't need the square root. You are actually interested in the power of the signal, not the magnitude. This is how CD has 96 dB dynamic range. Every bit gives your 3 dB more amplitude. With CD's 16 bit your amplitude has 48 dB of dynamic range. log10(65536) = 4.8165. But with 48 dB of amplitude you can get 96 dB of signal power. Amplitude tells you the signal voltage but power tells you, well power. To get the audio power you square your amplitude. You never need to calculate the expensive square root. Just use the real^2 + complex^2 and you're good to go. This is not only cheaper to calculate but more accurate. If you took the FFT with let's say 4096 samples, your screen might not have that much resolution. You might want to combine each frequency together so that you have the same resolution of for example a piano keyboard. You need to sum the powers together to get an accurate picture. If you sum the amplitudes the image won't look right but if you sum the powers it does. In the use case of this video of finding the loudest frequency you might want to get the power in logarithmic units. Just take a log10 of the power. You're interested in how loud that frequency is in deciBels, not how high the signal amplitude is. Another reason not to not calculate the square root is that log10(sqrt(power)) = log10(power) / 2. Square root is just an unnecessary in that case too. Dividing by two is much cheaper. I worked on this a couple of years ago. At first I took 2048 square roots and that's expensive. It cost me like 2 milliseconds per frame and I didn't have two milliseconds. Because the accuracy of the square root is not that important I used the fast inverse square root algorithm that was 20 times faster with an error of only 0.07 %. But in the end it turned out that the square root was completely unneeded. I hope this helps or that someone found this at least interesting.
@bobwalance7237
@bobwalance7237 Жыл бұрын
Phil, this is the only place that I could find with proper format of the output of the rFFT. There is a lot of misinformation out there regarding the arm_rfft_fast_f32. Thank you for presenting such an accurate and easy-to-understand description. Also, it's important to note that this function destroys the values in the input buffer, and this is documented at the Keil webpage for the CMSIS-DSP routines.
@euglossine_tristanwhitehill
@euglossine_tristanwhitehill Жыл бұрын
Easily one of the best channels for learning dsp, your precision in teaching is remarkable
@PhilsLab
@PhilsLab Жыл бұрын
Thank you very much!
@yedidiaovadia407
@yedidiaovadia407 4 ай бұрын
Great Video! Best explanation for adding the CMSIS DSP library!
@Jose-tw9bl
@Jose-tw9bl Жыл бұрын
Thanks for this video! The part i found most interesting was how to include and configure the ide to use precompiled libraries. In lots of videos people assume we know how to do it but i had no idea. Thanks!
@fagnereng
@fagnereng Жыл бұрын
Please, make a video implementing the fft algorithm from scratch as you suggested on this video. We would appreciate it! Congratulations for this video.
@ianthehunter3532
@ianthehunter3532 Жыл бұрын
Wish to understand this some day, great work.
@PhilsLab
@PhilsLab Жыл бұрын
Thank you, Ian!
@senceryazici
@senceryazici Жыл бұрын
I just wished we had this awesome video a year ago when we were working on sound source localization using TDOA in a project. ChatGPT + Phil's Lab Videos is a powerhouse combo that equips one with all the tools we need to tackle any challenge haha :D The quality in this channel is unbeatable, as always, Excellent!
@PhilsLab
@PhilsLab Жыл бұрын
Thank you so much, Sencer!
@mausmettwurst7039
@mausmettwurst7039 10 ай бұрын
Hey, I am working on a similar project. Do you have an public repository with your project?
@PCBWay
@PCBWay Жыл бұрын
Always good to hear your thoughts, musing, and recommendations, Phil. :)👍👍👍
@PhilsLab
@PhilsLab Жыл бұрын
Thank you very much! :)
@garlicdogg_dev
@garlicdogg_dev 21 күн бұрын
Thanks a lot. Very clear expalanation!
@ahmedkamil7655
@ahmedkamil7655 Жыл бұрын
Excellent work
@PhilsLab
@PhilsLab Жыл бұрын
Thanks, Ahmed!
@severingetzner8211
@severingetzner8211 Жыл бұрын
I would beg you to upload the code. I am really struggeling to get this DMA working proberly and I can see from you comments in the code that you also tried alot to get it working on the STM32H723. Thank you for all the video uploads.
@marek_ryn
@marek_ryn Жыл бұрын
Excellent video!! Just small optimization: when searching peak frequency in the loop you can omit sqrtf function, as it is very costly. Thank you for all your videos, I learn so much from them!
@PhilsLab
@PhilsLab Жыл бұрын
Thanks, Marek! That's correct - although I left in the sqrt for sake of 'completeness'/'correctness'. Given the rather crude nature of the surrounding implementation and no need for 'speed increase', it doesn't make much of a difference for this example.
@fagnereng
@fagnereng Жыл бұрын
So how could i find the peak frequency without calculate the absolute value from fft output?
@MeeBilt
@MeeBilt Жыл бұрын
Great video as always!
@PhilsLab
@PhilsLab Жыл бұрын
Thank you!
@imoldovan
@imoldovan Жыл бұрын
Getting closer to using this for receiving rf... :)
@theintjengineer
@theintjengineer Жыл бұрын
I have an H757i-Eval Board which is a dual-core board, which makes it difficult when it comes to Tutorials, as most of them are based on single-core boards, meaning I always have the problem of - how to handle the CM4, for instance. What to do with it, start it or not, delegate stuff to it or not and so on. It was a gift, so, I didn't have much of a say. But I'm now thinking of buying a single-core board to educate myself and know enough to know how to appropriately handle the dual-core one.
@pcbden
@pcbden Жыл бұрын
Thank you for your amazing tutorial. If you are interested in only FFT frequency do you have to add imaginary part to calculate value. I think without it you would save some processing time
@PhilsLab
@PhilsLab Жыл бұрын
Thanks for watching. You need to include the imaginary & real part in the calculation of magnitude.
@TheMikeseiler
@TheMikeseiler Ай бұрын
Thanks for the detailed video Phil. I am considering using your example as a basis for a product we are working on. Do you have any idea on what the CPU load was for your example?
@RemcoStoutjesdijk
@RemcoStoutjesdijk Жыл бұрын
You might want to add in the library as source instead.. I went from 95% CPU load to roughly 70% on a cortex-m4 for a customer. It looks like the library as compiled doesn't use any optimizations. Also, it appears to have been compiled with round-as-floor where I could get about 6dB lower noise floor by changing that to round to nearest (if memory serves).
@dmarman
@dmarman 7 ай бұрын
Any chance of an example or guides on how to add the library as source? Just adding the headers files and include paths to the project?
@lucvanhove9639
@lucvanhove9639 Жыл бұрын
Hi Phil. I use STM32 for a while and it has a lot of bennefits agains Arduino. Mostly I learn programming from Digi Key KZbin cours, Controllers Tech and books from Elector. But your movie was the next level and I appreciat it a lot. Where can I find all this study info about the Cube compiler, I mean books or ... Thanks a lot.
@PhilsLab
@PhilsLab Жыл бұрын
Thanks! I'd suggest working on a real-life project and figuring out what you need (Google, Stackoverflow, datasheets, etc..) when the time comes during that project. That approach works the best for me.
@R2AUK
@R2AUK Жыл бұрын
Many thanks for the video. I noticed that you choose CMSIS_4 while CMSIS_5 is available. Is there a reason to prefer the older version?
@dajianghe
@dajianghe Ай бұрын
I use software generated signal. How come calculated peak value is 2 times of the original one? For example, I generated 1024 samples of 50Hz data, with 1024 sampling rate; then I used a STM32 G431 MCU to perform FFT on that data set. The calculated peak frequency is 100Hz. What went wrong?
@stickyfox
@stickyfox Жыл бұрын
Is CubeIDE the current version of the "System Workbench" Eclipse package? Because *that* was a disaster, and why I stopped even trying to use STM32 chips in the first place. The online community was dead and so was the support for the software. I tried using VSCode/PlatformIO but it never installed properly because Cygwin was also on my machine, so I just said forget it. It would be fantastic if they've gotten a real working dev suite that isn't pay-to-play.
@gabrielbortto
@gabrielbortto Жыл бұрын
I'm getting a Hard Fault when the function arm_rfft_fast_init_f32(&fftHandler, FFT_BUFFER_SIZE); gets called. Any ideas? I am using a STM32F411CEU6. I have the FPU set to hard and float.
@coderebel3568
@coderebel3568 Жыл бұрын
Hi Phil! I was wondering how you're finding those tag-connect connectors working for you. I noticed you've used two different versions. In Phil's lab #45 I noticed the Tag-Connect connector doesn't have four large holes around it and here in this design it does. I've seen some of those tag-connect connectors have some plastic legs that seem to be for holding on to the PCB. Is that the reason why you switched? And is there perhaps already a video where you talk about the version you're using here? I'm thinking about a custom design for a DSP board in my guitar with an STM32H7A3 and contemplating using such a tag-connect connector for programming as well.. By the way, I've tried experimenting with an AD1937 audio codec before, but I couldn't get it to work. I don't know what I'm doing wrong. Either it's an EMI issue, or I'm not setting up the PLL correctly or I'm making a software error.. Or I messed up the chip while soldering or something.. I did just get an easy to use MAX98357 on an adafruit breakout board to produce sound using DMA with a Nucleo F401, but for the guitar I'd prefer to use a more powerful codec chip with multiple inputs and outputs. Could you do a video about setting up audio codecs in the general sense, like what do they mean with 256fs and such. I have some idea about what they mean and how to set it up, but with all the assumptions I'm having to make, I think I'm just making too many mistakes and not quite sure how to debug it. I've searched around for some tutorials about that and found nothing, so maybe that's an idea. I like your channel a lot. I've learned so much! Thanks a lot!
@camk2552
@camk2552 Жыл бұрын
Great Videos on DSP thanks!
@PhilsLab
@PhilsLab Жыл бұрын
Thank you!
@gretarmark
@gretarmark Жыл бұрын
This was great! I once implemented an simple peak detector using Arduino to detect the peaks of a sine wave signal. The purpose was to keep the signal at 50Hz, just like the power system. But I didn't think about doing it by using FFT. Do you think it is more benefitial to use FFT to do it rather than just basic math to detect peaks?
@ΠΑΝΑΓΙΩΤΗΣΞΥΔΙΑΣ
@ΠΑΝΑΓΙΩΤΗΣΞΥΔΙΑΣ Жыл бұрын
Hello, i am not Phil but every opinion counts i assume :D I think an envelope detector, if well configured, is better for your purpose than FFT because FFT provides delay depending on the accuracy you need.Also arduino is not as good mcu as stm32 in this case, so FFT would not be that good for this case.
@gretarmark
@gretarmark Жыл бұрын
Hello @@ΠΑΝΑΓΙΩΤΗΣΞΥΔΙΑΣ, thank you for the answer. That's true, STM32 is much better, I had to use atmega328p in a course I took in my study program, otherwise I would have go for something better. But FFT is actually very fast algorithm, it was invented by James Cooley and John Tukey to make fourier calculations as fast as possible. I once heard that FFT is used in ABS braking systems of cars because of its speed and accuracy, so I was just wondering. But it's speed is O(NlogN), which is very good speed.
@shettymalnad1978
@shettymalnad1978 9 ай бұрын
Hello, DSP_CMSIS library limits to 4096 points in my project needs to 16384 point how to achive this ? which library is there to do how to add and and achive any suggestion,links or videos will be very helpfull
@Thats_Mr_Random_Person_to_you
@Thats_Mr_Random_Person_to_you Жыл бұрын
Totally off topic: as Altium also make/own CircuitMaker which is free would be interesring to have an opinion / design example walkthrough (being a tech consultant for Altium I think it does fit heavily into your overall content so its not too off piste if you did think it interesting/worth doing).
@PhilsLab
@PhilsLab Жыл бұрын
Thanks, good idea! I haven't used it at all myself to be honest, but will give it a try for a future video.
@frankieodling-smee4018
@frankieodling-smee4018 6 күн бұрын
Is this project available on your GitHub? I would like to reference this in my final year university project. The assesors are rarely fans of youtube videos being referenced but don't mind project references. Please let me know and thank you for this video!
@Kale514-pt8tg
@Kale514-pt8tg Жыл бұрын
Hi. If I have a 1kHz sinusoidal signal input to the ADC channel, how do I give the SAMPLING_RATE a value in the code? I am not using I2S or SAI1 as in your case. If I am not mistaken, I should set the sampling rate to at least twice the frequency of the input signal, right? Thank you!
@isaacclark9825
@isaacclark9825 3 ай бұрын
You have set your ADC sample to sample at a particular rate. Or you have specified the time between samples. If you have done the latter, the sampling frequency is 1/(time between samples).
@EmbeddedEnigma
@EmbeddedEnigma 4 ай бұрын
what is the formula used on int16_t_to_float directive ?
@isaacclark9825
@isaacclark9825 3 ай бұрын
Multiply the integer values by (1.0/32768). You will want to store that multiplier value as a constant.
@Εὐκλείδης300
@Εὐκλείδης300 Жыл бұрын
Thank you very much, your tutorials are very important! Do you have intention to create DSP programming tutorials for fpga zynq? It would be amazing!
@PhilsLab
@PhilsLab Жыл бұрын
Thanks for watching! Yeah, I wanna make some 'basic' FPGA DSP tutorials first (Spartan 7), before moving over to doing that on the Zynq (although the workflow is of course rather similar).
@ΠΑΝΑΓΙΩΤΗΣΞΥΔΙΑΣ
@ΠΑΝΑΓΙΩΤΗΣΞΥΔΙΑΣ Жыл бұрын
Very nice vid Phil, been always fan of your designs! Do you think this approach differs compared to using the HAL_ADC or HAL_DAC HalfConv/Conv Callbacks in case of standard ADC/DAC DMA streaming (i mean by taking into account the computational time, audio quality etc) ?
@PhilsLab
@PhilsLab Жыл бұрын
Thank you! Audio quality is not really achievable using the STM32's built-in ADCs/DACs. I had tried this a while back, but the ENOB is too low, even with oversampling. For other applications, where you only need 12bits or less, then the internal ADCs/DACs can achieve that. However, the actual FFT implementation as shown in the video can be done in pretty much the same way if you're if using the STM32's 'on-board' ADCs and DACs.
@ΠΑΝΑΓΙΩΤΗΣΞΥΔΙΑΣ
@ΠΑΝΑΓΙΩΤΗΣΞΥΔΙΑΣ Жыл бұрын
@@PhilsLab Thank you for your quick response. I am actually using it that way to minimize components on board (and the complexity of a codec but might go that way though) and being using FFT with a noise level cutoff to achieve a better signal. But i assume the better the signal in the input the better the output
@Ozonised
@Ozonised Жыл бұрын
Where did you learn digital signal processing from? Was it from college or the internet? If it was from the internet then can you point me to some good sources or books?
@PhilsLab
@PhilsLab Жыл бұрын
We had some introductory DSP classes at uni. The rest is pretty much self-taught. Check out: "The Scientist and Engineer's Guide to Digital Signal Processing" (SMITH) and - if you're into audio - "DAFX: Digital Audio Effects" (ZÖLZER).
@Ozonised
@Ozonised Жыл бұрын
​@@PhilsLabThank you Phil :)
@FixDaily
@FixDaily Жыл бұрын
What if you sweep across frequencies, will it detect the highest?
@ChromeExtension
@ChromeExtension Жыл бұрын
Depends on your SWEEP rate + SAMPLING rate + FFT buffer size. This peak frequency detector doesn't detect what is the "highest" frequency but rather what frequency component makes up majority of the input signal. For a sweep, an ideal DFT of the full sweep will result in peaks of all the same magnitude (i.e. all frequency components contribute equally to the input signal) [imagine a column chart with all same heights, from 0 - max sweep frequency]. Assuming the sweep is linear and sampling windows line up. If the sweep doesn't fit within buffer, e.g. like in this video, since it seems to be calculating FFT many times a second, then for each FFT buffer period, it will result in a similar picture to situation above, except starting frequency will not be 0 and ending frequency will not be max sweep either. Basically it will show chunks of column charts based on which part of the sweep it is at/sampled. To implement a highest frequency detector, like what I think you are suggesting, you would need to first determine what threshold or magnitude is considered as being more than NOISE/significant enough. Then just evaluate the FFT buffer in reverse from highest frequency, until you find a bin that exceeds your threshold. To understand more, find some videos about Fourier Transforms, like the one suggested in video, it will clear the confusion about frequency vs magnitude / components
@PhilsLab
@PhilsLab Жыл бұрын
Depends on how fast the sweep is, how long your FFT is, and so on.
@BlueStream123
@BlueStream123 Жыл бұрын
Do you know a cheap alternative to the TAG Connector? Because these connectors cost about 40$...
@PhilsLab
@PhilsLab Жыл бұрын
The initial cost is quite high, yes - but depending on how many boards you have made, assembled, programmed etc. the cost justifies itself quite quickly. Don't know of any alternatives, other than making your own.
@BlueStream123
@BlueStream123 Жыл бұрын
@@PhilsLab Okay thank you. Nice video btw :)
@rjordans
@rjordans Жыл бұрын
There are some pogo pin connector variations that clip onto the board edge. The main constraint with those is that you need to put the connector footprint near the board edge which may not be the most convenient place
@dharmasastha8632
@dharmasastha8632 4 ай бұрын
Can you send source code?
@luanphamng
@luanphamng Жыл бұрын
What're you doing for living?
PCB Traces 101 - Phil's Lab #112
30:19
Phil’s Lab
Рет қаралды 51 М.
Разгоняем PostgreSQL. Личный опыт. (Перезалив)
37:05
Сисадмин Михалыч
Рет қаралды 2,1 М.
FOREVER BUNNY
00:14
Natan por Aí
Рет қаралды 29 МЛН
ТЮРЕМЩИК В БОКСЕ! #shorts
00:58
HARD_MMA
Рет қаралды 2,6 МЛН
ТВОИ РОДИТЕЛИ И ЧЕЛОВЕК ПАУК 😂#shorts
00:59
BATEK_OFFICIAL
Рет қаралды 6 МЛН
Houdini Algorithmic Live #112 - Procedural Plant Growth
3:33:35
Junichiro Horikawa
Рет қаралды 283 М.
3 engineers race to design a PCB in 2 hours | Design Battle
11:50
Predictable Designs
Рет қаралды 427 М.
Understanding the Discrete Fourier Transform and the FFT
19:20
The Magic of RISC-V Vector Processing
16:56
LaurieWired
Рет қаралды 330 М.
[#23] FFT Spectrum Analysis - Audio DSP On STM32 (24 Bit / 48 kHz)
14:33
YetAnotherElectronicsChannel
Рет қаралды 32 М.
TI Precision Labs - ADCs: Fast Fourier Transforms (FFTs) and Windowing
10:47
DSP Overdrive Algorithm in Software (STM32) - Phil's Lab #117
32:52
Plotting the Fourier Transform in Python (DFT/FFT)
10:46
Signal Processing with Paul
Рет қаралды 24 М.