05-18-2012 10:55 PM
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,
Solved! Go to Solution.
05-19-2012 11:36 AM
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.
05-21-2012 09:43 AM
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
05-21-2012 09:58 AM
05-21-2012 10:46 AM
@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.
05-27-2012 08:08 PM
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
05-28-2012 01:45 PM
05-28-2012 06:19 PM
05-29-2012 12:59 AM - edited 05-29-2012 12:59 AM
05-29-2012 09:52 AM
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