Is there any matlab function to calculate moving mean square error?

6 visualizaciones (últimos 30 días)
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 comentarios
Jonas
Jonas el 30 de Nov. de 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?
Kalasagarreddi Kottakota
Kalasagarreddi Kottakota el 30 de Nov. de 2022
Sorry its a mistake, I am looking for to calculate sliding mean square error between two signals.

Iniciar sesión para comentar.

Respuestas (2)

Bruno Luong
Bruno Luong el 30 de Nov. de 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'))
RMS = 1×991
1.1971 1.2146 1.1593 1.0481 1.0444 1.0172 1.0472 1.0975 1.0711 0.9866 1.0295 0.9773 0.9768 1.0108 1.3782 1.3756 1.3565 1.7685 1.8392 1.8426 1.8149 1.8150 1.9150 1.8936 1.6972 1.7878 1.6632 1.1701 1.1023 1.0704

Mathieu NOE
Mathieu NOE el 30 de Nov. de 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

Categorías

Más información sobre Programming en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by