2
$\begingroup$

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:

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

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

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

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

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.

$\endgroup$
0
$\begingroup$

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

| improve this answer | |
$\endgroup$

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.