Recursive RMS (STM32 Implementation) - Phil's Lab

  Рет қаралды 18,052

Phil’s Lab

Phil’s Lab

Күн бұрын

Real-time, software implementation of a recursive moving root mean square filter/estimator. Including basic theory, derivation, C code, and tests. PCBs by PCBWay www.pcbway.com
[SUPPORT]
Free trial of Altium Designer: www.altium.com/yt/philslab
Patreon: / phils94
Mixed-signal hardware design course: phils-lab-shop.fedevel.education
Advanced Hardware Design Course Survey:
forms.gle/X4jwvtZeJ1jTXh7r9
[GIT]
github.com/pms67
[SOCIAL]
Instagram: / philslabyt
[TIMESTAMPS]
00:00 Introduction
00:13 Demo DSP PCB
00:43 PCBWay
00:56 Altium Designer Free Trial
01:23 What We'll Cover
01:44 Why RMS?
03:01 RMS Basics
03:35 RMS Demo
05:51 Discrete-Time Moving RMS
08:01 Recursive DT Moving RMS
09:52 MATLAB Demo (Window Length)
12:38 C Header File (Implementation)
14:28 C Source File (Implementation)
16:05 main.c (Implementation)
17:37 Test Set-Up
18:12 Real-Time Test
20:51 Outro

Пікірлер: 38
@aleksievnikolay
@aleksievnikolay Жыл бұрын
@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 Жыл бұрын
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 7 ай бұрын
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); ...
@Ferreira019760
@Ferreira019760 Жыл бұрын
Another very interesting video. I need someone like you to teach me more on physics.
@PhilsLab
@PhilsLab Жыл бұрын
Thank you, Alexandre!
@typedef_
@typedef_ Жыл бұрын
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
@AK-vx4dy
@AK-vx4dy Жыл бұрын
Very nice explanation. I need see more :)
@rick_er2481
@rick_er2481 Жыл бұрын
Great video and congrats on the 100k subscribers
@PhilsLab
@PhilsLab Жыл бұрын
Thank you very much, Rick!
@fir3w4lk3r
@fir3w4lk3r Жыл бұрын
Great explanation and implementation!
@PhilsLab
@PhilsLab Жыл бұрын
Thank you!
@karama300video
@karama300video Жыл бұрын
Another fantastic video!
@PhilsLab
@PhilsLab Жыл бұрын
Thank you!
@odissey2
@odissey2 11 ай бұрын
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 Жыл бұрын
Stunning and neat video! I would like some internship with you to learn more about this topics 😢
@PhilsLab
@PhilsLab Жыл бұрын
Thank you, Teddy! I'm afraid I'm not offering internships, due to limited time available... :(
@7alfatech860
@7alfatech860 Жыл бұрын
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 Жыл бұрын
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 11 ай бұрын
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.
@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
@user-uk5ep9hm5k
@user-uk5ep9hm5k 8 ай бұрын
Excellent
@PhilsLab
@PhilsLab 7 ай бұрын
Thank you!
@RBBlackstone
@RBBlackstone Жыл бұрын
Awesome! Personally, I think it would be cool/useful to add dBu and dBV values next to the voltage.
@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.
@jjjj7870
@jjjj7870 Жыл бұрын
Hi Phil are you planning on making firmware demostration with the FPGA pcie you made? LOVE your contrnt
@guruG509
@guruG509 Жыл бұрын
Still waiting for a dedicated DSP course
@odissey2
@odissey2 11 ай бұрын
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 7 ай бұрын
Why length of the filter / 2 , you just need to pass that initialisation phase and then you get instant result no?
@danielliden6829
@danielliden6829 Жыл бұрын
JLCPCB now offers flex PCBs! How about a video about them :) ?
@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?
@dimm__
@dimm__ Жыл бұрын
theres an audio glitch at 10:28, just wanted to let u know
@zaeemahmed8371
@zaeemahmed8371 15 күн бұрын
Hello Sir, can you share the STM32 project file with us ? So we can also experimet on our end! Thanks in advance😊
@tamaseduard5145
@tamaseduard5145 Жыл бұрын
👍🙏❤
@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.
USB-C Power Delivery Hardware Design - Phil's Lab #104
29:52
Phil’s Lab
Рет қаралды 91 М.
STM32 Oscilloscope
0:39
kortex
Рет қаралды 14 М.
Black Magic 🪄 by Petkit Pura Max #cat #cats
00:38
Sonyakisa8 TT
Рет қаралды 30 МЛН
Шокирующая Речь Выпускника 😳📽️@CarrolltonTexas
00:43
Глеб Рандалайнен
Рет қаралды 9 МЛН
How I Made this Electric Car that can go Anywhere
8:37
DD ElectroTech
Рет қаралды 14 МЛН
The Simplest Digital Filter (STM32 Implementation) - Phil's Lab #92
23:31
Z-Transform - Practical Applications - Phil's Lab #27
26:02
Phil’s Lab
Рет қаралды 50 М.
STM32 Fast Fourier Transform (CMSIS DSP FFT) - Phil's Lab #111
20:12
USB Headphone Amplifier Design Walkthrough - Phil's Lab #101
33:55
Phil’s Lab
Рет қаралды 32 М.
Making A Billion-Year Lego Clock
13:11
Brick Technology
Рет қаралды 7 МЛН
COPPER PIPE MADE INTO A STUDIO DELAY THAT RUNS AT THE SPEED OF SOUND
11:50
LOOK MUM NO COMPUTER
Рет қаралды 119 М.
Обзор игрового компьютера Макса 2в1
23:34
Apple watch hidden camera
0:34
_vector_
Рет қаралды 52 МЛН