Professional Documents
Culture Documents
Signal Lab
Signal Lab
Class: BCE 4A
Solution:
t = linspace(-3, 6, 1000);
x = zeros(size(t));
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';
t = (0:length(x)-1) / Fs;
sound(x_upsampled, 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);
end
Plot: