I am trying to understand how does the sliding window works when using the function envelope in MATLAB to calculate RMS (root mean square). I'm using the following code to reproduce the behavior of envelope:

Array = randn(1000,1);
window = 100;
limit = length(Array)-window;

%Part 2
for i=1:limit
    RMS(i) = rms(Array(i:i+window-1));

I expect the part 2 in the code above to generate the same results as:

upper = envelope(Array(1:limit), 100, 'rms');

However the first option (blue line) is displaced about 50 samples compared to the second option (red line):

enter image description here

I would like to understand how envelope determines the first samples.


Since your window is not centered, you receive a shift of half-length of the chosen window.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.