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):
I would like to understand how envelope
determines the first samples.