Skip to main content

MATLAB code for MSK



 Copy the MATLAB Code from here

 

MATLAB Code 

clc;
clear;
close all;

% Define a bit sequence
bitSeq = [0, 1, 0, 0, 1, 1, 1, 0, 0, 1];

% Perform MSK modulation
[modSignal, timeVec] = modulateMSK(bitSeq, 10, 10, 10000);

% Plot the modulated signal
subplot(2,1,1);
samples = 1:numel(bitSeq);
stem(samples, bitSeq);
title('Original message signal');
xlabel('Time (s)');
ylabel('Amplitude');

% Plot the modulated signal
subplot(2,1,2);
samples = 1:10000;
plot(samples / 10000, modSignal(1:10000));
title('MSK modulated signal');
xlabel('Time (s)');
ylabel('Amplitude');

% Perform MSK demodulation
demodBits = demodMSK(modSignal, 10, 10, 10000);

% Function to perform MSK modulation
function [signal, timeVec] = modulateMSK(bits, carrierFreq, baudRate, sampleFreq)
% Converts a binary bit sequence into an MSK-modulated signal
% Inputs:
% bits - Binary input sequence
% carrierFreq - Carrier frequency
% baudRate - Symbol rate
% sampleFreq - Sampling frequency
% Outputs:
% signal - Modulated MSK signal
% timeVec - Corresponding time vector

% Convert bits to NRZ format (-1, 1)
diffEncBits = 2 * bits - 1;
diffEncBits = [-1, diffEncBits]; % Append initial value

% Define time parameters
numBits = length(bits);
symbDur = 1 / baudRate;
timeVec = 0:1/sampleFreq:numBits * symbDur - (1/sampleFreq);

% Compute phase shifts
phaseShift = zeros(1, numBits + 1);
for idx = 2:numBits+1
phaseShift(idx) = mod(phaseShift(idx-1) + ((pi * idx) / 2) * (diffEncBits(idx-1) - diffEncBits(idx)), 2 * pi);
end
phaseShift = phaseShift(2:end);
diffEncBits = diffEncBits(2:end);

% Generate MSK waveform
symbolIdx = floor(timeVec / symbDur) + 1;
signal = cos(2 * pi * (carrierFreq + diffEncBits(symbolIdx) / (4 * symbDur)) .* timeVec + phaseShift(symbolIdx));
end

% Function to perform MSK demodulation
function bitSeq = demodMSK(signal, carrierFreq, baudRate, sampleFreq)
% Recovers a binary bit sequence from an MSK-modulated signal
% Inputs:
% signal - MSK-modulated input signal
% carrierFreq - Carrier frequency
% baudRate - Symbol rate
% sampleFreq - Sampling frequency
% Outputs:
% bitSeq - Demodulated binary sequence

symbDur = 1 / baudRate;
samplesPerSymbol = round(symbDur * sampleFreq);
numSamples = length(signal);

% Generate reference MSK waveforms for bits 0 and 1
refWave1 = modulateMSK([1], carrierFreq, baudRate, sampleFreq);
refWave0 = modulateMSK([0], carrierFreq, baudRate, sampleFreq);

bitSeq = logical.empty;

% Demodulation using correlation
for startIdx = 1:samplesPerSymbol:numSamples
if startIdx + samplesPerSymbol > numSamples
break;
end
sampleSegment = signal(startIdx:startIdx+samplesPerSymbol-1);

% Compute cross-correlation with reference waveforms
corr1 = xcorr(sampleSegment, refWave1);
corr0 = xcorr(sampleSegment, refWave0);

% Compare correlation values to determine bit
if max(corr1) + abs(min(corr1)) > max(corr0) + abs(min(corr0))
bitSeq = [bitSeq, 1];
else
bitSeq = [bitSeq, 0];
end
end
end

Output


 




In Minimum Shift Keying (MSK), the two frequencies used for 0 and 1 depend on the carrier frequency \( f_c \) and the baud rate \( R_b \) (symbols per second).

Formula for MSK frequencies:

The two frequencies are given by:

\[ f_0 = f_c - \frac{1}{4T} \] \[ f_1 = f_c + \frac{1}{4T} \]

where \( T = \frac{1}{\text{baud rate}} \) is the symbol duration.

Given values:

  • Carrier frequency: \( f_c = 10 \) Hz
  • Baud rate: \( R_b = 10 \) symbols/sec
  • Symbol duration: \( T = \frac{1}{10} = 0.1 \) sec

Now, calculating the frequencies:

\[ f_0 = 10 - \frac{1}{4 \times 0.1} = 10 - \frac{1}{0.4} = 10 - 2.5 = 7.5 \text{ Hz} \] \[ f_1 = 10 + \frac{1}{4 \times 0.1} = 10 + 2.5 = 12.5 \text{ Hz} \]

 

Minimum Shift Keying (MSK) Simulator






Differences Between MSK and FSK

 In FSK, if bits change from 0 to 1, and f₀ ≠ f₁, the carrier switches frequency — but phase continuity is not maintained unless explicitly enforced. This causes a sudden jump in phase at the bit boundary. In MSK, the phase is not static or abruptly switching. It evolves linearly over time based on the bit value, ensuring continuity. For bit duration Tb, the frequency deviation is: 
ฮ”f = ±(1 / 4Tb)
[Read More in Detail ...]
 

Q & A and Summary

1. What is the mathematical representation of the MSK signal and what does it represent?

Answer: The MSK signal is mathematically represented as: $$ s(t) = a_I(t) \cos\left(\frac{\pi t}{2T}\right) \cos(\omega_c t) - a_Q(t) \sin\left(\frac{\pi t}{2T}\right) \sin(\omega_c t) $$ In this formula, \( a_I(t) \) and \( a_Q(t) \) encode the even and odd information respectively, using square pulses of duration \( 2T \). The \( \omega_c \) is the carrier angular frequency, and the terms involving cosine and sine functions describe how the signal's phase and frequency vary over time. This continuous-phase signal is essential for reducing spectral sidebands and interference.

2. How does the constant-modulus property of MSK help reduce distortion in communication systems?

Answer: The constant-modulus property of MSK ensures that the amplitude of the signal remains unchanged regardless of the phase. This is important because non-linear distortion in communication systems typically occurs when the signal's amplitude fluctuates. By maintaining a constant amplitude, MSK reduces the chances of distortion due to non-linearities in amplifiers and other components, thus ensuring cleaner signal transmission and better performance in systems that use non-linear power amplifiers.

3. What is Minimum Shift Keying (MSK) and how does it differ from OQPSK?

Answer: Minimum Shift Keying (MSK) is a type of continuous-phase frequency-shift keying. Unlike OQPSK, MSK encodes data using half sinusoidal pulses rather than square pulses. This leads to a constant-modulus signal, reducing distortion and spectral spread. While OQPSK also uses quadrature components, MSK offers improved signal quality by ensuring smoother phase transitions.

4. Why is the continuous-phase property of MSK important?

Answer: The continuous-phase property of MSK is crucial because it minimizes spectral sidebands. In traditional phase-shift keying schemes, abrupt phase shifts can cause wide sidebands, which interfere with adjacent channels. MSK's smooth and continuous phase changes ensure a narrower spectral occupancy, allowing for better utilization of the available bandwidth and reducing interference.

5. How does the frequency separation in MSK affect the modulation process?

Answer: The frequency separation in MSK ensures that the phase shift over a bit period is exactly ±ฯ€/2. This specific frequency separation is what guarantees the smooth transitions between symbols, preventing abrupt phase changes. This also plays a critical role in maintaining the continuous-phase characteristic, which helps reduce spectral spreading and interference in the system.

6. Why is the phase modulation in MSK represented by \( \phi_k(t) = b(t) \frac{\pi t}{2T} + \phi_0 \)?

Answer: The phase modulation \( \phi_k(t) \) in MSK is represented as \( b(t) \frac{\pi t}{2T} + \phi_0 \) to ensure continuous, linear phase changes within each bit period. The term \( b(t) \) corresponds to the bit sequence, determining whether the phase shifts up or down. The factor \( \frac{\pi t}{2T} \) ensures that the phase modulation occurs smoothly over time, with no abrupt transitions, thus maintaining the continuous-phase property of MSK.

7. What makes MSK suitable for non-linear power amplifiers in communication systems?

Answer: MSK is suitable for non-linear power amplifiers because it has a constant-modulus signal. This means that the amplitude of the signal remains constant, regardless of the phase. Non-linear amplifiers work more efficiently when driven by signals with constant amplitude, as they avoid distortion that typically arises from varying amplitudes. This property of MSK allows for better power efficiency without compromising signal quality.


Further Reading

  1.  Minimum Shift Keying (MSK)
  2. Gaussian Minimum Shift Keying (GMSK)
  3. MATLAB code for GMSK
  4. Difference Between MSK and GMSK

People are good at skipping over material they already know!

View Related Topics to







Contact Us

Name

Email *

Message *

Popular Posts

BER vs SNR for M-ary QAM, M-ary PSK, QPSK, BPSK, ...

๐Ÿ“˜ Overview of BER and SNR ๐Ÿงฎ Online Simulator for BER calculation of m-ary QAM and m-ary PSK ๐Ÿงฎ MATLAB Code for BER calculation of M-ary QAM, M-ary PSK, QPSK, BPSK, ... ๐Ÿ“š Further Reading ๐Ÿ“‚ View Other Topics on M-ary QAM, M-ary PSK, QPSK ... ๐Ÿงฎ Online Simulator for Constellation Diagram of m-ary QAM ๐Ÿงฎ Online Simulator for Constellation Diagram of m-ary PSK ๐Ÿงฎ MATLAB Code for BER calculation of ASK, FSK, and PSK ๐Ÿงฎ MATLAB Code for BER calculation of Alamouti Scheme ๐Ÿงฎ Different approaches to calculate BER vs SNR What is Bit Error Rate (BER)? The abbreviation BER stands for Bit Error Rate, which indicates how many corrupted bits are received (after the demodulation process) compared to the total number of bits sent in a communication process. BER = (number of bits received in error) / (total number of tran...

Calculation of SNR from FFT bins in MATLAB

๐Ÿ“˜ Overview ๐Ÿงฎ MATLAB Code for Estimation of SNR from FFT bins of a Noisy Signal ๐Ÿงฎ MATLAB Code for Estimation of Signal-to-Noise Ratio from Power Spectral Density Using FFT and Kaiser Window Periodogram from real signal data ๐Ÿ“š Further Reading   Here, you can find the SNR of a received signal from periodogram / FFT bins using the Kaiser operator. The beta (ฮฒ) parameter characterizes the Kaiser window, which controls the trade-off between the main lobe width and the side lobe level in the frequency domain. For that you should know the sampling rate of the signal.  The Kaiser window is a type of window function commonly used in signal processing, particularly for designing finite impulse response (FIR) filters and performing spectral analysis. It is a general-purpose window that allows for control over the trade-off between the main lobe width (frequency resolution) and side lobe levels (suppression of spectral leakage). The Kaiser window is defined...

MIMO Channel Matrix | Rank and Condition Number

MIMO / Massive MIMO MIMO Channel Matrix | Rank and Condition...   The channel matrix in wireless communication is a matrix that describes the impact of the channel on the transmitted signal. The channel matrix can be used to model the effects of the atmospheric or underwater environment on the signal, such as the absorption, reflection or scattering of the signal by surrounding objects. When addressing multi-antenna communication, the term "channel matrix" is used. Let's assume that only one TX and one RX are in communication and there's no surrounding object. Here, in our case, we can apply the proper threshold condition to a received signal and get the original transmitted signal at the RX side. However, in real-world situations, we see signal path blockage, reflections, etc.,  (NLOS paths [↗]) more frequently. The obstruction is typically caused by building walls, etc. Multi-antenna communication was introduced to address this issue. It makes diversity app...

Constellation Diagrams of ASK, PSK, and FSK

๐Ÿ“˜ Overview of Energy per Bit (Eb / N0) ๐Ÿงฎ Online Simulator for constellation diagrams of ASK, FSK, and PSK ๐Ÿงฎ Theory behind Constellation Diagrams of ASK, FSK, and PSK ๐Ÿงฎ MATLAB Codes for Constellation Diagrams of ASK, FSK, and PSK ๐Ÿ“š Further Reading ๐Ÿ“‚ Other Topics on Constellation Diagrams of ASK, PSK, and FSK ... ๐Ÿงฎ Simulator for constellation diagrams of m-ary PSK ๐Ÿงฎ Simulator for constellation diagrams of m-ary QAM BASK (Binary ASK) Modulation: Transmits one of two signals: 0 or -√Eb, where Eb​ is the energy per bit. These signals represent binary 0 and 1.    BFSK (Binary FSK) Modulation: Transmits one of two signals: +√Eb​ ( On the y-axis, the phase shift of 90 degrees with respect to the x-axis, which is also termed phase offset ) or √Eb (on x-axis), where Eb​ is the energy per bit. These signals represent binary 0 and 1.  BPSK (Binary PSK) Modulation: Transmits one of two signals...

Online Simulator for ASK, FSK, and PSK

Try our new Digital Signal Processing Simulator!   Start Simulator for binary ASK Modulation Message Bits (e.g. 1,0,1,0) Carrier Frequency (Hz) Sampling Frequency (Hz) Run Simulation Simulator for binary FSK Modulation Input Bits (e.g. 1,0,1,0) Freq for '1' (Hz) Freq for '0' (Hz) Sampling Rate (Hz) Visualize FSK Signal Simulator for BPSK Modulation ...

Pulse Position Modulation (PPM)

Pulse Position Modulation (PPM) is a type of signal modulation in which M message bits are encoded by transmitting a single pulse within one of 2แดน possible time positions within a fixed time frame. This process is repeated every T seconds , resulting in a data rate of M/T bits per second . PPM is a form of analog modulation where the position of each pulse is varied according to the amplitude of the sampled modulating signal , while the amplitude and width of the pulses remain constant . This means only the timing (position) of the pulse carries the information. PPM is commonly used in optical and wireless communications , especially where multipath interference is minimal or needs to be reduced. Because the information is carried in timing , it's more robust in some noisy environments compared to other modulation schemes. Although PPM can be used for analog signal modulation , it is also used in digital communications where each pulse position represents a symbol or bit...

Simulation of ASK, FSK, and PSK using MATLAB Simulink

๐Ÿ“˜ Overview ๐Ÿงฎ How to use MATLAB Simulink ๐Ÿงฎ Simulation of ASK using MATLAB Simulink ๐Ÿงฎ Simulation of FSK using MATLAB Simulink ๐Ÿงฎ Simulation of PSK using MATLAB Simulink ๐Ÿงฎ Simulator for ASK, FSK, and PSK ๐Ÿงฎ Digital Signal Processing Simulator ๐Ÿ“š Further Reading ASK, FSK & PSK HomePage MATLAB Simulation Simulation of Amplitude Shift Keying (ASK) using MATLAB Simulink      In Simulink, we pick different components/elements from MATLAB Simulink Library. Then we connect the components and perform a particular operation.  Result A sine wave source, a pulse generator, a product block, a mux, and a scope are shown in the diagram above. The pulse generator generates the '1' and '0' bit sequences. Sine wave sources produce a specific amplitude and frequency. The scope displays the modulated signal as well as the original bit sequence created by the pulse generator. Mux is a tool for displaying b...

Comparisons among ASK, PSK, and FSK | And the definitions of each

๐Ÿ“˜ Comparisons among ASK, FSK, and PSK ๐Ÿงฎ Online Simulator for calculating Bandwidth of ASK, FSK, and PSK ๐Ÿงฎ MATLAB Code for BER vs. SNR Analysis of ASK, FSK, and PSK ๐Ÿ“š Further Reading ๐Ÿ“‚ View Other Topics on Comparisons among ASK, PSK, and FSK ... ๐Ÿงฎ Comparisons of Noise Sensitivity, Bandwidth, Complexity, etc. ๐Ÿงฎ MATLAB Code for Constellation Diagrams of ASK, FSK, and PSK ๐Ÿงฎ Online Simulator for ASK, FSK, and PSK Generation ๐Ÿงฎ Online Simulator for ASK, FSK, and PSK Constellation ๐Ÿงฎ Some Questions and Answers Modulation ASK, FSK & PSK Constellation MATLAB Simulink MATLAB Code Comparisons among ASK, PSK, and FSK    Comparisons among ASK, PSK, and FSK Comparison among ASK, FSK, and PSK Parameters ASK FSK PSK Variable Characteristics Amplitude Frequency ...