Generate the following random sequences and obtain their histogram using the hist function with 100 bins. Use the bar function to plot each histogram.
- x1(n) is a random sequence whose samples are independent and uniformly distributed over [0, 2] interval. Generate 100,000 samples.
- x2(n) is a Gaussian random sequence whose samples are independent with mean 10 and variance 10. Generate 10,000 samples.
- x3(n) = x1(n) + x1(n – 1) where x1(n) is the random sequence given in part 1 above. Comment on the shape of this histogram and explain the shape.
- x4(n) = Σy𝑘(n)4𝑘=1 where each random sequence y𝑘(n) is independent of others with samples uniformly distributed over [-0.5, 0.5]. Comment on the shape of this histogram.
clc; close all;
n1 = [0:100000-1]; x1 = 2*rand(1,100000);
Hf_1 = figure; set(Hf_1,'NumberTitle','off','Name','P0202a');
[h1,x1out] = hist(x1,100); bar(x1out, h1);
axis([-0.1 2.1 0 1200]);
xlabel('interval','FontSize',8);
ylabel('number of elements','FontSize',8);
title('Histogram of sequence x_1(n) in 100 bins','FontSize',8);
print -deps2 ../EPSFILES/P0202a;
clc; close all;
n2 = [1:10000]; x2 = 10 + sqrt(10)*randn(1,10000);
Hf_1 = figure; set(Hf_1,'NumberTitle','off','Name','P0202b');
[h2,x2out] = hist(x2,100); bar(x2out,h2);
xlabel('interval','FontSize',8);
ylabel('number of elements','FontSize',8);
title('Histogram of sequence x_2(n) in 100 bins','FontSize',8);
print -deps2 ../EPSFILES/P0202b;
Leave a comment