Tutorial 1
Tutorial 1
a) Matlab code:
n = -5:5; % Define the range of n
b) Matlab code:
n = 0:20; % Define the range of n
a) Matlab code:
n = -5:7; % Define the range of n for x(n)
Matlab code:
% Define the prototype sequence x(n)
x = [3, 11, 7, 0, -1, 4, 2];
% Generate the noise-corrupted-and-shifted version y(n)
n = 1:length(x); % indices for the prototype sequence
w = randn(1, length(x)); % Gaussian noise sequence
y = circshift(x, [0, -2]) + w; % y(n) = x(n-2) + w(n)
% Compute cross-correlation between y(n) and x(n)
cross_corr = xcorr(y, x);
% Plot the cross-correlation sequence
n_cross = -(length(x)-1):(length(x)-1); % indices for the cross-correlation sequence
stem(n_cross, cross_corr, 'filled');
xlabel('Lag x(n)');
ylabel('Cross-correlation');
title('Cross-correlation between y(n) and x(n)');
grid on;
Problem 5:
a) Matlab code:
% Define the range for n
n = -20:100;
% Initialize the signals y(n) and x(n)
y = zeros(size(n));
x = zeros(size(n));
x(n == 0) = 1; % Impulse input, x(n) is a delta function at n = 0
% Calculate y(n) using the given difference equation
for i = 3:length(n)
y(i) = x(i) + y(i - 1) - 0.9 * y(i - 2);
end
% Impulse response h(n) is the output signal y(n) for an input delta function
h = y;
% Plot the impulse response h(n)
stem(n, h, 'filled');
xlabel('n');
ylabel('h(n)');
title('Impulse Response h(n)');
grid on;
b) Matlab code:
% Define the range for n
n = -20:100;
% Initialize the signals y(n) and x(n)
y = zeros(size(n));
x = zeros(size(n));
x(n >= 0) = 1; % Unit step input, x(n) is a unit step function u(n)
% Calculate y(n) using the given difference equation
for i = 3:length(n)
y(i) = x(i) + y(i - 1) - 0.9 * y(i - 2);
end
% Unit step response h(n) is the output signal y(n) for an input unit step function
h = y;
% Plot the unit step response h(n)
stem(n, h, 'filled');
xlabel('n');
ylabel('h(n)');
title('Unit Step Response h(n)');
grid on;
c) Matlab code: