why the plot doesn't work ,in the code i'm finding the estimation value of the phase using montecarlo simulation

1 visualización (últimos 30 días)
%phase astimation using monte carlo
clear all
close all
clc
%signal model x(n)=Acos(2pif0n+thetha)+w(n)
phase=0.75;
A=1;
sigma=0.1;
f0=0.035;
SNR=A^2/2*(sigma^2)
SNR = 0.0050
for m=1:length(SNR)
M=5;
for i=1:M;
s=A*cos(2*pi*f0*i+phase);
w=randn(size(s));
x(i)=s+sigma*w
y1=sum(x*sin(2*pi*f0*i))
y2=sum(x*cos(2*pi*f0*i))
phasehat(i)=-atan(y1+y2)
%
% mat(i,:)=phasehat
end
%compute bias
b(m)=(1/M)*sum(mean(phasehat(i))-phase)
%mean square error
mse=mean((phasehat(i)-phase)^2)
var=1/M*SNR
end
x = 0.7006
y1 = 0.1528
y2 = 0.6837
phasehat = -0.6966
x = 1×2
0.7006 0.4581
y1 = 0.4933
y2 = 1.0484
phasehat = 1×2
-0.6966 -0.9954
x = 1×3
0.7006 0.4581 0.4058
y1 = 0.9588
y2 = 1.2361
phasehat = 1×3
-0.6966 -0.9954 -1.1433
x = 1×4
0.7006 0.4581 0.4058 0.0162
y1 = 1.2178
y2 = 1.0075
phasehat = 1×4
-0.6966 -0.9954 -1.1433 -1.1485
x = 1×5
0.7006 0.4581 0.4058 0.0162 -0.1706
y1 = 1.2563
y2 = 0.6401
phasehat = 1×5
-0.6966 -0.9954 -1.1433 -1.1485 -1.0855
b = -0.3671
mse = 3.3692
var = 1.0000e-03
figure(1)
plot(10*log(SNR),b)
figure(2)
plot(10*log(SNR),mse)
figure(3)
plot(10*log(SNR),10*log(var))

Respuestas (1)

Chris
Chris el 21 de En. de 2022
Editada: Chris el 21 de En. de 2022
since length(SNR) is 1, you are running one loop iteration and generating one point. plot() doesn't show one point unless you specify a marker:
figure(1)
plot(10*log(SNR),b,'o')
figure(2)
plot(10*log(SNR),mse,'x')
figure(3)
plot(10*log(SNR),10*log(var),'^')
or equivalently, use scatter:
figure(1)
scatter(10*log(SNR),b)
% ...etc
  4 comentarios
mhamad Yaacoub
mhamad Yaacoub el 21 de En. de 2022
Thank you a lot! Now i understand why the answers in my program are already wrong sorry i’m begginer in matlab how i can change from scalar to vector?

Iniciar sesión para comentar.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by