4-FSK modulator and demodulator
In this example, we will look at working with 4-FSK (Frequency Shift Keying) in Engee. Frequency modulation is a type of modulation in which information is encoded by changing the frequency of a signal. 4-FSK, four–level frequency manipulation, is a type of modulation used in DMR (Digital Mobile Radio), and it is also optimal for use in PMR (Professional Mobile Radio) systems.
Each pair of information bits
defines a frequency shift relative to the carrier frequency.
The envelope in this type of modulation is constant, which provides significant advantages in terms of consumption and construction of the transmitter circuit:
there are no strict requirements to ensure the linearity of the transmission path. The bit encoding is performed based on the table below.
| Bit combination | The corresponding symbol (4-FSK) |
|---|---|
| 11 | 3 |
| 10 | 1 |
| 00 | -3 |
| 01 | -1 |
We will build a 4-FSK modulator and demodulator on the basic elements.
function run_model( name_model)
Path = (@__DIR__) * "/" * name_model * ".engee"
if name_model in [m.name for m in engee.get_all_models()] # Проверка условия загрузки модели в ядро
model = engee.open( name_model ) # Открыть модель
model_output = engee.run( model, verbose=true ); # Запустить модель
else
model = engee.load( Path, force=true ) # Загрузить модель
model_output = engee.run( model, verbose=true ); # Запустить модель
engee.close( name_model, force=true ); # Закрыть модель
end
sleep(5)
return model_output
end
The model contains two main units: a modulator and a demodulator. A bit stream is supplied at the input, after which we use a buffer to form packets of two samples and perform modulation and demodulation. In our example, the conditions for the operation of the modulator and demodulator are ideal: there is no communication channel and no interference.
Next, let's run the model and analyze the simulation results.
run_model("4fsk")
Let's compare the input group of bits with the output bits.
In_bit = collect(simout["4fsk/4-FSK demodulator.Out1"]);
Out_bit = collect(simout["4fsk/Buffer.1"]);
In_and_Out_bit = [In_bit.value Out_bit.value]
As we can see from the explicit comparison of the bit pairs, all sequences are recognized correctly. Now let's look at the numerical error rate in our model.
ErrorCnt = collect(simout["4fsk/SumError.ErrorCnt"]);
ErrorCnt = ErrorCnt.value;
print("Кол-во ошибок за всё время моделирования: $(ErrorCnt[end])")
Conclusion
The simulation results are as follows: the modulator and demodulator that we have implemented work correctly, without errors. This means that such an implementation can be applied to communication protocols, for example, DMR.