Compute RMS value over 1-second intervals
16 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Trying to get RMS 1s value from a excell file which contains 2 collums of data . collum 1 time and collum 2 is accelaration. I appled Wk filter and code runs fine but now i wanted to Compute RMS value over 1-second intervals but its howing error.
% Compute RMS value over 1-second intervals
windowSize = round(fs); % Number of samples in one second
a_rms = movrms(ac, windowSize); (ERROR in this line)
0 commentaires
Réponses (2)
Mathieu NOE
le 11 Mai 2023
Modifié(e) : Mathieu NOE
le 12 Mai 2023
hello
I am not aware of a matlab function called movrms (but there is a movmean and movsum)
here a code that does the same thing with the possibilty also to add overlap
Edit : improved code
% dummy data
n = 1000;
Fs = 100;
dt = 1/Fs;
t=(0:n-1)*dt;
y = max(0.707,abs(cos(t))+0.1*rand(size(t)));
buffer = Fs; % 1 second buffer
overlap = round(0.5*Fs); % overlap (here 50 % of buffer size)
[t_rms,y_rms] = my_rms(t,y,buffer,overlap);
figure(1),
plot(t,y,t_rms,y_rms,'r-*');
legend('raw data','1 s rms');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [t_rms,x_rms] = my_rms(t,x,buffer,overlap)
%%%% main loop %%%%
m = length(x);
dt = mean(diff(t));
shift = buffer-overlap; % nb of samples between 2 contiguous buffers
for ci=1:fix((m-buffer)/shift +1)
start_index = 1+(ci-1)*shift;
stop_index = min(start_index+ buffer-1,m);
t_rms(ci) = dt*(start_index+stop_index)/2; % time (centered in buffer)
x_rms(ci) = sqrt(mean(x(start_index:stop_index).^2));
end
end
Star Strider
le 12 Mai 2023
Try this —
movrms = @(A,k) sqrt(movmean(A.^2,k));
Fs = 1000;
T = 10;
t = linspace(0, T*Fs, T*Fs+1).';
s = randn(size(t));
srms = movrms(s,round(Fs));
figure
plot(t,s, 'DisplayName','Signal')
hold on
plot(t, srms, '-r', 'DisplayName','RMS')
hold off
grid
legend('Location','best')
s = sin(2*pi*t/10);
srms = movrms(s,round(Fs));
Check = srms([1 end-1000])
figure
plot(t,s, 'DisplayName','Signal')
hold on
plot(t, srms, '-r', 'DisplayName','RMS')
hold off
grid
legend('Location','best')
xlim([0 200])
See the documentation on movmean for details. My ‘movrms’ function can be changed to accommodate other arguments to movmean by changing the ‘movrms’ argument list accordingly.
This gives the correct result, the RMS value of a sine being
.
. .
0 commentaires
Voir également
Catégories
En savoir plus sur Array and Matrix Mathematics dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


