Name :- Siddhi Pawase
Subject :- Signals & systems
Assignment No. 1
Title :- Generate and plot the following signals in time domain and also sketch its
amplitude and phase spectrum. Verify the result: Impulse Unit Step Exponential
Unit ramp Sinc Rectangular.
Matlab Program :-
% MATLAB code to generate and plot time-domain signals and their
spectra
% Time vector for plotting
t = -5:0.01:5; % Time from -5 to 5 seconds with a step size of 0.01
fs = 100; % Sampling frequency
f = linspace(-fs/2, fs/2, length(t)); % Frequency axis
% 1. Impulse Signal (Dirac delta)
impulse_signal = (t == 0); % Impulse function at t = 0
% 2. Unit Step Signal
unit_step_signal = t >= 0; % Unit step function
% 3. Exponential Signal
exponential_signal = exp(-0.5*t); % Exponential decay
% 4. Unit Ramp Signal
unit_ramp_signal = max(0, t); % Ramp signal
% 5. Sinc Signal
sinc_signal = sinc(t); % sinc function
% 6. Rectangular Signal
rectangular_signal = double(abs(mod(t, 1) - 0.5) < 0.5); %
Rectangular pulse of width 1
% Plot time-domain signals
figure;
subplot(3,2,1);
plot(t, impulse_signal, 'LineWidth', 2);
title('Impulse Signal');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;
subplot(3,2,2);
plot(t, unit_step_signal, 'LineWidth', 2);
title('Unit Step Signal');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;
subplot(3,2,3);
plot(t, exponential_signal, 'LineWidth', 2);
title('Exponential Signal');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;
subplot(3,2,4);
plot(t, unit_ramp_signal, 'LineWidth', 2);
title('Unit Ramp Signal');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;
subplot(3,2,5);
plot(t, sinc_signal, 'LineWidth', 2);
title('Sinc Signal');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;
subplot(3,2,6);
plot(t, rectangular_signal, 'LineWidth', 2);
title('Rectangular Signal');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;
% Now, calculate and plot the Frequency Domain (Amplitude and Phase
Spectra)
signals = {impulse_signal, unit_step_signal, exponential_signal,
unit_ramp_signal, sinc_signal, rectangular_signal};
signal_titles = {'Impulse Signal', 'Unit Step Signal', 'Exponential
Signal', 'Unit Ramp Signal', 'Sinc Signal', 'Rectangular Signal'};
% Create a new figure for the frequency domain analysis
figure;
for i = 1:6
signal = signals{i};
% Compute the Fourier Transform of the signal
signal_fft = fftshift(fft(signal)); % FFT and shift zero frequency
component to center
amplitude_spectrum = abs(signal_fft); % Amplitude Spectrum
phase_spectrum = angle(signal_fft); % Phase Spectrum
% Plot the Amplitude Spectrum
subplot(6,2,2*i-1);
plot(f, amplitude_spectrum, 'LineWidth', 2);
title([signal_titles{i}, ' - Amplitude Spectrum']);
xlabel('Frequency (Hz)');
ylabel('Amplitude');
grid on;
% Plot the Phase Spectrum
subplot(6,2,2*i);
plot(f, phase_spectrum, 'LineWidth', 2);
title([signal_titles{i}, ' - Phase Spectrum']);
xlabel('Frequency (Hz)');
ylabel('Phase (radians)');
grid on;
end
OUTPUT :-
FIGURE 1 :-
FIGURE 2:-