Complex Engineering Problem
EE-322L Analog and Digital Communication Lab
Submitted To:
Dr. Imran Javed
Submitted By:
Usama
Roll Number :
2021-EE-185
Section :
B
___________________________________________________
Introduction
Just like AM modulation, there exists angle modulation techniques, which are FM and PM. In
these modulations, either the frequency or the phase of the transmitted signal change with the
amplitude of the message signal. In this complex engineering assignment, we are dealing with
FM modulation, where the instantaneous frequency of the transmitted signal is proportional to
the instantaneous amplitude of the message signal. This type of modulation is complex and
difficult to analyze. The bandwidth of the transmitted signal also expands, which can be many
times larger than that of the message signal. However, these problems are often outweighed by
the higher noise immunity of FM signal when compared to an AM signal.
Background
This technical background will be used as the basis for my implementation of FM modulation in
GNU Radio Companion and demodulator in MATLAB. In FM modulation, the transmitted
signal can be represented mathematically, as:
π‘
π’(π‘) = π΄π cosβ‘(2πππ π‘ + 2πππ ∫ π(π)ππ)
−∞
Where the carrier signal is
π(π‘) = β‘ π΄π cosβ‘(2πππ π‘)
And the message signal is
π(π‘) = cosβ‘(2πππ π‘)
So,
π‘
π‘
∫ π(π)ππ = ∫ cos(2πππ π) ππ
−∞
−∞
=β‘
sin(2πππ π‘)
2πππ
Hence, u(t) can be expressed as,
π’(π‘) = π΄π cosβ‘(2πππ π‘ + π½sin(2πππ π‘))
Where,
π½=
ππ
ππ
And is referred to as the modulation index of the FM signal.
Using Euler’s identity, u(t) can be expressed as,
π’(π‘) = π
π{π΄π π π2ππππ‘ π ππ½sinβ‘(2πππ π‘) }
Therefore, by multiplying the real parts of the carrier and the integral of the message signal, we
can generate an FM signal.
From the above discussion, it is clear that the message signal information lies in the frequency
variation of the FM signal. Therefore, to extract that information we can first pass this received
signal through a differentiator,
π
ππ‘
(π΄π cos(2πππ π‘ + π½sin(2πππ π‘))) = −π΄π sinβ‘(2πππ π‘ + π½sin(2πππ π‘)) × (2πππ +
2πππ π½πππ (2πππ π‘))
To get rid of the positive negative oscillations, due to the sinusoidal expressions in the output, we
can take the modulus of this signal, which will give us the envelope of frequency variation of the
FM signal.
Afterwards, a low pass filter can be used to remove the frequency varying FM component from
differentiator output, passing only the constant frequency part, which corresponds to our message
signal and also a DC component due to the carrier response. This DC component can be
neutralized by giving an equal negative offset, resulting in our demodulated signal.
Task 1 – FM Modulator in GNU Radio Companion
Flowchart:
Explanation:
As discussed earlier, the final modulated signal is of the form:
π’(π‘) = π΄π cosβ‘(2πππ π‘ + π½sin(2πππ π‘))
Which can also be expressed as
π’(π‘) = π
π{π΄π π π2ππππ‘ π ππ½ sin(2πππ π‘) }
The sin(2πππ π‘)) is generated by the first signal source block, where the default frequency is set
as 5 kHz, amplitude as 1 and the sampling rate to 500 kHz. The default value of π½ in this case is
taken as 4 which is represented by the multiplying constant, to which the 5 kHz sine wave is
passed.
The QT GUI Range blocks, with ID’s, mess_freq and beta, are used to vary the frequency, of the
message signal and π½, during runtime. A throttle block is used to limit the processing rate of the
signal by CPU, since there is no upper limit, because no hardware is being used.
The phase mod block is used to phase modulate the sin signal, essentially generating a signal
which can be expressed mathematically as, π ππ½ sin(2πππ π‘) , using Euler’s identity. The second
signal source block is used to generate the carrier signal, which is a cosine, with default
frequency 25 kHz and amplitude 1, for simplicity. The carrier frequency can also be changed
during runtime because of the QT GUI Range block with ID carr_freq. This signal can also be
expressed as Re{π π2ππππ‘ }. However, since the output of phase mode is a complex signal, and we
want to multiply that signal with our carrier, the output of the signal block is also set as complex.
Afterwards, the multiply block is used to multiply the two signals, which is then passed through
a complex to real block, to get u(t), as expressed in the above equation.
Time Domain signal for m(t) (default value):
Time Domain signal for u(t) (default values):
Frequency Domain signal for u(t) (default values):
,
The carrier frequency is located at 25 kHz and -25 kHz (mathematical representation). The
sidebands are located symmetrically around the carrier frequency. Lower side band ranges for
values below 25 kHz and upper band for frequencies beyond 25 kHz.
The harmonics of the sideband are therefore located at integer multiples of message frequency,
around the carrier frequency, as follows
First order sideband: 25 – 5, 25 + 5 = 20 kHz, 30 kHz
Second order sideband: 25 – 2(5), 25 + 2(5) = 15 kHz, 35 kHz
Nth order sideband: 25 – n(5), 25 + n(5)
By looking at the diagram, the upper band is located at frequencies ranging mainly from 25kHz
to 75 kHz, so effective bandwidth is approximately 50 kHz.
According to Carson’s rule, the effective bandwidth B is given as,
π΅ = 2(βπ + β‘ ππ )
Where
βπ = β‘π½ × ππ
So,
βπ = 4β‘ × 5 = 20β‘ππ»π§
Hence, B = 2(20 + 5) = 50 kHz.
Effect of changing modulation index:
π· = π. π:
π· = π:
π· = π:
π· = π:
π· = π:
For smaller values of π½, the frequency deviations are smaller, so the harmonics in the frequency
spectrum are packed together closely. The number of harmonics in the side bands are also fewer.
As the modulation index increases, the deviations in frequency increase, increasing effective
bandwidth and also the number of harmonics in the sidebands.
Task 2 – Implementing a FM demodulator in MATLAB
Block Diagram of Receive Chain:
Differentiator
• Evaluates rate of
change of FM
signal, to map it
with amplitude
variation
Rectifier
• Rectifies the
signal, giving a
frequency
deviation
envelop
Butterworth
Filter
• Smoothens the
curve by
removing high
frequency
components
Negative DC
offset
MATLAB code:
% Specify file name and parameters
filename = 'FM_TX_Coine.dat';
fs = 500e3; % Sampling frequency used in GNU Radio
% Open the file
fid = fopen(filename, 'rb');
% Read the data (adjust data type as per the file sink settings)
fm_signal = fread(fid, 'float32');
% Close the file
fclose(fid);
% Time-domain plot
figure;
t1 = (0:length(fm_signal)-1) / fs;
plot(t1, fm_signal);
xlim([0, 0.002]);
ylim([-1.5, 1.5]);
xlabel('Time (s)');
ylabel('Amplitude');
title('FM Signal Generated in GNURadio');
grid on;
% Demodulation
% Differentiating the FM signal, to map frequency change to amplitude
x = diff(fm_signal);
% Rectification, so amplitude is proportional to only magnitude of frequency
deviations
y = abs(x);
% Low pass filter to remove high frequency noise and smoothen the demodulated signal
[b, a] = butter(10, 0.056);
demodulated_signal = filter(b, a, y);
% Removing firstfew samples
demodulated_signal = demodulated_signal(100000:length(demodulated_signal));
% Removing DC component
avg = (max(demodulated_signal) + min(demodulated_signal))/2;
demodulated_signal = demodulated_signal - avg;
t2 = (0:length(demodulated_signal)-1)/fs;
figure;
plot(t2, demodulated_signal);
xlim([0, 0.002]);
xlabel('Time (s)');
ylabel('Amplitude');
title("Demodulated signal and Message signal");
grid on;
hold on;
m_t = cos(2*pi*5000*t2);
plot(t2, m_t);
legend('Demodulated Signal', 'Message signal)');
N = length(demodulated_signal); % Number of samples in the signal
% Compute the FFT of the demodulated signal
demod_fft = fft(demodulated_signal);
% Compute the frequency axis
frequencies = (-N/2:N/2-1) * (fs / N); % Frequency vector (including negative
frequencies)
% Shift the FFT output to center the zero frequency
demod_fft_shifted = fftshift(demod_fft);
% Take the magnitude of the shifted FFT and normalize it
magnitude = abs(demod_fft_shifted) / N;
% Plot the frequency spectrum
figure;
plot(frequencies, magnitude);
xlim([-10e3, 10e3]);
ylim([0, 0.1]);
title('Frequency Spectrum of the Demodulated Signal');
xlabel('Frequency (Hz)');
ylabel('Magnitude');
grid on;
% Normalizing the demodulated signal to the range [-1, 1]
demod_normalized = demodulated_signal / max(abs(demodulated_signal));
% Save the normalized signal as a .wav file
filename = 'FM_RX_sine.wav';
audiowrite(filename, demod_normalized, fs);
disp(['Audio file saved as: ', filename]);
Demodulated signal (Time Domain):
First few samples of demodulated signal were rejected, hence the apparent phase shift. Some of
the energy was lost during demodulation process, resulting in smaller amplitude. Rest, the
frequency of the signal is preserved.
Demodulated signal (Frequency Domain):
The spectrum contains two equal components at -5 and +5 kHz, as it should for a cosine wave at
5 kHz.