Write MATLAB Code That Performs Various Transformations On The Given Input Signal
Write MATLAB Code That Performs Various Transformations On The Given Input Signal
% 1. Time Shifting
% Shift the signal by 3 units to the right
n_shift_right = n + 3;
subplot(3, 2, 2);
stem(n_shift_right, x, 'filled');
title('Time-Shifted Signal x[n-3] (Right Shift)');
xlabel('n (Discrete Time)');
ylabel('Amplitude');
grid on;
% 2. Time Scaling
% Scale the time axis by a factor of 2 (expands the signal)
n_scale_expand = n * 2;
subplot(3, 2, 4);
stem(n_scale_expand, x, 'filled');
title('Time-Scaled Signal x[2n] (Expansion)');
xlabel('n (Discrete Time)');
ylabel('Amplitude');
grid on;
% 3. Time Reversal
% Reverse the signal in time
n_reverse = -n;
subplot(3, 2, 6);
stem(n_reverse, x, 'filled');
title('Time-Reversed Signal x[-n]');
xlabel('n (Discrete Time)');
ylabel('Amplitude');
grid on;
% Adjust layout
sgtitle('Various Signal Transformations');