How to find the RMSE?
11 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I have the following code:
clear;clc
ula = phased.ULA('NumElements',10,'ElementSpacing',0.5);
angs = [40 -20 20; 0 0 0];% angs=[azimuth; elevation]; My desired angles are 40, -20 and 20.
NumSignals = size(angs,2);
c = physconst('LightSpeed');
fc = 300e6; % Operating frequency
lambda = c/fc;
pos = getElementPosition(ula)/lambda;
Nsamp = 1000;
nPower = 0.01;
rs = rng(2007);
signal = sensorsig(pos,Nsamp,angs,nPower);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% MUSIC Algorithm
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
musicspatialspect = phased.MUSICEstimator('SensorArray',ula,...
'OperatingFrequency',fc,'ScanAngles',-90:90,...
'DOAOutputPort',true,'NumSignalsSource','Property','NumSignals',NumSignals);
[~,ang] = musicspatialspect(signal)
ymusic = musicspatialspect(signal);
helperPlotDOASpectra(musicspatialspect.ScanAngles,ymusic)% Changed by Me
function helperPlotDOASpectra(x2,y2)% Changed by Me
% Plot spectra in dB normalized to 0 dB at the peak
y2_dB = 20*log10(y2) - max(20*log10(y2));
plot(x2,y2_dB)
xlabel('Broadside Angle (degrees)');
ylabel('Power (dB)');
title('DOA Spatial Spectra')
end
This estimates the angles and displays them in the command window. It also gives me the plot. Now I want to find the RMSE plot i.e., the root mean square error vs number of runs plot , where number of runs=100. The RMSE is between the actual angles i.e., 40 -20 20 assigend to "angs" and the estimated angles in variable "ang". But I don't know how to do it?
0 comentarios
Respuestas (2)
aditi bagora
el 8 de En. de 2025
To calculate the RMSE between the values of 'angs' and 'ang' over multiple runs, you can store the RMSE values in an array for each run and then you can plot these errors against the run number using the 'plot' function
Please find the sample code attached below:
num_runs = 100;
rmse_values = zeros(1, num_runs);
for idx = 1:num_runs
error = angs - ang;
rmse = sqrt(mean(error.^2));
rmse_values(idx) = rmse;
end
figure;
plot(1:num_runs, rmse_values, '-o');
xlabel('Run Number');
ylabel('RMSE');
title('RMSE vs Number of Runs');
grid on;
Hope this helps!
6 comentarios
Torsten
el 20 de En. de 2025
Editada: Torsten
el 20 de En. de 2025
I don't understand what you are doing.
Technically, "angs" is 2x2, "ang" is 1x2 and thus "rmse" is 1x2. You can't save a vector in a scalar component, thus
rmse_values(idx) = rmse;
throws an error.
But the complete loop
for idx = 1:num_runs
error = angs - ang;
rmse = sqrt(mean(error.^2));
rmse_values(idx) = rmse;
end
doesn't make sense because you compute the same thing "num_runs" times (you only have data for num_runs = 1 times).
And don't call a variable "rmse" - you overwrite the MATLAB function with the same name:
Ver también
Categorías
Más información sobre Digital Filtering en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!