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

3 Ansichten (letzte 30 Tage)
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 Kommentare
Kalasagarreddi Kottakota
Kalasagarreddi Kottakota am 30 Nov. 2022
Sorry its a mistake, I am looking for to calculate sliding mean square error between two signals.

Melden Sie sich an, um zu kommentieren.

Antworten (2)

Bruno Luong
Bruno Luong am 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'))
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 am 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

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by