필터 지우기
필터 지우기

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

조회 수: 1 (최근 30일)
%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))

답변 (1개)

Chris
Chris 2022년 1월 21일
편집: Chris 2022년 1월 21일
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
mhamad Yaacoub
mhamad Yaacoub 2022년 1월 21일
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?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Bartlett에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by