Is there any matlab function to calculate moving mean square error?
6 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I am looking for a way to calculate mean square error for every 'n' sample in a signal of length N (total number of samples)
2 commentaires
Jonas
le 30 Nov 2022
please make clear: do you calculate the least square line once and first and then you want the sliding window of mean error per n sample
OR
do you take a window of n samples, calculate least square line and want to measure the error of that part?
Réponses (2)
Bruno Luong
le 30 Nov 2022
Assuming you have 2 signals S1 and S2 in 1 x N arrays:
N = 1000;
S1 = randn(1,N);
S2 = randn(1,N);
n = 10;
dS = S1 - S2;
RMS = sqrt(conv(dS.^2, ones(1,n)/n, 'valid'))
0 commentaires
Mathieu NOE
le 30 Nov 2022
hello
I doubt that there is a code for that
try this :
(based on formula) :

% dummy data
n=300;
x=linspace(0,2*pi,n);
f = cos(x) + 0.1*randn(1,n); % values of the model
y = smoothdata(f,'gaussian',30); % actual data
buffer = 10; % nb of samples in one buffer (buffer size)
overlap = 9; % overlap expressed in samples
%%%% main loop %%%%
m = length(f);
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);
time_index(ci) = round((start_index+stop_index)/2); % time index expressed as sample unit (dt = 1 in this simulation)
mse(ci) = my_mse(f(start_index:stop_index) - y(start_index:stop_index)); %
end
xx = x(time_index); % new x axis
figure(1),
plot(x,f,xx,mse,'r*');
figure(1),
plot(x,f,'k',x,y,'b',xx,mse,'r');
legend('f data','y data','MSE');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function x_mse = my_mse(x)
x_mse = mean(x.^2);
end
0 commentaires
Voir également
Catégories
En savoir plus sur Matrices and Arrays 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!