0% found this document useful (0 votes)
32 views2 pages

Write MATLAB Code That Performs Various Transformations On The Given Input Signal

matlab code

Uploaded by

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

Write MATLAB Code That Performs Various Transformations On The Given Input Signal

matlab code

Uploaded by

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

>> % MATLAB Code to Perform Various Transformations on a Signal

% Define the original signal


n = -10:10; % Discrete time indices
x = (n >= 0 & n <= 5); % Original signal (rectangular pulse from n = 0 to 5)

% Plot the original signal


figure;
subplot(3, 2, 1);
stem(n, x, 'filled');
title('Original Signal x[n]');
xlabel('n (Discrete Time)');
ylabel('Amplitude');
grid on;

% 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;

% Shift the signal by 3 units to the left


n_shift_left = n - 3;
subplot(3, 2, 3);
stem(n_shift_left, x, 'filled');
title('Time-Shifted Signal x[n+3] (Left 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;

% Scale the time axis by a factor of 0.5 (compresses the signal)


n_scale_compress = n * 0.5;
subplot(3, 2, 5);
stem(n_scale_compress, x, 'filled');
title('Time-Scaled Signal x[0.5n] (Compression)');
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;

% 4. Amplitude Scaling (Separate Figure)


% Scale the amplitude by a factor of 2
x_amp_scale = 2 * x;
figure;
subplot(2, 1, 1);
stem(n, x_amp_scale, 'filled');
title('Amplitude-Scaled Signal 2 * x[n]');
xlabel('n (Discrete Time)');
ylabel('Amplitude');
grid on;

% Scale the amplitude by a factor of 0.5


x_amp_scale_half = 0.5 * x;
subplot(2, 1, 2);
stem(n, x_amp_scale_half, 'filled');
title('Amplitude-Scaled Signal 0.5 * x[n]');
xlabel('n (Discrete Time)');
ylabel('Amplitude');
grid on;

% Adjust layout
sgtitle('Various Signal Transformations');

You might also like