
FREQUENCY MODULATIONS
Frequency modulations are techniques in which the information is encoded in a carrier wave by varying its frequency in time. Unlike analog versions, in digital frequency modulations the frequency shifts can assume only a fixed number of values (related to the modulation order) and their variations occur only at multiples of the symbol period.
In this project, after a short recap of general theory, the basic digital frequency modulations are discussed and analyzed. First, a MATLAB custom script for implementing digital frequency modulators (without employing any of its built-in functions) is proposed. Then, the same algorithm is adapted for a much more efficient C/C++ implementation and validated by means of an SDR, a transceiver IC and a GNU Radio script. Finally, the algorithm and all the generated plots are transposed in Python, providing also a practical example of Graphical User Interface (GUI) to smartly handle simulations.
The general form of a radio-frequency (RF) modulated signal can be expressed as

where α(t), δ(t) and ϕ(t) represent respectively the amplitude [V|A], frequency [Hz] and phase [rad] variations of the sinusoid in time and FC the carrier frequency [Hz].
Another important equation relates the RF signal to its baseband (BB) equivalent as

While SRF(t) depicts the physical E/M waveform travelling over the channel and thus assumes only real (R) values, SBB(t) is introduced as a mathematical representation of the RF signal before the in-phase/quadrature (I/Q) up-conversion (i.e. the multiplication by the unmodulated RF sinusoid at frequency FC and by its 90° delayed version) and assumes complex (C) values. Developing Eq.2 by means of the Euler’s formula (i.e. e^(ix) = cosx + i·sinx), it gives

where I(t) and Q(t), both ∈ R, are defined respectively as the real and imaginary part of SBB(t). An example of up-converter block diagram is depicted in Fig.1.

Fig.1 - Up-conversion scheme
In case of Frequency Shift Keying (FSK) modulation, the RF signal consists of a sinusoid with constant amplitude and phase but time-varying frequency, where the latter varies in correspondence of symbol period (Ts) changes, assuming discrete values as a function of the modulation order (M), the inner deviation (dev, i.e the shift absolute value [Hz] between FC and the closest tone among the M available) and the input bits. In particular, the modulating parameters of Eq.1 for the FSK case become

and so, keeping in mind the trigonometric relation cos(x+y) = cosx·cosy - sinx·siny, Eq.1 can be written as

Now comparing the equation just above with Eq.3, it can be easily found out that the FSK equivalent baseband signal has respectively real and imaginary parts

The scheme of a typical FSK modulator is shown in Fig.2, where the blocks MAP and SMP represent respectively the mapper (to convert the input bits into constellation symbols, generally following a Gray coding) and resampler (to pass from symbols to PCM samples by specifying the oversampling factor osf) blocks, whereas the values within square brackets indicate the data rate at specific points of the diagram. In particular, Rs represents the symbol rate [S/s], in turn linked to the bit rate [b/s] (Rb) and Ts respectively by the relations Rb = Rs · log2(M) and Rs = 1/Ts.
Clearly, at the expense of a wider bandwidth allocation (see Eq.4), the higher the deviation the more robust and reliable the link becomes, since the receiver can better distinguish the transmitted tones and counteract non-ideal effects, such as Doppler shifts.

Fig.2 - FSK baseband modulator scheme
Another important parameter for digital modulations is the modulation index (h), which specifically for frequency ones is defined as

By choosing h ∉ N, both baseband and bandpass FSK waveforms exhibit strong first-order phase discontinuities every Ts seconds, causing an evident bandwidth widening. Continuous Phase Frequency Shift Keying (CPFSK) modulation employs an integrator in order to assure phase continuity and reduce bandwidth occupation, as depicted from the modulator scheme of Fig.3. The real and imaginary parts of the CPFSK equivalent baseband signal can be expressed as

By choosing M = 2 and h = 0.5, a special case of CPFSK modulation is obtained, known as Minimum Shift Keying (MSK). The name stems from the fact that this is the frequency modulation with minimum tone spacing, and therefore best spectral efficiency, such that orthogonality is still guaranteed in case of coherent detection (i.e. carrying out carrier phase recovery) on RX side. In fact, the condition to assure orthogonality between the modulating tones, which is to say absence of intersymbol interference (ISI) at the times symbols are sampled, is respectively 2h ∈ N and h ∈ N for coherent and non-coherent detection [1].

Fig.3 - CPFSK baseband modulator scheme
In order to further compact the signal spectral components, an extra filtering stage can be added to the CPFSK modulator scheme of Fig.3, just before the integrator. This way, even the second-order discontinuities of the waveform are removed, causing a bandwidth restraint. A Gaussian filter (i.e. a filter with an approximately Gaussian shaped impulse response) is typically employed for this purpose, resulting in the corresponding modulation to be called Gaussian Frequency Shift Keying (GFSK), whose scheme is summarized in Fig.4. A basic parameter for the Gaussian filter design is the bandwidth-time product (BT), which defines the relation between the period of each symbol Ts and the bandwidth allocated to it (in terms of 3dB bandwidth). In particular, this indicates that each symbol will be spread over 1/BT symbol periods. Therefore, the lower the BT factor the narrower the bandwidth (due to a wider filter impulse response) at the expense of a stronger ISI. For instance, BT = 0.2 means that the waveform representation of every symbol will be spread over five consecutive symbol periods, causing interference to the four adjacent symbols. Typical BT factor values range from 0.3 to 0.5. The real and imaginary parts of the GFSK equivalent baseband signal can be expressed as

where g(t) is the impulse response of the Gaussian filter. It is worth noting that by adding this Gaussian filtering stage to the aforementioned MSK modulation, the result is the Gaussian Minimum Shift Keying (GMSK) modulation, popular for many applications such as GSM.

Fig.4 - GFSK baseband modulator scheme
The bandwidth occupation of a digital frequency modulation can be approximately estimated by means of the Carson’s rule (returning the spectral range in which the 98% of the signal energy is contained) as

Actually the real form of the Carson's rule (applying for FM modulation) is BW = 2(Δf + fm), where Δf represents the peak frequency deviation and fm the modulating signal highest frequency. The conversion from the original analog expression to the digital of Eq.4 is rather straightforward by considering that in the latter case Δf = dev and fm = Rs/2 (since the modulating square wave period is double the symbol time). In Eq.4 dev' represents the maximum outer deviation (for the general case where M can be greater than 2). Moreover, keep in mind the expression yields a slight overestimation of the actual occupied bandwidth in case of Gaussian filtering.
Another interesting bandwidth formula is BW' = 2dev + 2Rs, which gives the frequency distance between the first right and left notches in the modulated spectrum (as depicted in the following MATLAB and Python images).
Finally, it is important to remember that even though reducing the bandwidth occupation by avoiding waveform discontinuities (for a fixed Rs and dev) is generally something desirable, this has the disadvantage of making the tone detection harder on RX side, since the symbol transitions of the waveform become smoother due to the filtering stages in transmission. Therefore, a trade-off between these two aspects must be always kept in mind.
The FSK, CPFSK and GFSK modulators developed in MATLAB allow to set all the main parameters aforementioned (e.g. bit-rate, modulation order, modulation index, BT factor, ecc...). After estimating the waveform samples, the script displays the obtained time and frequency-domain signals at both baseband and radio-frequency. An example of the graphical results is reported in Fig.5, Fig.6 and Fig.7 respectively for the FSK, CPFSK and GFSK cases. Here, the modulation of 480 random bits (with Rb = 10 kb/s, M = 4, h = 1.1 and Fc = 10 MHz and Gray bit-to-symbol coding) has been simulated. As can be seen from Fig.5, since the selected h is not integer the FSK waveform presents strong first-order discontinuities, which in turn badly affect bandwidth occupation. As expected, these discontinuities are avoided by CPFSK and then made further softened by GFSK, causing the spectrum side-lobes to decrease much more quickly.

Fig.5 - FSK modulation example (MATLAB)

Fig.6 - CPFSK modulation example (MATLAB)

Fig.7 - GFSK modulation example (MATLAB)
As second step, all the code has been transposed in Python language, which also provides smart libraries to reproduce graphs just as the ones generated in MATLAB. Examples of Python plots are displayed in Fig.8, Fig.9 and Fig.10. Moreover, in order to make the simulations more straightforward a practical GUI has been developed in Tkinter. Fig.11 shows the GUI before and after running. This is composed of four sections: the first one (PARAMETERS) allows the user to set the main simulation parameters discussed above, the second (OPTIONS) dedicated to the choice of the desired processing options by means of checkboxes, the third (KEYS) contains the three buttons to run simulations and clear messages window / generated plots, and the fourth (MESSAGES) shows a dialogue window where the simulation progress as well as the main parameters / constants are recapped.

Fig.8 - FSK modulation example (Python)

Fig.9 - CPFSK modulation example (Python)

Fig.10 - GFSK modulation example (Python)

Fig.11 - Tkinter / Python GUI
After the MATLAB and Python implementations, the modulator algorithms have been then adapted for C/C++ language, making it much more efficient and compatible for microcontroller operation. This C/C++ code implements the same processing steps of the MATLAB / Python one, allowing to perform FSK, CPFK and GFSK modulations (again by specifying all the key parameters) and producing exactly the same results.
Moreover, all three scripts provide a dedicated function in charge of storing the calculated baseband complex samples in a binary file in order to be validated by means of an additional hardware chain. For instance, in this case the combination of a software-defined radio (SDR), a commercial transceiver and the free and open-source GNU Radio software has been successfully used to validate the proper operation of the modulators. In particular, a USRP N210 SDR by Ettus Research (mounting an SBX daughterboard, see Fig.13) is driven by a simple GNU Radio script (whose flowgraph is reported in Fig.12) to load and up-convert at 435 MHz the baseband complex samples stored in the binary files. Then, the RF signal outgoing from the SDR is given as input (via cable or antenna) to the receiving device (a development kit equipped with a CC1101 transceiver by Texas Instrument, which can be programmed for FSK, GFSK or MSK modulation, see Fig.14) to check the correct demodulation of the original bits, and in turn validate the modulator quality.
Since the baseband sample rate (Fs) in the modulators software is set as the bit-rate selected by the user times a modifiable integer over-sampling factor (osf) but hardware devices (such as SDRs) generally work only at specific sample rates (e.g. 250 kSa/s, 500 kSa/s, etc... for the USRP N210), a resampling stage is needed before creating the binary file and interfacing with the GNU Radio script. A standard linear interpolating function has been written in order to match the SDR-imposed sample rates with more than sufficient accuracy. Moreover, in both MATLAB and C/C++ projects it is proposed a formula for estimating the optimal osf value (related to a specific SDR Fs) to be chosen in order to get the best compromise between limiting the computational complexity and minimizing the baseband waveform noise due to resampling.

Fig.12 - GNU Radio flowgraph for SDR up-conversion

Fig.13 - USRP N210

Fig.14 - CC1101DK433
Below there the links through which the aforementioned codes can be free downloaded. For further details and explanations about the practical implementation of the modulators take a look at the comments within these files.
-
Download MATLAB project : FreqMods.m
-
Download C/C++ project : FreqMods.cpp
-
Download GNUR project : FreqMods.grc
-
Download Python / GUI project : FreqMods_Py.zip
NOTE#1: The Tkinter GUI has been implemented with the aid of PAGE (version 5.3) and ActiveTcl (version 8.6).
WARNING#1: The FreqMods.m and FreqMods.grc projects have been developed in MATLAB R2017a and GNU Radio Companion 3.7.9. Therefore, the correct operation of the script may not be assured for different software versions.
WARNING#2: The FreqMods.py projects have been developed in Python 3.8.3 with the addition of the scipy and matplotlib libraries (available via pip). Therefore, the correct operation of the script may not be assured for different software versions. However, the GUI project has been also converted into an exe application by means of the pyinstaller library, making it available and usable even for users without Python.
Last update : 21/06/2020
References
[1] B. Sklar, P. K. Ray, Digital Communications, Chap. 4-9, Pearson Education, 2012.
[2] Wikipedia - Frequency-shift keying (link/a)