You are on page 1of 28

Digital Communication Lab, Dept. of ECE, KLEF Deemed to be University, A.P., India.

Department of ECE
Digital Communications Lab (22EC2208L) AY2023-23
Module2: Representation and Visualization of Communication
Signals

Introduction:

The generation and visualization of various signals such as periodic signals, singularity functions and
other useful signals used in communication systems are explored both in Time domain and Frequency domain
in this module.

Module Objectives:
Development of programming skills using Matlab scripts / Simulink / GNU Radio SDR to representation,
generation and visualize the following signals that are widely used in communication systems both in Time
domain and Frequency domain.
 Development of Matlab codes to generate and visualization of Periodic signals such as
sinusoidal signals, exponential signals, square wave, triangular wave signals and periodic
impulse train in time domain.
 Development of Matlab codes to generate and visualization in spectral domain (frequency
domain) of Periodic signals such as sinusoidal signals, exponential signals, square wave,
triangular wave signals and periodic impulse train.
 Development of Matlab codes to generate and visualization in time domain of useful signals
such as square, triangular, sinc and Gaussian pulse signals that are widely used in
communication system.
 Development of Matlab codes to generate and visualization in spectral domain (frequency
domain) of useful signals such as square, triangular, sinc and Gaussian pulse signals.

Matlab commands used in this project module:

sin, cos, square, pulstran, rectpuls, tripuls

Students are instructed to study the above commands prior to the commencement of this project
Digital Communication Lab, Dept. of ECE, KLEF Deemed to be University, A.P., India.

2.1 Spectral Representation: Fourier Transform (FT)

The Analysis and synthesis equations of a continuous time Fourier transform (CTFT) s defined as below:

 jtdt
Analysis equation / forward FT: X ( j)  

x(t) e

1 
x(t) 
Synthesis equation / inverse FT:
2  X ( j) e jtd
Magnitude and Phase spectrum:
X ( j) is complex in general and need two plots for its graphical representation

X ( j)  | X ( j) | e j ()


where | X ( j)
is known as magnitude spectrum, and is
 ( )
known as phase spectrum.

2.1 Sinusoidal Signal and its spectrum:

2.1.1 Time domain representation of Sinusoidal signals.

The graphical representation of sinusoidal signals is shown in Fig 2.1. A standard mathematical representation of

sinusoidal signal is given by x(t)  Acos(0t   ) or x(t)  Asin(0t  ) , where

A is the peak or maximum value of the signal, 0 is the frequency in radians ( 0  2 F0 


2 ),
T0
and 
is the phase angle measured in radians.

Fig.2.1 Representation of sinusodal signals

2.1.2: Frequency domain representation of Sinusoidal signals


FT
(a) Acos(0t)  A  (  0 )   (  0 )

Digital Communication Lab, Dept. of ECE, KLEF Deemed to be University, A.P., India.

(b) sin(0t) FT
 Aj  (  0 )   (   0 )

WE1: Generate a sinusoidal signal with the following specifications:

Amplitude = 1 V, Frequency: 400 Hz, Develop Matlab code, simulate and display

(a) Time domain signal

(b) Spectrum of the given signal

% Generation and display of single tone message signal and its spectrum
% Message signal is a sinusoidal signal with frequency of 400 Hz.

clear; close all; clc;

%Sample frequency
Fs=10000;%Sample frequency

% %Number of samples
N=5000;%Number of samples
Ts=1/Fs; % Sampling interval
% t=(0:Ts:(N*Ts)- Ts); % Time index
t = (-N/2:1:(N/2)-1)*Ts;

% Message (Sinusoidal) signal generation


% Signal amplitude, frequency and phase components
A = 1; fm = 400; theta = 0;
m = A*cos(2*pi*fm*t+theta);

% Visualizing the signals


% Sinusoidal signal
figure();
Digital Communication Lab, Dept. of ECE, KLEF Deemed to be University, A.P., India.

subplot(2,1,1);
plot(t,m, 'k', 'LineWidth',1.5);
xlabel('Time (seconds)');ylabel('Amplitude');
title('Sinusoidal signal');grid on;
axis([0 0.008 -1.2 1.2]);% for 400 Hz

% Spectrum of Message signal ----------


f = (1/N)*(-N/2:1:(N/2)-1)*Fs; % Frequency scale
M = (2/N)*fftshift(fft(m)); % FT of the message signal

% Plotting the Spectrum of Message signal


subplot(2,1,2);
% plot(f,abs(M/max(M)),'r','Linewidth',2); q
plot(f,abs(M),'r','Linewidth',2);
xlabel('frequency'); ylabel('Magnitude|');
title('Spectrum of Sinusoidal Signal'); grid on
axis([-1000 1000 0 1.1]); % for 400 Hz

Task1: Consider two sinusoidal signals with amplitudes of 1.4 Volts and, 0.8 Volts and frequencies of 2 Hz
and 8 Hz respectively. Develop Matlab code, simulate and display

(a) Time domain signal

(b) Spectrum of the given signal.


Digital Communication Lab, Dept. of ECE, KLEF Deemed to be University, A.P., India.

(c) Suppose a phase of +pi/2 is added to the signal. Is there any change in the spectrum?

(d) Analyze the results for various phase values.

Code:

% Parameters for the first sinusoidal signal


amplitude_1 = 1.4; % Amplitude of the first signal (1.4 V)
frequency_1 = 2; % Frequency of the first signal (2 Hz)
% Parameters for the second sinusoidal signal
amplitude_2 = 0.8; % Amplitude of the second signal (0.8 V)
frequency_2 = 8; % Frequency of the second signal (8 Hz)
% Time specifications
duration = 1; % Duration of the signal in seconds
sampling_rate = 1000; % Sampling rate (samples per second)
t = linspace(0, duration, duration * sampling_rate); % Time vector
% Generate the two sinusoidal signals
signal_1 = amplitude_1 * sin(2 * pi * frequency_1 * t);
signal_2 = amplitude_2 * sin(2 * pi * frequency_2 * t);
% Plot time domain signals
figure;
subplot(3, 2, 1);
plot(t, signal_1);
title('Sinusoidal Signal 1 (2 Hz)2200040248');
xlabel('Time (s)');
ylabel('Amplitude');
ylim([-1.5 * amplitude_1, 1.5 * amplitude_1]);
subplot(3, 2, 2);
plot(t, signal_2);
title(['Sinusoidal Signal 2 (8 Hz)' ...
'2200040248']);
xlabel('Time (s)');
ylabel('Amplitude');
ylim([-1.5 * amplitude_2, 1.5 * amplitude_2]);
% Calculate and plot the spectrum for both signals
figure;
subplot(3, 2, 3);
fft_signal_1 = fft(signal_1);
L = length(signal_1);
P2 = abs(fft_signal_1/L);
P1 = P2(1:L/2+1);
P1(2:end-1) = 2*P1(2:end-1);
f = sampling_rate*(0:(L/2))/L;
stem(f, P1);
title([' Sinusoidal Signal 1 (2 Hz)/n' ...
' 2200040248']);
xlabel('Frequency (Hz)');
ylabel('Amplitude');
subplot(3, 2, 4);
fft_signal_2 = fft(signal_2);
L = length(signal_2);
P2 = abs(fft_signal_2/L);
Digital Communication Lab, Dept. of ECE, KLEF Deemed to be University, A.P., India.

P1 = P2(1:L/2+1);
P1(2:end-1) = 2*P1(2:end-1);
f = sampling_rate*(0:(L/2))/L;
stem(f, P1);
title('Spectrum of Sinusoidal Signal 2 (8 Hz)2200040248');
xlabel('Frequency (Hz)');
ylabel('Amplitude');

% Adding phase shift of +pi/2 to both signals


phase_shift = pi/2;
signal_1_phase_shifted = amplitude_1 * sin(2 * pi * frequency_1 * t + phase_shift);
signal_2_phase_shifted = amplitude_2 * sin(2 * pi * frequency_2 * t + phase_shift);
% Calculate and plot the spectrum for phase-shifted signals
figure;
subplot(3, 2, 5);
fft_signal_1_phase_shifted = fft(signal_1_phase_shifted);
L = length(signal_1_phase_shifted);
P2 = abs(fft_signal_1_phase_shifted/L);
P1 = P2(1:L/2+1);
P1(2:end-1) = 2*P1(2:end-1);
f = sampling_rate*(0:(L/2))/L;
stem(f, P1);
title('Spectrum of Sinusoidal Signal 1 with Phase Shift (+pi/2)/n2200040248');
xlabel('Frequency (Hz)');
ylabel('Amplitude');
subplot(3, 2, 6);
fft_signal_2_phase_shifted = fft(signal_2_phase_shifted);
L = length(signal_2_phase_shifted);
P2 = abs(fft_signal_2_phase_shifted/L);
P1 = P2(1:L/2+1);
P1(2:end-1) = 2*P1(2:end-1);
f = sampling_rate*(0:(L/2))/L;
stem(f, P1);
title('Spectrum of Sinusoidal Signal 2 with Phase Shift (+pi/2)2200040248');
xlabel('Frequency (Hz)');
ylabel('Amplitude');

Result:
Digital Communication Lab, Dept. of ECE, KLEF Deemed to be University, A.P., India.
Digital Communication Lab, Dept. of ECE, KLEF Deemed to be University, A.P., India.

Periodic Square wave (clock) and its Spectrum.

 1, | t |  1
One period of square wave is represented by rect(t)    2
T tT
1 2 2
0, | t | 2

The corresponding Fourier series is represented by

WE2: Generate a square wave signal with the following specifications: Amplitude = 1 V,
Frequency: 400 Hz, Consider duty cycle 25%.
Develop Matlab code, simulate and display
(a) Time domain signal
(b) Spectrum of the given signal
Digital Communication Lab, Dept. of ECE, KLEF Deemed to be University, A.P., India.

% %Sample frequency
Fs=30000;%Sample frequency

% %Number of samples
N=5000;%Number of samples

Ts=1/Fs; % Sampling interval


t = (-N/2:1:(N/2)-1)*Ts;

% Periodic square wave signal generation


% Signal amplitude, frequency and duly cycle
A = 1; fm = 400; D = 25; % Duty cycle 25%
m = A*square(2*pi*fm*t,25); % Generation of periodic square wave

% Visualizing the signals


% Periodic square wave
figure();
subplot(2,1,1);
plot(t,m, 'b', 'LineWidth',1.5);
xlabel('Time (seconds)');ylabel('Amplitude');
title('Periodic Square wave');grid on;
axis([-0.004 0.004 -1.2 1.2]);% for 400 Hz

% FT of Periodic square wave / Pulse train


f = (1/N)*(-N/2:1:(N/2)-1)*Fs; % Frequency scale
M = (2/N)*fftshift(fft(m)); % FT of the message signal
% Plotting the Spectrum of Message signal
subplot(2,1,2);
plot(f,abs(M/max(M)),'r','Linewidth',2);
xlabel('frequency'); ylabel('Magnitude|');
title('Spectrum of Periodic Square wave signal'); grid on
% axis([-1000 1000 0 1.1]); % for 400 Hz
Digital Communication Lab, Dept. of ECE, KLEF Deemed to be University, A.P., India.

Task2: Develop Matlab code to generate a square wave signal and its spectrum with the following specifications:
Amplitude = 1 V, Frequency: 50 Hz,
(a) Analyze the results with the duty cycles: (i) 10%, (ii) 25% and (iii) 80%
(b) What are the frequency components available in the spectrum?
(c) Comment on the shape of the spectrum

Code:
% Parameters
amplitude = 1; % Amplitude of the square wave (1 V)
frequency = 50; % Frequency of the square wave (50 Hz)
duty_cycles = [0.1, 0.25, 0.8]; % Duty cycles: 10%, 25%, and 80%
% Time specifications
duration = 1; % Duration of the signal in seconds
sampling_rate = 1000; % Sampling rate (samples per second)
t = linspace(0, duration, duration * sampling_rate); % Time vector
% Generate and plot square waves for different duty cycles
figure;
for i = 1:length(duty_cycles)
duty_cycle = duty_cycles(i);
square_wave = amplitude * square(2 * pi * frequency * t, duty_cycle * 100);
% Plot square wave
subplot(length(duty_cycles), 1, i);
plot(t, square_wave);
title(sprintf('Square Wave with Duty Cycle %.0f%2200040248', duty_cycle * 100));
xlabel('Time (s)');
ylabel('Amplitude');
ylim([-1.2 * amplitude, 1.2 * amplitude]);
end
% Calculate and plot the spectrum for a duty cycle of 50%
duty_cycle_50 = 0.5;
square_wave_50 = amplitude * square(2 * pi * frequency * t, duty_cycle_50 * 100);
figure;
subplot(2, 1, 1);
plot(t, square_wave_50);
title('Square Wave with Duty Cycle 50%2200040248');
xlabel('Time (s)');
ylabel('Amplitude');
ylim([-1.2 * amplitude, 1.2 * amplitude]);
% Calculate and plot the spectrum
Y = fft(square_wave_50);
L = length(square_wave_50);
P2 = abs(Y/L);
P1 = P2(1:L/2+1);
P1(2:end-1) = 2*P1(2:end-1);
f = sampling_rate*(0:(L/2))/L;
subplot(2, 1, 2);
stem(f, P1);
title('Single-Sided Amplitude Spectrum2200040248');
Digital Communication Lab, Dept. of ECE, KLEF Deemed to be University, A.P., India.

xlabel('Frequency (Hz)');
ylabel('Amplitude');
% Display frequency components
disp('Frequency components in the spectrum:2200040248');
disp(f(2:end)); % Display frequencies excluding DC component
% Comment on the shape of the spectrum
disp('Comment on the shape of the spectrum:2200040248');

Result:
Digital Communication Lab, Dept. of ECE, KLEF Deemed to be University, A.P., India.

Periodic Pulse train and its Spectrum using square wave

 1, | t |  1
One period of square wave is represented by rect(t)    2
T tT
1 2 2
0, | t | 2
The corresponding Fourier series is represented by

WE3: Generate a periodic pulse train signal with the following specifications:
Amplitude = 1 V, Frequency: 400 Hz, Consider duty cycle 25%. Develop Matlab code, simulate and
display
(a) Time domain signal
(b) Spectrum of the given signal.

Code:
% %Sample frequency
Fs=30000;%Sample frequency

% %Number of samples
N=5000;%Number of samples

Ts=1/Fs; % Sampling interval


t = (-N/2:1:(N/2)-1)*Ts;

% Periodic square wave signal generation


% Signal amplitude, frequency and duly cycle A =
1; fm = 400; D = 25; % Duty cycle 25%
m = A*square(2*pi*fm*t,25); % Generation of periodic square wave

% Visualizing the signals


% Periodic square wave
figure();
subplot(2,1,1);
plot(t,m, 'b', 'LineWidth',1.5);
xlabel('Time (seconds)');ylabel('Amplitude');
title('Periodic Square wave');grid on;
axis([-0.004 0.004 -1.2 1.2]);% for 400 Hz

% FT of Periodic square wave / Pulse train


f = (1/N)*(-N/2:1:(N/2)-1)*Fs; % Frequency scale
M = (2/N)*fftshift(fft(m)); % FT of the message signal

% Plotting the Spectrum of Message signal


subplot(2,1,2);
plot(f,abs(M/max(M)),'r','Linewidth',2);
Digital Communication Lab, Dept. of ECE, KLEF Deemed to be University, A.P., India.

xlabel('frequency'); ylabel('Magnitude|');
title('Spectrum of Periodic Square wave signal'); grid on
% axis([-1000 1000 0 1.1]); % for 400 Hz

Result:
Digital Communication Lab, Dept. of ECE, KLEF Deemed to be University, A.P., India.

Task3: Develop Matlab code to generate a square wave signal and its spectrum with the following specifications:
Amplitude = 1 V, Frequency: 10 Hz,
(a) Analyze the results with the duty cycles: (i) 10%, (ii) 25% and (iii) 80%
(b) What are the frequency components are available in the spectrum?
(c) Comment on the shape of the spectrum
Code:

% Parameters
amplitude = 1; % Amplitude of the square wave (1 V)
frequency = 10; % Frequency of the square wave (10 Hz)
duty_cycles = [0.1, 0.25, 0.8]; % Duty cycles: 10%, 25%, and 80%
% Time specifications
duration = 1; % Duration of the signal in seconds
sampling_rate = 1000; % Sampling rate (samples per second)
t = linspace(0, duration, duration * sampling_rate); % Time vector
% Generate and plot square waves for different duty cycles
figure;
for i = 1:length(duty_cycles)
duty_cycle = duty_cycles(i);
square_wave = amplitude * square(2 * pi * frequency * t, duty_cycle * 100);

% Plot square wave


subplot(length(duty_cycles), 1, i);
plot(t, square_wave);
title(sprintf('Square Wave with Duty Cycle %.0f%2200040248', duty_cycle * 100));
xlabel('Time (s)');
ylabel('Amplitude');
ylim([-1.2 * amplitude, 1.2 * amplitude]);
end
% Calculate and plot the spectrum for a duty cycle of 50%
duty_cycle_50 = 0.5;
square_wave_50 = amplitude * square(2 * pi * frequency * t, duty_cycle_50 * 100);
figure;
subplot(2, 1, 1);
plot(t, square_wave_50);
title('Square Wave with Duty Cycle 50%2200040248');
xlabel('Time (s)');
ylabel('Amplitude');
ylim([-1.2 * amplitude, 1.2 * amplitude]);
% Calculate and plot the spectrum
Y = fft(square_wave_50);
L = length(square_wave_50);
P2 = abs(Y/L);
P1 = P2(1:L/2+1);
P1(2:end-1) = 2*P1(2:end-1);
f = sampling_rate*(0:(L/2))/L;
subplot(2, 1, 2);
stem(f, P1);
title('Single-Sided Amplitude Spectrum 2200040248');
Digital Communication Lab, Dept. of ECE, KLEF Deemed to be University, A.P., India.

xlabel('Frequency (Hz)');
ylabel('Amplitude');
% Display frequency components
disp('Frequency components in the spectrum:2200040248');
disp(f(2:end)); % Display frequencies excluding DC compone

Result

2.3.
Digital Communication Lab, Dept. of ECE, KLEF Deemed to be University, A.P., India.

2.3. periodic Pulse Train and its Spectrum using Matlab command pulstran.m.

The mathematical representation are similar to above in 2.3.

WE3: Generate a periodic pulse train signal with the following specifications:

Amplitude = 1 V, Frequency 20 Hz. Pulse width: unity. Develop Matlab code, simulate and display

(a) Time domain signal

(b) Spectrum of the given signal.


Digital Communication Lab, Dept. of ECE, KLEF Deemed to be University, A.P., India.

clear; close all; clc;

Fs = 1000; % Sampling frequency


t = -0.5 : 1/Fs : 0.5;
d = -0.5 : 1/20 : 0.5; % repetition frequency
m = pulstran(t,d,'rectpuls',0.01);
N = length(m);
figure();
subplot(2,1,1);
plot(t,m,'b', 'LineWidth', 1.5);
axis([-0.3 0.3 -0.002 1.12]); grid on;
xlabel('Time (ns)');ylabel('Amplitude');
title('Rectangular Pulse Train');

% Spectrum of Periodic pulse train-----


f = (1/N)*(-N/2:1:(N/2)-1)*Fs; % Frequency scale
M = (2/N)*fftshift(fft(m)); % FT of the message signal

% Plotting the Spectrum of Message signal


subplot(2,1,2);
plot(f,abs(M/max(M)),'r','Linewidth',2);
xlabel('frequency'); ylabel('Magnitude|');
title('Spectrum of Periodic Pulse Train'); grid on

Task4: Develop Matlab code to generate a square wave signal and its spectrum with the following specifications:
Amplitude = 1 V, Frequency: 10 Hz,
(d) Analyze the results with the duty cycles: (i) 10%, (ii) 25% and (iii) 80%
(e) What are the frequency components are available in the spectrum?
(f) Comment on the shape of the spectrum
Code:
% Parameters
Digital Communication Lab, Dept. of ECE, KLEF Deemed to be University, A.P., India.

amplitude = 1; % Amplitude of the square wave in Volts


frequency = 10; % Frequency of the square wave in Hz
duty_cycles = [0.1, 0.25, 0.8]; % Duty cycles to analyze
% Time vector
Fs = 1000; % Sampling frequency
t = 0:1/Fs:1-1/Fs; % Time vector from 0 to 1 second

% (d) Generate square wave signals with different duty cycles


figure;
for i = 1:length(duty_cycles)
duty_cycle = duty_cycles(i);
square_wave = amplitude * square(2 * pi * frequency * t, duty_cycle);

% Plot time domain signal


subplot(3, 2, 2 * i - 1);
plot(t, square_wave);
title(['Square Wave - Duty Cycle-2200040161: ' num2str(duty_cycle * 100) '%']);
xlabel('Time (s)');
ylabel('Amplitude');
% (e) Plot frequency spectrum

subplot(3, 2, 2 * i);
fft_square_wave = fft(square_wave);
frequencies = linspace(0, Fs, length(fft_square_wave));
plot(frequencies(1:length(frequencies)/2),
abs(fft_square_wave(1:length(frequencies)/2)));
title(['Frequency Spectrum - Duty Cycle-2200040161: ' num2str(duty_cycle * 100)
'%']);
xlabel('Frequency (Hz)');
ylabel('Magnitude');

% (f) Comment on the shape of the spectrum


% Provide comments based on the observed spectrum shape
if duty_cycle == 0.1
comment = 'The spectrum shows a strong emphasis on lower harmonics.';
elseif duty_cycle == 0.25
comment = 'The spectrum exhibits a balanced distribution of harmonics.';
elseif duty_cycle == 0.8
comment = 'The spectrum places more emphasis on higher harmonics.';
end
annotation('textbox', [0.2, 0.01, 0.6, 0.05], 'String', comment, 'FitBoxToText',
'on', 'EdgeColor', 'none');
end

result:
Digital Communication Lab, Dept. of ECE, KLEF Deemed to be University, A.P., India.

2.3. Square pulse and its Spectrum

The mathematical representations and corresponding graph are illustrated below:

 A,
 t FT   
x(t)   2 2  X ( j)  A  sinc 
 0, Elsewhere  2 

WE:5. Generate 2 seconds of a square pulse with a sample rate of 10 kHz and a width of 20 ms.

clear; close all; clc;


Fs = 10000;
t = -1:1/Fs:1;
% t = -0.5:1/Fs:0.5;
m = rectpuls(t,20e-3);

figure();
subplot(2,1,1);
plot(t,m,'b','LineWidth',2)
axis([-0.1 0.1 -0.2 1.2])
xlabel('Time (sec)');ylabel('Amplitude');
title('Rectangular Aperiodic Pulse');

% Spectrum of Square pulse -----


N = length(m);
f = (1/N)*(-N/2:1:(N/2)-1)*Fs; % Frequency scale
M = (2/N)*fftshift(fft(m)); % FT of the message signal

% Plotting the Spectrum of Rectaangular Pulse


subplot(2,1,2);
plot(f,abs(M)/max(M),'m','Linewidth',2);
xlabel('frequency'); ylabel('Magnitude|');
title('Spectrum of Rectangular Pulse'); grid on
axis([-500 500 -0.2 1.1]); % for 400 Hz
Digital Communication Lab, Dept. of ECE, KLEF Deemed to be University, A.P., India.

Task5: Develop Matlab code to generate a 1 second square pulse and its spectrum with the following Pulse
width:
(i) 10 ms, (ii) 50 ms (iii) 80 ms.
(a) Plot the signals in time domain for the above pulse width and analyze the results.
(b) Plot the spectra for the above signals and analyze the results. .
Choose appropriate sampling frequency.
Code:

clear;
close all;
% Define parameters
duration = 1; % 1 second duration
sampling_freq = 10000; % Sampling frequency (10 kHz)
time = 0:1/sampling_freq:duration-1/sampling_freq; % Time vector
% Pulse widths
pulse_widths = [0.01, 0.05, 0.08]; % Pulse widths in seconds
% Initialize figure for time domain plots
figure;
% Generate and plot square pulses in time domain
for i = 1:length(pulse_widths)
pulse_width = pulse_widths(i);

% Create square pulse


square_pulse = square(2*pi*(1/pulse_width)*time);

subplot(length(pulse_widths), 1, i);
plot(time, square_pulse);
title(['Square Pulse - Width:2200040248' 'ms']);
xlabel('Time (s)');
ylabel('Amplitude');
ylim([-1.5 1.5]);
grid on;
end
% Calculate and plot spectra
Digital Communication Lab, Dept. of ECE, KLEF Deemed to be University, A.P., India.

figure;
for i =
pulse_width =
square_pulse =
spectrum =
freq = linspace(0, sampling_freq, length(square_pulse)); % Frequency vector

subplot(length(pulse_widths), 1, i);

stem(freq(1:round(length(square_pulse)/2)), spectrum(1:round(length(square_pulse)/2)));
title(['Spectrum - Width:2200040248' ' ms']);

xlabel('Frequency (Hz)');
ylabel('Amplitude');
xlim([0 500]);
grid on;
end

Result:

2.4. Sinc Function (Duality of Rectangular pulse).and its Spectrum.

The mathematical representations and corresponding graph are illustrated below:


sin  t
A sinc function is represented by .

sinc(t)
t

1 
 Aw Sa  wt FT
A rect 

2  2 

w
Digital Communication Lab, Dept. of ECE, KLEF Deemed to be University, A.P., India.

WE:6. Develop Matlab code to generate a sinc pulse and its spectrum. Consider a frequency of 500 Hz.

clear; close all; clc; Ts = 0.001; Fs = 1/Ts; t = (-pi:0.001:pi)/100;


j = sqrt(-1);
A = 1; f = 500;
m = A*sin(2*pi*f*t)./(2*pi*f*t);

figure(); subplot(2,1,1);
plot(t,m,'m','LineWidth',3);%grid on
xlabel('time ----->');ylabel('Amplitude >');
title('Sinc(2*pi*f*t)2200040248');

% Spectrum of Square pulse -----


N = length(m);
f = (1/N)*(-N/2:1:(N/2)-1)*Fs; % Frequency scale
M = (2/N)*fftshift(fft(m)); % FT of the message signal

% Plotting the Spectrum of Rectaangular Pulse subplot(2,1,2);


plot(f,abs(M)/max(abs(M)),'k','Linewidth',2); xlabel('frequency');
ylabel('Magnitude|'); title('Spectrum of Rectangular Pulse'); grid on axis([-50 50
-0.1 1.1]); % for 400 Hz
Digital Communication Lab, Dept. of ECE, KLEF Deemed to be University, A.P., India.

Task6: Develop Matlab code to generate a sinc pulses and their spectrum with the following frequencies:
(i) 50 Ha (ii) 1000 Hz (iii) 10 KHz.
(a) Plot the signals in time domain for the above frequencies and analyze the results.
(b) Plot the spectra for the above signals and analyze the results. Code:

% Parameters
frequencies = [50, 1000, 10000]; % Frequencies in Hz
Fs = 5000; % Sampling frequency in Hz
t = -0.02:1/Fs:0.02; % Time vector from -0.02 to 0.02 seconds
% (a) Plot the signals in time domain
figure;
for i = 1:length(frequencies)
frequency = frequencies(i);
sinc_pulse = sinc(2 * frequency * t);
% Plot time domain signal
subplot(3, 2, 2 * i - 1);
plot(t, sinc_pulse);
title(['Sinc Pulse - Frequency-2200040248: ' num2str(frequency) ' Hz']);
xlabel('Time (s)');
ylabel('Amplitude');
end
% (b) Plot the spectra
for i = 1:length(frequencies)
frequency = frequencies(i);
sinc_pulse = sinc(2 * frequency * t);
% Plot frequency spectrum
subplot(3, 2, 2 * i);
fft_sinc_pulse = fftshift(fft(sinc_pulse));
frequencies = linspace(-Fs/2, Fs/2, length(fft_sinc_pulse));
plot(frequencies, abs(fft_sinc_pulse));
title(['Frequency Spectrum - Frequency-2200040248: ' num2str(frequency) ' Hz']);
xlabel('Frequency (Hz)');
ylabel('Magnitude');
end

Result
Digital Communication Lab, Dept. of ECE, KLEF Deemed to be University, A.P., India.

2.5. Triangular pulse and its Spectrum:

The mathematical representations and corresponding graph are illustrated below:

2t 1,  21  t  0
 FT   
x(t)  2t 1, 0  t  1     X ( j)  sinc2
2  
 2
0,  
 Elsewhere

WE.7 Generate 2 seconds of a Triangular pulse with a sample rate of 10 kHz and a width of 20 ms.

clear; close all; clc;


Fs = 10000;
t = -1:1/Fs:1;
m = tripuls(t,20e-3);

figure();
subplot(2,1,1);
plot(t,m,'r','LineWidth',2)
axis([-0.1 0.1 -0.2 1.2])
xlabel('Time (sec)')
ylabel('Amplitude')
title('Triangular Aperiodic Pulse')

% Spectrum of Periodic pulse train-----


N = length(m);
f = (1/N)*(-N/2:1:(N/2)-1)*Fs; % Frequency scale
M = (2/N)*fftshift(fft(m)); % FT of the message signal

% Plotting the Spectrum of Triangular Pulse


subplot(2,1,2);
plot(f,abs(M/max(M)),'r','Linewidth',2);
xlabel('frequency'); ylabel('Magnitude|');
title('Spectrum of Triangular Pulse'); grid on
axis([-500 500 0 1.1]); % for 400 Hz
Digital Communication Lab, Dept. of ECE, KLEF Deemed to be University, A.P., India.

Task7: Develop Matlab code to generate a 1 second triangular pulse and its spectrum with the following
Pulse width:
(i) 10 ms, (ii) 50 ms (iii) 80 ms.
(c) Plot the signals in time domain for the above pulse width and analyze the results.
(d) Plot the spectra for the above signals and analyze the results.

Code:
% Define parameters
Fs = 1000; % Sampling frequency (1 kHz)
t = 0:1/Fs:1; % Time vector for 1 second
f = (-Fs/2:Fs/length(t):Fs/2-Fs/length(t)); % Frequency vector for FFT

% Generate triangular pulses for different pulse widths


pulse_widths = [0.01, 0.05, 0.08]; % Pulse widths in seconds

figure;

for i = 1:length(pulse_widths)
% Generate triangular pulse
pulse = sawtooth(2*pi*10*t, pulse_widths(i)) * (2/pulse_widths(i)) - 1;

% Plot the signal in time domain


subplot(length(pulse_widths), 2, 2*i - 1);
plot(t, pulse);
title(['Triangular Pulse - Width:2200040248 ' num2str(pulse_widths(i)*1000) 'ms']);
xlabel('Time (s)');
ylabel('Amplitude');
Digital Communication Lab, Dept. of ECE, KLEF Deemed to be University, A.P., India.

% Calculate FFT of the pulse


pulse_fft = fftshift(fft(pulse)/length(pulse));

% Plot the spectrum


subplot(length(pulse_widths), 2, 2*i);
plot(f, abs(pulse_fft));
title('Frequency Spectrum');
xlabel('Frequency (Hz)');
ylabel('Magnitude');
xlim([-50 50]); % Limiting the x-axis to better visualize the spectrum
end

sgtitle('Triangular Pulse and Spectrum for Different Pulse Widths');

Result:

2.3.
2.4. Gaussian pulse and its Spectrum
The mathematical representations and corresponding graph are illustrated below:
Digital Communication Lab, Dept. of ECE, KLEF Deemed to be University, A.P., India.

.WE8: Develop Matlab code to generate a Gaussian pulse and its spectrum with sigma = 0.05 .

clear; close all; clc;


Fs=80; %sampling frequency
sigma = 0.05;
t=-0.5:1/Fs:0.5; %time base
variance=sigma^2;
m=1/(sqrt(2*pi*variance))*(exp(-t.^2/(2*variance)));

figure();
subplot(2,1,1);
plot(t,m,'b','LineWidth',2);
title(['Gaussian Pulse \sigma=', num2str(sigma),'s']);
xlabel('Time(s)'); ylabel('Amplitude');

% Spectrum of Square pulse -----


N = length(m);
f = (1/N)*(-N/2:1:(N/2)-1)*Fs; % Frequency scale
M = (2/N)*fftshift(fft(m)); % FT of the message signal

% Plotting the Spectrum of Rectaangular Pulse


subplot(2,1,2);
plot(f,abs(M)/max(M),'m','Linewidth',2);
xlabel('frequency'); ylabel('Magnitude|');
title('Spectrum of Gaussian Pulse'); grid on
axis([-50 50 -0.1 1.1]); % for 400 Hz
Digital Communication Lab, Dept. of ECE, KLEF Deemed to be University, A.P., India.

Task8: Develop Matlab code to generate a Gaussian pulse and its spectrum with the following sigma
values:
(i) 0.005 (ii) 0.25 (iii) 0.5 (iv) 1
(a) Plot the signals in time domain for the above sigma values and analyze the results.
(b) Plot the spectra for the above signals and analyze the results. .

code:
clear;
% Time axis
t = -5:0.01:5;
% Sigma values
sigmaValues = [0.005 0.25 0.5 1];
figure;
for i = 1:length(sigmaValues)
sigma = sigmaValues(i);
% Generate Gaussian pulse
gaussianPulse = exp(-(t.^2) / (2 * sigma^2));
% Plot time domain signal
subplot(4, 2, 2*i - 1);
plot(t, gaussianPulse);
title(['Time Domain Signal with Sigma 2200040248 = ', num2str(sigma)]);
xlabel('Time (t)');
ylabel('Amplitude');
% Calculate and plot spectrum
G = fftshift(fft(gaussianPulse));
f = linspace(-1/0.01, 1/0.01, length(G));
subplot(4, 2, 2*i);
plot(f, abs(G));
title(['Spectrum with Sigma 2200040248 = ', num2str(sigma)]);
xlabel('Frequency (f)');
ylabel('Magnitude');
end

Result:

You might also like