LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

RMS Calc for 1ms windows with overlap

Solved!
Go to solution

Hello everyone

 

I need to do some calculations in a sinusoidal signal with 43kHZ, 200000 samples per second and 20000 samples.

For 1ms i have 200 samples and a overlap maximum of 50% so i develop two types of vi (based on other threads of community) but none of them have the desired behaviour.

 

In Teste Calculo RMS_teste.vi i have a method with calculation of RMS based on # of samples calculated for my desired integration time, but i can't do it with a overlap calculation.

 

In Teste CalculoRMS ARRAYS.vi i have a method with sampling a window and calc the RMS based on # of samples excluded with the window, but i need to do that calculation for various windows with the overlap set to the maximum of 50% of the values.

 

Someone have an idea how i can upgrade this VIs to my purpose?

 

Thanks in advance.

André Simões
Work with LV2019 and cRIO since 2021
Download All
0 Kudos
Message 1 of 9
(1,316 Views)

Hi Simon,

 


@Simon_A wrote:

In Teste Calculo RMS_teste.vi i have a method with calculation of RMS based on # of samples calculated for my desired integration time, but i can't do it with a overlap calculation.


  • Why don't you cleanup the block diagram?
  • Why is there a glaring race condition because of that single local variable?
  • Why is that inner FOR loop set to iterate by the iterator of the outer WHILE loop?
  • Why do you need to convert from DDT to an 1D array twice?
  • Why are some indicators set to EXT datatype, while showing a coercion dot?
  • Why do you need to calculate RMS twice?
  • Why do you calculate the RMS in the FOR loop using a PtByPt function?
  • Why is the "initialize 2" button inside the FOR loop? How do you determine the exact iteration of that FOR loop when you want to initialize that PtByPt function?
  • Why do you use only the last value of the FOR loop output? What's the sense of using a loop at all, when you only use the last value???
  • Why does the VI run as fast as possible, burning (atleast) a CPU core?

@Simon_A wrote:

In Teste CalculoRMS ARRAYS.vi i have a method with sampling a window and calc the RMS based on # of samples excluded with the window,


Here several items apply again:

Why use the FXP datatype?

Why convert twice from DDT to 1D array?

Why are WindowStep/Length of DBL datatype when you want to handle integer samples/elements of the array?

 

Did you debug your VIs using probes and highlight execution?

 


@Simon_A wrote:

For 1ms i have 200 samples and a overlap maximum of 50% so i develop two types of vi (based on other threads of community)


Where do you applay that "50% overlap" in your VIs? There is no control/constant labelled similarly and no comment pointing to this requirement!?

Does that overlap apply in total or "50%" on both sides of your sliding window?

Why don't you simply apply the ArraySubset function on each 300 (or 400) samples of your array?

 

(Explanation: All those "Why…?" questions are intended to point you on parts of your code that needs to be improved. I tend to point people on (potentially) code errors instead of presenting a solution for free: this way most will easier/faster learn to write better LabVIEW code. So please don't take all those question as an offense, but as suggestions for improvement…)

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 9
(1,298 Views)

Hello GerdW

 


@GerdW  escreveu:

 

(Explanation: All those "Why…?" questions are intended to point you on parts of your code that needs to be improved. I tend to point people on (potentially) code errors instead of presenting a solution for free: this way most will easier/faster learn to write better LabVIEW code. So please don't take all those question as an offense, but as suggestions for improvement…)

 

I appreciate your aproach and i'm compleatly cool with that. When i post something here is to think with some help and go through a solution with that. So i'm 100% with your approach.

 

  • Why don't you cleanup the block diagram?

     A: My mistake, i think that in simple test programs it is possible to read the block diagram easy.

 

  • Why is there a glaring race condition because of that single local variable?

     A: What do you mean with "glaring race condition"? I want that # of samples actualize if i change the integration time.

 

  • Why is that inner FOR loop set to iterate by the iterator of the outer WHILE loop?

     A: This isn't mandatory, but i only put that to execute the for entil end of the while loop, because the change in integration time in the mid of          running

 

  • Why do you need to convert from DDT to an 1D array twice?

     A: Here i only want to test the difference between de RMS calculation with RMS VI and RMS PtbyPt VI.

 

  • Why are some indicators set to EXT datatype, while showing a coercion dot?

     A: Honestly here i don't have idea why.

 

  • Why do you need to calculate RMS twice?

     A: Only for test VIs because i think with RMS PtbyPt i can achive more easily the change in the integration time.

 

  • Why do you calculate the RMS in the FOR loop using a PtByPt function?

     A: Because i think with PtByPt function i can change integration time and consequently change the # of samples in the sample length in of the      VI.

 

  • Why is the "initialize 2" button inside the FOR loop? How do you determine the exact iteration of that FOR loop when you want to initialize that PtByPt function?

     A: Maybe i need to put it out of for loop. My itention is to initialize when i change integration time.

 

  • Why do you use only the last value of the FOR loop output? What's the sense of using a loop at all, when you only use the last value???

     A: I think that PtByPt function need to run a for loop to calculate the RMS value of defined number of samples set by integration time. Am I            wrong in that interpretation?

 

  • Why does the VI run as fast as possible, burning (atleast) a CPU core?

     A: Ok, maybe i can put a wait function here to set a wait time.

 

 

Why use the FXP datatype?

A: Only because it is the output of signal generator.

 

Why convert twice from DDT to 1D array?

A: Only for test the difference between two VIs.

 

Why are WindowStep/Length of DBL datatype when you want to handle integer samples/elements of the array?

A: Ok, my mistake here. I need to correct this.

 

Did you debug your VIs using probes and highlight execution?

A: Yes, always.

 

Where do you applay that "50% overlap" in your VIs?

A: In this VI i don't have this overlap yet. My idea is the Window and the step define different sets of values which are calculated by the RMS VI and output the different values of RMS for different values of integration time (and number of samples).

 

There is no control/constant labelled similarly and no comment pointing to this requirement!?

A: Not yet.

 

Does that overlap apply in total or "50%" on both sides of your sliding window?

A: The goal is to put that in the two sides of window and the window moves in time (25% per side of window max). My idea is to have various windows in my set of data calculating each set of 200 samples (1ms integration time) with maximum limit of 50% of data overlaped (100 samples, 50 each side of window).

 

Why don't you simply apply the ArraySubset function on each 300 (or 400) samples of your array?

A: Maybe it's a better option, i will try.

 

The goal here is to acquire a large number of data in a train test, that data is writed in a TDMS file and then i will run that TDMS in a program where filtered and calculate the RMS with this requisits.

I will work in that VI's and made some changes with your inputs and i will comeback to you, but if you have more inputs to me i will apreciate.

 

Thank you so much.





André Simões
Work with LV2019 and cRIO since 2021
0 Kudos
Message 3 of 9
(1,276 Views)

Hello GerdW

 

I've made some changes in the VI for calculation the # of samples and to change it in the PtByPt function. But i have some doubts. The PtByPt VI, the RMS VI and the Amplitude and Level Measurements for RMS calculation have all the same value for RMS, but in the case of PtByPt i only have the calculation with # of samples (in that case 200) in the others i have 20000 samples. Why that value is the same in both VIs?

 

Now i'm going to correct and improve more to share with you.

André Simões
Work with LV2019 and cRIO since 2021
0 Kudos
Message 4 of 9
(1,246 Views)

Hi André,

 

what's the point of placing another loop around the calculation of "#samples"?

Why do you still use a local variable of "#samples"? Why not use a simple wire to "OBEY DATAFLOW!"?

 

Do you really need a bandpass filter for 43kHz±0.15kHz?

Your simulated signal only comes with a Fs of 1kHz so you clearly miss the Nyquist criterion, when you want to create a 43kHz sine wave!!!

 

See this as inspiration:

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 5 of 9
(1,212 Views)

@GerdW  escreveu:

Hi André,

 

what's the point of placing another loop around the calculation of "#samples"?

Why do you still use a local variable of "#samples"? Why not use a simple wire to "OBEY DATAFLOW!"?

 

Do you really need a bandpass filter for 43kHz±0.15kHz?

Your simulated signal only comes with a Fs of 1kHz so you clearly miss the Nyquist criterion, when you want to create a 43kHz sine wave!!!

 

See this as inspiration:


Hi GerdW 

 

I really need that filter, it is a imposition of european criteria for that calculation.

In concern of frequency of signal, i dont know why, when i save the vi, close and open again, the old values are reseted.

 

In other way i'm doing progress in the ARRAYS Calculation with overlap. Can you see and comment the new attached VI? Maybe it's near of purpose that i want, but know i'm stucked with doing that programatically and don't doing that with a million steps of blocks for splitting, deleting and Insert into arrays.

 

I appreciate very much your help and your time with that!

André Simões
Work with LV2019 and cRIO since 2021
0 Kudos
Message 6 of 9
(1,197 Views)
Solution
Accepted by topic author Simon_A

HI André,

 


@Simon_A wrote:
Can you see and comment the new attached VI? Maybe it's near of purpose that i want, but know i'm stucked with doing that programatically and don't doing that with a million steps of blocks for splitting, deleting and Insert into arrays.

Well, whatever you define as "near"! 😄

 

  • Why do you use DeleteFromArray when you want to get a subset of an array? Why not use ArraySubset?
  • Why do you use InsertIntoArray when you want to build an array? Why not use BuildArray?
  • Why do you duplicate code when you want to repeat an operation? Why not use a loop to repeat some code???

See this for inspiration:

For all those array operations: I still don't see how that fits to your requirement of getting "overlapping subsets" of your array. You only use those "samples to retire"…

Can you describe the requirement with some pseudocode?

 


@Simon_A wrote:
In concern of frequency of signal, i dont know why, when i save the vi, close and open again, the old values are reseted.

When you want to set default values then you need to set default values!

Either right-click each control and use the context menu - or use the Edit menu to set all control values at once…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 7 of 9
(1,182 Views)

Hello GerdW

 

  • Why do you use DeleteFromArray when you want to get a subset of an array? Why not use ArraySubset?

     A: Well, i don't use ArraySubset because i want to throw away the first data that are out of overlap limit. For example, i'm building parts of arrays set up with at least 200 samples, when i go to the next 200 samples i need to have the 0% to 50% overlaped data plus the new set of 50% to 100% of the remaining elements in the original array, so i found easier to delete the data that i used in previous calculations.

 

  • Why do you use InsertIntoArray when you want to build an array? Why not use BuildArray?

     A: Because i want to have 0% to 50% data of the previous array and 50% to 50% of the values in the new array. Basically i'm trying to do something like windows set by 200 samples which can be overlaped from 0% to 50% of the last values in the older array.

 

  • Why do you duplicate code when you want to repeat an operation? Why not use a loop to repeat some code???

     A: I need to do that, but i don't wonder how i can do it... I resume the code to six final values of RMS, but in the total i will have something like 150 or 200 sub arrays to calculate the RMS, depending on the overlaped setted up at the begining. Your image is clear and i'm sure that the fore cycle could help me. Tomorrow i will test it and get back to you with some news.

 

Thanks a lot for your help and your patience.

André Simões
Work with LV2019 and cRIO since 2021
0 Kudos
Message 8 of 9
(1,167 Views)

Hello GerdW

 

I was working on the code you sent to me and i noticed that the build array in connections needed to be changed. Otherwise i'm putting the first values of overlap in the end of the array i think.

 

Simon_A_0-1650638476354.png

I build a very simple VI attached here to debug that. Do you agree with that?

 

Although if i change that two connections, if i was reading 200000 samples per second, 20000 samples and arrays of 200 samples, the value of RMS is always the same and i don't have any clue why... (I think possible is for simulated waveforme that throw away the exact same values every period of 1ms).

 

André Simões
Work with LV2019 and cRIO since 2021
0 Kudos
Message 9 of 9
(1,126 Views)