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

Поделиться
HTML-код
  • Опубликовано: 3 дек 2024
  • НаукаНаука

Комментарии • 74

  • @PhilsLab
    @PhilsLab  Год назад +15

    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 Год назад +1

      I was looking to find if any one noted that...but your pined comments break my research loop!!

    • @isaacclark9825
      @isaacclark9825 Год назад +1

      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 Год назад +1

      @@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 Год назад +1

      Curious to know why you didn't add CMSIS DSP using the CubeIDE MX Software Pack manager?

    • @acidangel162
      @acidangel162 7 месяцев назад +2

      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 Год назад +1

    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.

  • @yedidiaovadia407
    @yedidiaovadia407 4 месяца назад +1

    Great Video! Best explanation for adding the CMSIS DSP library!

  • @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!

  • @ianthehunter3532
    @ianthehunter3532 Год назад +3

    Wish to understand this some day, great work.

  • @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!

  • @garlicdogg_dev
    @garlicdogg_dev Месяц назад

    Thanks a lot. Very clear expalanation!

  • @senceryazici
    @senceryazici Год назад +6

    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?

  • @fagnereng
    @fagnereng Год назад +2

    Please, make a video implementing the fft algorithm from scratch as you suggested on this video. We would appreciate it! Congratulations for this video.

  • @imoldovan
    @imoldovan Год назад

    Getting closer to using this for receiving rf... :)

  • @severingetzner8211
    @severingetzner8211 Год назад +2

    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.

  • @MeeBilt
    @MeeBilt Год назад +1

    Great video as always!

  • @ahmedkamil7655
    @ahmedkamil7655 Год назад +1

    Excellent work

  • @pcbden
    @pcbden Год назад +2

    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  Год назад +3

      Thanks for watching. You need to include the imaginary & real part in the calculation of magnitude.

  • @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.

  • @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 Год назад +1

    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 Год назад +3

    Hi Phil. I use STM32 for a while and it has a lot of bennefits agains Arduino. Mostly I learn programming from Digi Key RUclips 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  Год назад +1

      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.

  • @PCBWay
    @PCBWay Год назад

    Always good to hear your thoughts, musing, and recommendations, Phil. :)👍👍👍

    • @PhilsLab
      @PhilsLab  Год назад

      Thank you very much! :)

  • @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?

  • @stickyfox
    @stickyfox Год назад +1

    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.

  • @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?

  • @gretarmark
    @gretarmark Год назад +1

    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?

    • @ΠΑΝΑΓΙΩΤΗΣΞΥΔΙΑΣ
      @ΠΑΝΑΓΙΩΤΗΣΞΥΔΙΑΣ Год назад +1

      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.

  • @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!

  • @marek_ryn
    @marek_ryn Год назад +1

    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  Год назад +1

      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?

  • @frankieodling-smee4018
    @frankieodling-smee4018 15 дней назад

    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!

  • @ΠΑΝΑΓΙΩΤΗΣΞΥΔΙΑΣ

    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  Год назад +2

      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

  • @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.

  • @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).

  • @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.

  • @chaiboonchuai6515
    @chaiboonchuai6515 18 часов назад

    stm32 FFT Can meassure up to 400 KHz ?

  • @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

  • @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  Год назад +3

      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 :)

  • @camk2552
    @camk2552 Год назад

    Great Videos on DSP thanks!

  • @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  Год назад +1

      Thanks, good idea! I haven't used it at all myself to be honest, but will give it a try for a future video.

  • @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  Год назад +1

      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

  • @Εὐκλείδης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).

  • @dharmasastha8632
    @dharmasastha8632 5 месяцев назад

    Can you send source code?

  • @luanphamng
    @luanphamng Год назад

    What're you doing for living?