Lab5 Solutions
Lab5 Solutions
Lab5 Solutions
clear;
close all;
%% Task 1
for i = 1:8
N = rand(1, 1); % 2.a) Generating random signal realizations
th = 2*pi*N; % 2.b)) Generating random signal realizations
x = A*cos(w*t+th); % 2.c) Generating random signal realizations
plot(t, x); grid on; hold all; % 2.d) Plotting the random signal
realizations
end
%% Task 2
figure
hist (x1, 100); grid on; %d) Generating histogram for the signal
[N1, X1] = hist(x1, 100); %e) Defining the number of elements in each bin (N)
and the positions of bin centers (X)
figure
bar(X1, N1/10000); grid on; hold on; %f) Normalized histogram result
t2 = 1.92; %j) Repeating the same test for another time constant
(t2)
x2 = A*cos(w*t2+2*pi*N); % Generating random signal x(t1)
figure
hist (x2, 100); grid on; % Generating histogram for the signal
[N2, X2] = hist(x2, 100); % Defining the number of elements in each bin (N) and
the positions of bin centers (X)
figure
bar(X2, N2/10000); grid on; hold on; % Normalized histogram result
%% Task 4
%% Task 5
figure
plot(lag1_s1, s1_ACVF); title('Auto-covariance function of s1'); grid on; xlim([-
size(lag1_s1, 2)/2 size(lag1_s1, 2)/2]);
figure
plot(lag2_s1, s1_ACF); title('Auto-correlation function of s1'); grid on;
figure
plot(lag1_s2, s2_ACVF); title('Auto-covariance function of s2'); grid on; xlim([-
size(lag1_s2, 2)/2 size(lag1_s2, 2)/2]);
figure
plot(lag2_s2, s2_ACF); title('Auto-correlation function of s2'); grid on;
figure
plot(lagVx, s1_s2_CCVF); title('Cross-covariance between s1 and s2'); grid on;
figure
plot(lagCx, s1_s2_CCF); title('Cross-correlation between s1 and s2'); grid on;
% g) Testing the normal distribution of the signals
figure
histfit(s1);
figure
histfit(s2);
figure
normplot(s1);
figure
normplot(s2);
%% Task 6
m.NoiseVariance = 0;
ykstar = sim(m, uk); %c) Noise-free output
signal
m.Noisevariance = 0.9*var(ykstar)/10; %d) Changing thee noise
variance of the model
yk = sim(m, uk, simOptions('AddNoise', true)); %e) Noisy output
e = yk-ykstar; %f) Noise(error) signal
figure
subplot(411); plot(uk(1:500)); title('Input signal');
subplot(412); plot(ykstar(1:500)); title('Noise-free output signal');
subplot(413); plot(yk(1:500)); title('Noisy output signal');
subplot(414); plot(e(1:500));title('Error signal');