LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How program for-loop to calculate RMS with window length of 100 samples and window step of 1 sample

Solved!
Go to solution

Hi everyone,

 

I am trying to make a switch from Matlab to Labview from my signal processing needs....Specifically, I need to smooth and quantify a randon, biphasic signal of ~128000 samples in length... In matlab I would calculate the RMS with a window length of 100 samples and window step of 1 sample to smooth.linear evelope the signal; then do my amplitude calculations...

 

I am having trouble doing this in Labview.. The matlab code I would normally use is:

 

___________________________________________________________ 

% Assign RMS variables

x= signal of interest;

window_length= 100;

window_step= 1;

 

% RMS calculation

EMG= x.^2;

index= 0;

nwindows= floor(nrows - (window_length - window_step)) / window_step;

EMG_rms = zeros(nwindows,ncols); % Preallocation for memory

 

for j = 1:window_step:length(EMG)-window_length+1;

    index = index+1;

    EMG_rms(index,:) = sqrt(mean(EMG(j:j+window_length-1,:)));

end

________________________________________________________

 

I have tried  numerous times using the for-loop, but no luck... Ingore the smilies... They should be a colon (:, to indicate all rows) followed by a )....

 

Any suggestions??

 

Thanks,

0 Kudos
Message 1 of 21
(8,564 Views)

Can you show us what you have tried so far?

 

It seems to me that you need a for loop with an Array Subset inside of it.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 2 of 21
(8,553 Views)

Hi jcannon,

 

Here is a link with an example on for loops which should get you familiar enough with them to be able to achieve what you need.

 

https://decibel.ni.com/content/docs/DOC-20828

 

DylanC

0 Kudos
Message 3 of 21
(8,528 Views)

Hi jcannon,

 

there's a ready-to-use function that should do what you need...

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 4 of 21
(8,525 Views)

@GerdW wrote:

Hi jcannon,

 

there's a ready-to-use function that should do what you need...


To be more exact, you need the RMS PtByPt VI.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 5 of 21
(8,522 Views)

Hi everyone,

 

Thanks for your feedback with this and the link the the functions...I am ok wth calculating the RMS, my problem is wiring the interation and/or "N" count of the for-loop the get the appropriate sub-array for each signal segment be analysed.

 

For example, let's say I have a signal that is  5000 samples in length and I want to calculate the RMS for consective windows that are 100 samples long and have the window step of 1 sample each time fr thr total ength of the signal (i.e. smooth it). In this situation the total number of interations for the for-loop runs would be calculated as:

 

runs= floor(signal_length - (window_length- window_step)) / window_step;

runs= floor(5000-(100-1))/1

runs= 4901.

 

So, I would the for-loop to run 4901 times (and ingnore the remaining 99 samples at the end of the signal)... In each loop I would calcuate the RMS of the appropriate 100 sample subarray... But how do I wire the interation count and "N" counter to the subarray so that each interations gets the right subarray for each specific interation?...

 

Thanks,

Jack

0 Kudos
Message 6 of 21
(8,498 Views)

Hi Jack,

 

use the Pt-by-Pt function and you will not need any subarrays...

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 7 of 21
(8,487 Views)
Of course!

Had a late night...

Any ideas about the wiring?

Thanks,
Jack
0 Kudos
Message 8 of 21
(8,478 Views)

Hi Jack,

 

as PtByPt-RMS only has 2 (useful) inputs for your duty wiring is as easy as this:

check.png

But well, one could read the context help to know all this...

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 9 of 21
(8,468 Views)

Hi GerdW,

 

I think you might not be correctly understanding my problem regarding the wiring... I am refering to the wiring of the "N" and/or "I" terminal of the for-loop into the coding inside the loop(?) so that the RMS is calculated for the appropriate segment of the signal in each of the 4901 interations... That is, samples 1-100 for the 1st interation, samples 2-101 for the 2nd interaction, etc, etc, through to samples 4802-4901.

 

I think with the code you have provided, the RMS will only be calculated on the 1st 100 samples of the 5000 sample array...? How to do get the remaining data? I think I will have to use the subarray function with the "N" and/or "I" terminal of the loop wired so that the subarray specs update on each interation to get the new segment of data needed for processing...?

 

Regards,

Jack

0 Kudos
Message 10 of 21
(8,455 Views)