0% found this document useful (0 votes)
37 views10 pages

Tutorial 1

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

Tutorial 1

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

Problem 1:

a) Matlab code:
n = -5:5; % Define the range of n

% Calculate x(n) values


x = zeros(size(n)); % Initialize x(n) with zeros
x(n == -2) = 2; % Set x(n) = 2 at n = -2
x(n == 4) = -1; % Set x(n) = -1 at n = 4
% Plot the sequence
stem(n, x, 'filled')
xlabel('n')
ylabel('x(n)')
title('Plot of the sequence x(n) = 2\delta(n + 2) - \delta(n - 4)')
grid on

b) Matlab code:
n = 0:20; % Define the range of n

% Calculate x(n) values


x = n .* ( (n >= 0) & (n < 10) ) + 10 * exp(-0.3 * (n - 10)) .* ( (n >= 10) & (n <
20) );
% Plot the sequence
stem(n, x, 'filled')
xlabel('n')
ylabel('x(n)')
title('Plot of the sequence x(n) = n[u(n) - u(n-10)] + 10e^{-0.3(n-10)}[u(n-10) -
u(n-20)]')
grid on
c) Matlab code:
n = 0:50; % Define the range of n

% Generate the Gaussian random sequence w(n)


w = 0.2 * randn(size(n)); % Gaussian random sequence with zero mean and unit
variance
% Calculate x(n) values
x = cos(0.04 * pi * n) + w;
% Plot the sequence
stem(n, x, 'filled')
xlabel('n')
ylabel('x(n)')
title('Plot of the sequence x(n) = cos(0.04\pi n) + 0.2w(n)')
grid on
d) Matlab code:
n = -10:9; % Define the range of n

% Create the repeating sequence pattern


pattern = [5, 4, 3, 2, 1];
% Replicate the pattern to match the range of n
repetitions = ceil(numel(n) / numel(pattern));
x_tilde = repmat(pattern, 1, repetitions);
x = x_tilde(1:numel(n)); % Truncate to fit the range of n
% Plot the sequence
stem(n, x, 'filled')
xlabel('n')
ylabel('x~(n)')
title('Plot of the sequence x~(n) = {..., 5, 4, 3, 2, 1, 5 ↑ , 4, 3, 2, 1, 5, 4, 3,
2, 1, ...}')
grid on
Problem 2:

a) Matlab code:
n = -5:7; % Define the range of n for x(n)

% Define the sequence x(n)


x = [1, 2, 3:7, 6:-1:1];
% Initialize x1(n) sequence
x1 = zeros(size(n));
% Calculate x1(n) = 2x(n - 5) - 3x(n + 4)
for i = 1:numel(n)
if (n(i) - 5) >= min(n) && (n(i) - 5) <= max(n)
x1(n == n(i)) = 2 * x(n == n(i) - 5);
end
if (n(i) + 4) >= min(n) && (n(i) + 4) <= max(n)
x1(n == n(i)) = x1(n == n(i)) - 3 * x(n == n(i) + 4);
end
end
% Plot the sequence x1(n)
stem(n, x1, 'filled')
xlabel('n')
ylabel('x1(n)')
title('Plot of the sequence x1(n) = 2x(n - 5) - 3x(n + 4)')
grid on
b) Matlab code:
n = -5:7; % Define the range of n for x(n)

% Define the sequence x(n)


x = [1, 2, 3:7, 6:-1:1];
% Initialize x2(n) sequence
x2 = zeros(size(n));
% Calculate x2(n) = x(3 - n) + x(n) * x(n - 2)
for i = 1:numel(n)
if (3 - n(i)) >= min(n) && (3 - n(i)) <= max(n)
x2(n == n(i)) = x(n == 3 - n(i));
end
if n(i) >= min(n) && n(i) <= max(n) && (n(i) - 2) >= min(n) && (n(i) - 2) <= max(n)
x2(n == n(i)) = x2(n == n(i)) + x(n == n(i)) * x(n == n(i) - 2);
end
end
% Plot the sequence x2(n)
stem(n, x2, 'filled')
xlabel('n')
ylabel('x2(n)')
title('Plot of the sequence x2(n) = x(3 - n) + x(n) * x(n - 2)')
grid on
Problem 3:
n = -10:10; % Define the range of n
% Generate the complex-valued signal
x = exp(-0.1 * n + 0.3j * n);
% Create subplots for magnitude, phase, real part, and imaginary part
subplot(2, 2, 1)
stem(n, abs(x), 'filled')
title('Magnitude of x(n)')
xlabel('n')
ylabel('|x(n)|')
grid on
subplot(2, 2, 2)
stem(n, angle(x), 'filled')
title('Phase of x(n)')
xlabel('n')
ylabel('Phase (radians)')
grid on
subplot(2, 2, 3)
stem(n, real(x), 'filled')
title('Real Part of x(n)')
xlabel('n')
ylabel('Re(x(n))')
grid on
subplot(2, 2, 4)
stem(n, imag(x), 'filled')
title('Imaginary Part of x(n)')
xlabel('n')
ylabel('Im(x(n))')
grid on
sgtitle('Complex-valued Signal x(n) = e^{(-0.1 + j0.3)*n}')
Problem 4:

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:

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy