(b) Generate a Bernoulli (p=0.2) random variable (i.e. matlab code)
(c) Investigate whether the code in (b) works
2. Use the Matlab NORMAL random number generator to
(a) Investigate the claim that it’s mean and variance really are 0 and 1, respectively.
(b) Let X be generation of a random number and Y be generation of the next number. Investigate whether X and Y are independent (in this case, you can do this by seeing if they are simply uncorrelated.)
(c) Extend (b) to the case of a 10-element random vector
Problem 1.
Problem 2. Repeat the investigation of the sinusoid-plus-noise problem conducted in class, but where the frequency of the sinusoid is changing with time. Specifically, suppose the frequency w(t) = w(t-1) + u(t) where u(t) is a normal white noise process with standard deviation equal to (i) 0.001, and then (ii) 0.02. Comment on the accuracy of the AR(2) model in each case.
% PURPOSE: Illustrate need for course concepts %==================== % sinusoid as a recursion w = 0.2; % sine frequency re: fsamp=1; phi = pi/8; % phase; x(1)=1; x(2)=cos(w); % initial conditions; n = 1000; % data length for t = 3:n x(t) = 2*cos(w)*x(t-1) - x(t-2); end figure(1) plot(x) title('1000 Points of a Sinusoid with frequency = 0.2') pause % End of sine generation % ===================== % realization of a white noise process sigma = 0.5; % white noise std. dev.; e=sigma*randn(1,n); % white noise with power sigma^2; figure(2) plot(e) title('1000 Points of a White Noise Process with sigma = 0.25') pause % End of White Noise Generation % ====================== % Observation = sine plus noise process y = x + e; figure(3) plot(y) title('1000 Points of sine-plus-noise process') pause % ====================== % AR(2) model parameter estimation c0 = y*y'; c1 = y(1:n-1)*y(2:n)'; c2 = y(1:n-2)*y(3:n)'; Cmat = [c0 c1 ; c1 c0]; cvec = [c1 ; c2]; ahat = inv(Cmat)*cvec; % Generation of modeled pprocess xhat(1) = y(1); xhat(2) = y(2); for t =3:n xhat(t) = ahat(1)*y(t-1) + ahat(2)*y(t-2); end figure(4) plot(xhat) hold plot(x,'m') title('Plots of the original sine and the estimated one')