Recursive RMS (STM32 Implementation) - Phil's Lab

Поділитися
Вставка
  • Опубліковано 6 вер 2024

КОМЕНТАРІ • 39

  • @aleksievnikolay
    @aleksievnikolay Рік тому +20

    @Phil, great video and great channel! I believe you have off by one error in your C implementation. You want to subtract X(n-L), but you are subtracting X(n-L+1). The result of this is that you have running sum of the last L-1 elements instead of L elements. Another small potential issue you may have is accumulating floating point precision error over time. I would probably keep the running sum and ring buffer integer and convert to float only the result.

    • @PhilsLab
      @PhilsLab  Рік тому +12

      Thank you, Nikolay - you're completely right. I've pinned your comment, so people can see the error in the code. As stated in my previous pinned comment, thankfully, for large L (as is the case in the video), the error is small (due to summing 2047 samples, diving by 2048).
      Good point also regarding floating points.

    • @EduardoBehr
      @EduardoBehr 10 місяців тому

      So in essence, for anyone reading this in the future, just save the n-L sample in a temporary variable before overwriting it with the square of the current sample:
      ...
      float n_minus_L = mrms->in_sq_L[mrms->count];
      mrms->in_sq_L[mrms->count] = in_sq;
      ...
      mrms->out_sq += mrms->invL * (in_sq - n_minus_L);
      ...

    • @riyazkureshi8113
      @riyazkureshi8113 10 днів тому

      Exactly ​@@EduardoBehr

  • @Ferreira019760
    @Ferreira019760 Рік тому +9

    Another very interesting video. I need someone like you to teach me more on physics.

    • @PhilsLab
      @PhilsLab  Рік тому +4

      Thank you, Alexandre!

  • @typedef_
    @typedef_ Рік тому +8

    fun fact the RMS of a sine wave is equal to its amplitude multiplied by sin(45) or cos(45)

    • @timovandrey
      @timovandrey Рік тому

      Yeah but for arbitrary waveforms this wont help unfortunately

  • @odissey2
    @odissey2 Рік тому

    The lowest useful frequency will be: (ADC sampling rate) / (filter length) = 48kHz / 2048 ~ 23Hz.
    The highest useful frequency shall depend on the "crest factor" of the signal, that is highest harmonic detected. In case of the pure sine: 48kHz / 2 = 24kHz

  • @teddyjamilonatefreire8797
    @teddyjamilonatefreire8797 Рік тому +5

    Stunning and neat video! I would like some internship with you to learn more about this topics 😢

    • @PhilsLab
      @PhilsLab  Рік тому +2

      Thank you, Teddy! I'm afraid I'm not offering internships, due to limited time available... :(

  • @7alfatech860
    @7alfatech860 Рік тому +4

    Thanks for a great video. I see that the STM32 you are using is capable of keeping up with audio frequency waveforms. How high of an input frequency do you think it is capable of analysing reliably? And a side question: what is the reason you prefer hTerm as opposed to the built-in terminal in cubeIDE?

    • @PhilsLab
      @PhilsLab  Рік тому +7

      Thank you! In terms of 'raw sampling', the STM32 has its own ADCs which typically can go up to a few MSPS (according to datasheets) and at a significantly lower bit-depth. The external CODEC I'm using can go up to 192kHz sampling rate.
      What you can actually process using the H7 strongly depends on the algorithm, so it's hard to generalise.
      From past experiences, I'm not too much of a fan of the built-in terminals. Also I like having a single program for that, since I typically use quite a few different IDEs/platforms.

    • @7alfatech860
      @7alfatech860 Рік тому

      @@PhilsLab 👍

    • @odissey2
      @odissey2 Рік тому

      The answer depends on the input signal' "crest factor" and needed accuracy of the result.
      For example, to measure RMS of the sawtooth signal with 8-bit accuracy, one would need about 64 samples per period. So, for example, using 1 MHz ADC will give 1MHz/64=15kHz max!
      You can reach higher frequencies by reducing the number of samples per period, but at the expense of accuracy, and highest harmonic you want to catch. The sawtooth signal is very rich in harmonics, so a high sampling rate is needed. If you expect only a sine and a 2-nd harmonic, then 8 samples per period should suffice.
      There are hardware solutions for signals up to GHz frequencies.

  • @rick_er2481
    @rick_er2481 Рік тому +1

    Great video and congrats on the 100k subscribers

    • @PhilsLab
      @PhilsLab  Рік тому +1

      Thank you very much, Rick!

  • @fir3w4lk3r
    @fir3w4lk3r Рік тому

    Great explanation and implementation!

  • @RBBlackstone
    @RBBlackstone Рік тому

    Awesome! Personally, I think it would be cool/useful to add dBu and dBV values next to the voltage.

  • @jjjj7870
    @jjjj7870 Рік тому +1

    Hi Phil are you planning on making firmware demostration with the FPGA pcie you made? LOVE your contrnt

  • @AK-vx4dy
    @AK-vx4dy Рік тому

    Very nice explanation. I need see more :)

  • @odissey2
    @odissey2 Рік тому

    There is one catch using this technique - it provides RMS value, which is delayed by the (length of the filter) / 2. So the results are not instantaneous.

    • @nezhazahri372
      @nezhazahri372 11 місяців тому

      Why length of the filter / 2 , you just need to pass that initialisation phase and then you get instant result no?

  • @karama300video
    @karama300video Рік тому

    Another fantastic video!

  • @user-uk5ep9hm5k
    @user-uk5ep9hm5k 11 місяців тому

    Excellent

  • @s_i_m_o_n_e_n_g_e_l
    @s_i_m_o_n_e_n_g_e_l Рік тому

    Uhh been waiting for this

  • @sc0or
    @sc0or Рік тому

    Thanks. I wonder is that a part of a digital compressor, sir? I mean is it used in this shape for a coefficient of a signal amplification. or everything can be enveloped into a formula without a preliminary calculation of an RMS value? Unfortunately I don't remember, have you already created a digital compressor for your guitar pedal or not.

  • @danielliden6829
    @danielliden6829 Рік тому

    JLCPCB now offers flex PCBs! How about a video about them :) ?

  • @guruG509
    @guruG509 Рік тому +1

    Still waiting for a dedicated DSP course

  • @vinothn4228
    @vinothn4228 Рік тому

    Greetings sir! Big fan of your work. We need some another platforms for ESP32 like ESP_IDF, ESP 32 jama ....!

  • @darkside924
    @darkside924 Рік тому

    Is the recursive RMS C code available somewhere?

  • @tamaseduard5145
    @tamaseduard5145 Рік тому +2

    👍🙏❤

  • @dimm__
    @dimm__ Рік тому

    theres an audio glitch at 10:28, just wanted to let u know

  • @zaeemahmed8371
    @zaeemahmed8371 3 місяці тому

    Hello Sir, can you share the STM32 project file with us ?
    So we can also experimet on our end!
    Thanks in advance😊

  • @mspeir
    @mspeir Рік тому

    Couldn't you just use the absolute value of the sin wave instead of squaring it?

    • @RemcoStoutjesdijk
      @RemcoStoutjesdijk Рік тому

      no, you need to sum the squares, then only take the square root. The order of operations is not arbitrary here.