0% found this document useful (0 votes)
19 views8 pages

Signal Lab

The document discusses three questions related to signal processing. Question 1 involves generating and plotting various signals. Question 2 repeats this for discrete-time signals. Question 3 reads and manipulates a sound signal by upsampling and downsampling it.

Uploaded by

Rehan Gaming
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)
19 views8 pages

Signal Lab

The document discusses three questions related to signal processing. Question 1 involves generating and plotting various signals. Question 2 repeats this for discrete-time signals. Question 3 reads and manipulates a sound signal by upsampling and downsampling it.

Uploaded by

Rehan Gaming
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/ 8

COMPUTER ENGINEERING DEPARTMENT

“Signal and System”


LAB ASSIGNMENT

Group Members: AHMED RAHEEL (FA21-BCE-015)


Aashir Ali Khan (FA21-BCE-011)
Zain Ul Abideen (FA21-BCE-009)

Class: BCE 4A

DATE: 2nd June 2023


Question Number 1:
Use MATLAB to generate and plot the following signals, where (𝑡) is shown below. Plot
all the signals including (𝑡), 𝑡 ∈ [−3, 6] in one figure using the subplot.

Solution:
t = linspace(-3, 6, 1000);
x = zeros(size(t));

x(t >= 0 & t <= 1) = 1;


x(t > 1 & t <= 2) = 2 - t(t > 1 & t <= 2);

t_new = t/2 + 1;
x_new = x((t_new >= -3) & (t_new <= 6));

subplot(2,2,1);
plot(t, x, 'k-', 'LineWidth', 1.5);
title('Original Signal');

subplot(2,2,2);
x_shifted = [0 x(1:end-1)];
plot(t, x + x_shifted, 'b-', 'LineWidth', 1.5);
title('x(t) + x(t-1)');

subplot(2,2,3);
plot(t, x .* x_shifted, 'r-', 'LineWidth', 1.5);
title('x(t) * x(t-1)');

subplot(2,2,4);
integral = cumtrapz(t, x); % Compute the integral of x(t)
plot(t, integral, 'g-', 'LineWidth', 1.5);
title('Integral of x(\tau)');

spacing = 0.08;
for i = 1:4
subplot(2,2,i);
pos = get(gca, 'Position');
if mod(i,2) == 0
pos(1) = pos(1) + spacing;
else
pos(3) = pos(3) - spacing;
end
pos(4) = pos(4) - spacing;
set(gca, 'Position', pos);
end

Plot:

Question Number 2:
Repeat part 1 for the discrete-time signal [𝑛], 𝑛 ∈ [−6, 6].

Solution
n = -6:6;
x = zeros(size(n));
x(n == -4) = -1;
x(n == -3) = -1/2;
x(n == -2) = 1/2;
x(n == -1 | n == 0 | n == 1 | n == 2) = 1;
x(n == 3) = 1/2;

subplot(3, 2, 1);
stem(n, x, 'filled', 'MarkerSize', 5);
title('x[n]');
xlabel('n');
ylabel('x');
grid on;

subplot(3, 2, 2);
stem(1 - n, x, 'filled', 'MarkerSize', 5);
title('x[1-n]');
xlabel('n');
ylabel('x');
grid on;

subplot(3, 2, 3);
x_shifted = [0 x(1:end-1)];
stem(n, x - x_shifted, 'filled', 'MarkerSize', 5);
title('x[n] - x[n-1]');
xlabel('n');
ylabel('x');
grid on;

subplot(3, 2, 4);
x_multiplied = x .* [zeros(1, 3) x(1:end-3)];
stem(n, x_multiplied, 'filled', 'MarkerSize', 5);
title('x[n] * x[n-3]');
xlabel('n');
ylabel('x');
grid on;

subplot(3, 2, 5);
sum_x = cumsum(x);
stem(n, sum_x, 'filled', 'MarkerSize', 5);
title('Sum of x[k]');
xlabel('n');
ylabel('Sum');
grid on;

spacing = 0.08;
for i = 1:5
subplot(3, 2, i);
pos = get(gca, 'Position');
if mod(i, 2) == 0
pos(1) = pos(1) + spacing;
else
pos(3) = pos(3) - spacing;
end
pos(4) = pos(4) - spacing;
set(gca, 'Position', pos);
end
Plot:

Question 3
Read the sound signal ‘speech_16k.wav’ provided with this lab in MATLAB and play it.

Then create a suitable time axis to plot the signal. Now, construct an up-sampled and

down-sampled version of sound signal by a factor of 2 and then play them one by one.

What do you notice? Also plot these signals together with the original signal.

Solution:
filename = 'speech_16k.wav';

[x, Fs] = audioread(filename);

t = (0:length(x)-1) / Fs;

x_upsampled = upsample(x, 2);

t_upsampled = (0:length(x_upsampled)-1) / (Fs * 2);

sound(x_upsampled, Fs * 2);

x_downsampled = downsample(x, 2);

t_downsampled = (0:length(x_downsampled)-1) / (Fs / 2);

sound(x_downsampled, Fs / 2);

figure;

subplot(3, 1, 1);
plot(t, x);

title('Original Signal');

xlabel('Time (s)');

ylabel('Amplitude');

subplot(3, 1, 2);

plot(t_upsampled, x_upsampled);

title('Upsampled Signal');

xlabel('Time (s)');

ylabel('Amplitude');

subplot(3, 1, 3);

plot(t_downsampled, x_downsampled);

title('Downsampled Signal');

xlabel('Time (s)');

ylabel('Amplitude');

spacing = 0.08;

for i = 1:3

subplot(3, 1, i);

pos = get(gca, 'Position');

pos(4) = pos(4) - spacing;

set(gca, 'Position', pos);

end
Plot:

You might also like