Analogue and Digital Communication Lab
(EL-3003)
LABORATORY MANUAL
Engr. Fakhar Abbas
Review of Signals in Time and Frequency Domain and
MORSE CODE Communication System
(LAB # 01)
Student Name: MUHAMMAD SARMAD FOWAD
Roll No:22i-2222 Section: A Marks________/10
Date performed: 08 AUG, 2024
____________________________________________________________________________________________________________________________________________________________
NATIONAL UNIVERSITY OF COMPUTER AND EMERGING SCIENCES, ISLAMABAD
Prepared by: Engr. M. Asim, Engr. Ihtisham Khalid Version: 2.01
Last Edited by: Engr. Fakhar Abbas
Verified by: Updated: Fall 2024
Dr. Shahzad Saleem
Analogue and Digital National University Roll No: 22i-2222 L
Communication Lab
(EL3003)
of Computer and Emerging Sciences
Islamabad Fall 2024
a
b
#
01
____________________________________________________________________________________
Lab # 01: Review of Signals in time and frequency domain and Morse
Code Transceiver
Learning Objectives:
1. Time and Frequency Domain Analysis of Sinusoidal functions
2. Implementation of Morse code Communication System in MATLAB
Equipment Required:
1. PC
2. MATLAB
Frequency Domain Representation (Magnitude Spectrum):
The frequency domain representation shows the frequency components of a signal. For example,
x=cos(2*pi*20*t); since x has a frequency of 20 Hz so frequency domain representation shows peaks at
−+ 20 Hz. Magnitude of any signal can be found by abs() command in Matlab.
Fourier analysis of a Periodic Signal using fft command:-
Fourier series provides an alternate way of representing data: instead of representing the signal amplitude
as a function of time, we represent the signal by how much information is contained at different
frequencies. If you ever watched the blinking lights on a stereo equalizer then you have seen Fourier
analysis at work. The lights represent whether the music contains lots of bass or treble. Fourier analysis
allows you to isolate certain frequency ranges. Fourier transform is
computed using fft command in discrete time.
FUNDAMENTAL PERIOD:-
The fundamental period is the smallest positive value of ‘T’ (continuous) or ‘N’ (discrete) for which the
equations of periodicity held.
Some Important Properties of Discrete Fourier Transform:
𝑛
For a discrete time signal 𝑥(𝑡), 𝑤ℎ𝑒𝑟𝑒 𝑡 = 𝑛 * 𝑇𝑠 = 𝐹 , its fourier transform would be 𝑋(𝑓).
𝑠
If 𝑥(𝑡) = 𝐴𝑚𝑐𝑜𝑠(2π𝑓𝑚𝑡) then 𝑋(𝑓) would be given as
𝐴𝑚
𝑋(𝑓) = 2 ( )
[δ 𝑓 − 𝑓𝑚 + δ(𝑓 + 𝑓𝑚)]
(
If 𝑥(𝑡) = 𝐴𝑚 cos 𝑐𝑜𝑠 2π𝑓𝑚𝑡 ) ( )
* 𝐴𝑐 cos 𝑐𝑜𝑠 2π𝑓𝑐𝑡 , assuming that 𝑓𝑐 > 𝑓𝑚 , then 𝑋(𝑓) would be given
as
𝑋(𝑓) =
𝐴𝑚*𝐴𝑐
4 (
[δ 𝑓 − (𝑓𝑐±𝑓 ) + δ(𝑓 + (𝑓𝑐±𝑓 ))]
𝑚
) 𝑚
If 𝑥(𝑡) = 𝐾 + 𝐴𝑚𝑐𝑜𝑠(2π𝑓𝑚𝑡), where K is DC component, then 𝑋(𝑓) would be given as
𝐴𝑚
𝑋(𝑓) = 𝐾 * δ(𝑓) + 2 ( )
[δ 𝑓 − 𝑓𝑚 + δ(𝑓 + 𝑓𝑚)]
_____________________________________________________________________________________________
Page 2 of 11
Analogue and Digital National University Roll No: 22i-2222 L
Communication Lab
(EL3003)
of Computer and Emerging Sciences
Islamabad Fall 2024
a
b
#
01
____________________________________________________________________________________
Note:- It means if we add a DC componet of magnitude K, there would appear an impulse of K amplitude
at 0 Hz in frequency spectrum.
Time domain and frequency domain analysis:-
Consider the following code to understand how a cosine signal of specific frequency is generated and plottd
in time domain and its spectrum in frequency domain.
clc;close all;clear all
Fs = 500; %sampling Frequency
f = 20; % Signal’s Frequency
N = 100; % Total number of samples
n = 0:N-1; % n represents sample number
T = 1/Fs; % T represents sampling interval i.e., time between 2 samples
t = n*T; % t = nTs = n/Fs
x = cos(2*pi*f*t);
Xk = fft(x)/N; % Computing fft
Y = abs(Xk);
X = fftshift(abs(Xk));
fx = -Fs/2:Fs/length(X):Fs/2-(Fs/length(X));
subplot(211)
plot(t,x,'linewidth',2);
grid on;
subplot(212)
stem(fx,X,'filled','linewidth',2);
grid on;
xlabel('-Fs/2 to Fs/2','fontweight','bold');
ylabel('|X(k)|','fontweight','bold');
title('Frequency Domain Spectrum');
_____________________________________________________________________________________________
Page 3 of 11
Analogue and Digital National University Roll No: 22i-2222 L
Communication Lab
(EL3003)
of Computer and Emerging Sciences
Islamabad Fall 2024
a
b
#
01
____________________________________________________________________________________
Pre-Task: Understanding fftshift () command:
Let 𝑥(𝑡) = 𝑐𝑜𝑠(2π2𝑡), where 𝑡 = 𝑛𝑇𝑠, 𝐹𝑠 = 10, and N=10 samples.
Write a Matlab code to compute dft using fft command . The objective of this task is to become familiar
with fftshift command. Your graphs should contain 3 subplots like this:
Matlab
Code:-
_____________________________________________________________________________________________
Page 4 of 11
Analogue and Digital National University Roll No: 22i-2222 L
Communication Lab
(EL3003)
of Computer and Emerging Sciences
Islamabad Fall 2024
a
b
#
01
____________________________________________________________________________________
Morse Code:
Morse code is a method of transmitting text information as a series of on-off tones, lights, or clicks that can
be directly understood by a skilled listener or observer without special equipment. It is named for Samuel F.
B. Morse, an inventor of the telegraph. The International Morse Code[1] encodes the ISO basic Latin
alphabet, some extra Latin letters, the Arabic numerals and a small set of punctuation and procedural
signals (prosigns) as standardized sequences of short and long signals called "dots" and "dashes",[1] or "dits"
and "dahs", as in amateur radio practice. Because many non-English natural languages use more than the 26
Roman letters, extensions to the Morse alphabet exist for those languages.
_____________________________________________________________________________________________
Page 5 of 11
Analogue and Digital National University Roll No: 22i-2222 L
Communication Lab
(EL3003)
of Computer and Emerging Sciences
Islamabad Fall 2024
a
b
#
01
____________________________________________________________________________________
TASK 01:
Consider two continuous-time signals 𝑚(𝑡) = cos 𝑐𝑜𝑠 (2π8𝑡) , 𝑐(𝑡) = cos 𝑐𝑜𝑠 (2π12𝑡) , are
converted to discrete-time signals with 𝑡 = 𝑛𝑇𝑠 (Sampling Time = 1/𝐹𝑠 ). Implement following
equation in Matlab, plot its time domain graph and magnitude spectrum. Select a suitable value for
𝐹𝑠 and 𝑁 (number of samples) .
𝑦(𝑡) = 𝑚(𝑡) + 𝑐(𝑡)
CODE:
clc;close all;clear all
Fs = 100; %sampling Frequency
N = 100; % Total number of samples
n = 0:N-1; % n represents sample number
Ts = 1/Fs; % T represents sampling interval i.e., time between 2 samples
t = n*Ts; % t = nTs = n/Fs
m = cos(2*pi*8*t);
c = cos(2*pi*12*t);
y=m+c;
Xk = fft(y)/N; % Computing fft
Y = abs(Xk);
X = fftshift(abs(Xk));
fx = -Fs/2:Fs/length(X):Fs/2-(Fs/length(X));
subplot(211)
plot(n,y,'linewidth',2);
grid on;
subplot(212)
stem(fx,X,'filled','linewidth',2);
grid on;
xlabel('-Fs/2 to Fs/2','fontweight','bold');
ylabel('|X(k)|','fontweight','bold');
title('Frequency Domain Spectrum');
_____________________________________________________________________________________________
Page 6 of 11
Analogue and Digital National University Roll No: 22i-2222 L
Communication Lab
(EL3003)
of Computer and Emerging Sciences
Islamabad Fall 2024
a
b
#
01
____________________________________________________________________________________
_____________________________________________________________________________________________
Page 7 of 11
Analogue and Digital National University Roll No: 22i-2222 L
Communication Lab
(EL3003)
of Computer and Emerging Sciences
Islamabad Fall 2024
a
b
#
01
____________________________________________________________________________________
TASK 02:
Let 𝑚(𝑡) = cos 𝑐𝑜𝑠 (2π30𝑡) , 𝑐(𝑡) = cos 𝑐𝑜𝑠 (2π400𝑡) , 𝑤ℎ𝑒𝑟𝑒 𝑡 = 𝑛𝑇𝑠
Implement following equation in Matlab, plot its time domain graph and magnitude spectrum.
Select a suitable value for 𝐹𝑠 and 𝑁 (number of samples) .
𝑦(𝑡) = (1 + 𝑚(𝑡)) * 𝑐(𝑡)
CODE:
clc;close all;clear all;
Fs = 1000; %sampling Frequency
N = 100; % Total number of samples
n = 0:N-1; % n represents sample number
Ts = 1/Fs; % T represents sampling interval i.e., time between 2 samples
t = n*Ts; % t = nTs = n/Fs
m=cos(2*pi*30*t);
c=cos(2*pi*400*t);
y=((1+m).*c);
subplot(211)
plot(t,y,'linewidth',2)
title('Time Domain Signal','fontweight','bold')
grid on
Xk = fft(y); % Computing fft
Y = abs(Xk);
X = fftshift(abs(Xk));
fx = -Fs/2:Fs/length(X):Fs/2-(Fs/length(X));
subplot(212)
stem(fx,X,'filled','linewidth',2);
grid on;
xlabel('-Fs/2 to Fs/2','fontweight','bold');
ylabel('|X(k)|','fontweight','bold');
title('Frequency Domain Spectrum','fontweight','bold');
_____________________________________________________________________________________________
Page 8 of 11
Analogue and Digital National University Roll No: 22i-2222 L
Communication Lab
(EL3003)
of Computer and Emerging Sciences
Islamabad Fall 2024
a
b
#
01
____________________________________________________________________________________
_____________________________________________________________________________________________
Page 9 of 11
Analogue and Digital National University Roll No: 22i-2222 L
Communication Lab
(EL3003)
of Computer and Emerging Sciences
Islamabad Fall 2024
a
b
#
01
____________________________________________________________________________________
TASK 03:
Decoding Morse Code: Since morse code for Letter “D” is “_..” which in binary form is
“1 1 1 0 1 0 1” since dot (.) represents one digt (1), space is equal to one 0 (zero) while dash (-) represents
three (3) ones. Your goal is to write a Matlab code that implements a Morse Code communication system
which includes a Transmitter (Tx), a Channel and a Receiver R(x). The Tx transmits an alphabet like D
(1110101) in the form of 𝑠(𝑡), channel will attenuate the message 𝑠(𝑡) by attenuation factor “α” and add a
random noise 𝑛(𝑡) such that message becomes 𝑟(𝑡) = α𝑠(𝑡) + 𝑛(𝑡). Rx will detect transmitted message by
applying some decision method. If message received correctly, Rx will display a message “Letter D
received correctly” otherwise it displays “Error Occured”. Vary SNR(Standard Deviation-> Sigma) and α
and comment on the results.
Note: Noise can be added in the signal by using ‘awgn’ command or ‘randn’ function. For further details use
MATLAB help. Usage of ‘randn’ function is given below:
𝑟 = 𝑎𝑡 * 𝑠 + 𝑠𝑖𝑔𝑚𝑎 * 𝑟𝑎𝑛𝑑𝑛(1, 𝑙𝑒𝑛𝑔𝑡ℎ(𝑠));
Example: Let s = [ 0 1]; at = 0.6, and let 𝑠𝑖𝑔𝑚𝑎 * 𝑟𝑎𝑛𝑑𝑛(1, 𝑙𝑒𝑛𝑔𝑡ℎ(𝑠)) = [0. 3 − 0. 2], 𝑡ℎ𝑒𝑛 𝑟 = [0. 3 0. 4]
You can set Threshold = 0.5 (Boundary Value) for the detection of the Error. Vary sigma like sigma 0.5 etc.
CODE:
clc,clear all;close all;
D=[1 1 1 0 1 0 1];
at=0.7;
std=0.2;
R=at*D + std*randn(1,length(D));
Z=abs(R)>=0.5
if (isequal(D,Z)==1)
display ('Letter "D" received correctly')
else
display ('Error occured')
_____________________________________________________________________________________________
Page 10 of 11
Analogue and Digital National University Roll No: 22i-2222 L
Communication Lab
(EL3003)
of Computer and Emerging Sciences
Islamabad Fall 2024
a
b
#
01
____________________________________________________________________________________
end
_____________________________________________________________________________________________
Page 11 of 11