Professional Documents
Culture Documents
DC Skill Module Digital Communications
DC Skill Module Digital Communications
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.
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.
The Analysis and synthesis equations of a continuous time Fourier transform (CTFT) s defined as below:
jtdt
Analysis equation / forward FT: X ( j)
x(t) e
1
x(t)
Synthesis equation / inverse FT:
2 X ( j) e jtd
Magnitude and Phase spectrum:
X ( j) is complex in general and need two plots for its graphical representation
The graphical representation of sinusoidal signals is shown in Fig 2.1. A standard mathematical representation of
(b) sin(0t) FT
Aj ( 0 ) ( 0 )
Amplitude = 1 V, Frequency: 400 Hz, Develop Matlab code, simulate and display
% Generation and display of single tone message signal and its spectrum
% Message signal is a sinusoidal signal with frequency of 400 Hz.
%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;
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
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
(c) Suppose a phase of +pi/2 is added to the signal. Is there any change in the spectrum?
Code:
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');
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.
1, | t | 1
One period of square wave is represented by rect(t) 2
T tT
1 2 2
0, | t | 2
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
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.
1, | t | 1
One period of square wave is represented by rect(t) 2
T tT
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
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);
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.
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
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.
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');
result:
Digital Communication Lab, Dept. of ECE, KLEF Deemed to be University, A.P., India.
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.
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');
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);
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:
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.
figure(); subplot(2,1,1);
plot(t,m,'m','LineWidth',3);%grid on
xlabel('time ----->');ylabel('Amplitude >');
title('Sinc(2*pi*f*t)2200040248');
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.
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.
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')
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
figure;
for i = 1:length(pulse_widths)
% Generate triangular pulse
pulse = sawtooth(2*pi*10*t, pulse_widths(i)) * (2/pulse_widths(i)) - 1;
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 .
figure();
subplot(2,1,1);
plot(t,m,'b','LineWidth',2);
title(['Gaussian Pulse \sigma=', num2str(sigma),'s']);
xlabel('Time(s)'); ylabel('Amplitude');
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: