0% found this document useful (0 votes)
39 views27 pages

Full Assignment

Uploaded by

Siddharth Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views27 pages

Full Assignment

Uploaded by

Siddharth Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

MATLAB code for Question 2

3 graphs are drawn. First graph is drawn for N from 1 to 10 Second graph is drawn for N from 10 to 50
Third graph is drawn for N from 50 to 150

N = [Link];
theta_1 = 2./N;
theta_2 = 1./N + 100./(N.^2);

figure(1);
plot(N, theta_1, N, theta_2, '.-'), legend('var_est_1', 'var_est_2');

N=[Link];
theta_1 = 2./N;
theta_2 = 1./N + 100./(N.^2);

figure(2);
plot(N, theta_1, N, theta_2, '.-'), legend('var_est_1', 'varest2');

N=[Link];
theta_1 = 2./N;
theta_2 = 1./N + 100./(N.^2);

figure(3);
plot(N, theta_1, N, theta_2, '.-'), legend('varest1', 'varest2');

1
2
Published with MATLAB® R2020a

3
Question-9
Code for finding MMSE if N is given
N = input('Enter the number of observations')

M = 5000
% M denotes number of realizations

mean_theta = 12;
var_theta = 0.011;
% mean_theta is prior mean %
% var_theta is prior variance %

mean_noise = 0;
var_noise = 1;
% mean_noise is noise mean %
% var_noise is noise variance %

theta_real = mean_theta + sqrt(var_theta).*randn(1,M);


noise_real = mean_noise + sqrt(var_noise).*randn(N,M);
% theta_real is M realizations of theta %
% noise_real is M realizations of random vector of noise %

meas = ones(N,M);
for j=1:M
meas(:, j) = theta_real(j) + noise_real(:,j);
end
% meas is set of measurements %

Z_bar = mean(meas, 1);


% Z_bar is sample mean %

ratio = var_theta/(var_theta+(var_noise/N));
theta_estimate = ratio*Z_bar + (1-ratio)*mean_theta;
% theta_estimate is MMSE estimate of theta %

MSE = immse(theta_real, theta_estimate)


% MSE is mean squared error %

Error using input


Cannot call INPUT from EVALC.

Error in ell_705_M (line 4)


N = input('Enter the number of observations')

Published with MATLAB® R2020a

1
Code for plotting MMSE vs no. of measure-
ments
% No. of measurements i.e. N is varied from 1 to 1000

M = 5000
% M denotes number of realizations
MSE_arr = ones(1000, 1);

for N=1:1000

mean_theta = 12;
var_theta = 0.011;
% mean_theta is prior mean %
% var_theta is prior variance %

mean_noise = 0;
var_noise = 1;
% mean_noise is noise mean %
% var_noise is noise variance %

theta_real = mean_theta + sqrt(var_theta).*randn(1,M);


noise_real = mean_noise + sqrt(var_noise).*randn(N,M);
% theta_real is M realizations of theta %
% noise_real is M realizations of random vector of noise %

meas = ones(N,M);
for j=1:M
meas(:, j) = theta_real(j) + noise_real(:,j);
end
% meas is set of measurements %

Z_bar = mean(meas, 1);


% Z_bar is sample mean %

ratio = var_theta/(var_theta+(var_noise/N));
theta_estimate = ratio*Z_bar + (1-ratio)*mean_theta;
% theta_estimate is MMSE estimate of theta %

MSE = immse(theta_real, theta_estimate);


% MSE is mean squared error %

MSE_arr(N) = MSE;
end

range = 1:1000;
plot(range, MSE_arr, '.-'), legend ('Mean Squared Error')

M =

1
5000

Published with MATLAB® R2020a

You might also like