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...

Theoretical BER vs SNR for binary ASK, FSK, and PSK

📘 Overview & Theory 🧮 MATLAB Codes 📚 Further Reading Theoretical BER vs SNR for Amplitude Shift Keying (ASK) The theoretical Bit Error Rate (BER) for binary ASK depends on how binary bits are mapped to signal amplitudes. For typical cases: If bits are mapped to 1 and -1, the BER is: BER = Q(√(2 × SNR)) If bits are mapped to 0 and 1, the BER becomes: BER = Q(√(SNR / 2)) Where: Q(x) is the Q-function: Q(x) = 0.5 × erfc(x / √2) SNR : Signal-to-Noise Ratio N₀ : Noise Power Spectral Density Understanding the Q-Function and BER for ASK Bit '0' transmits noise only Bit '1' transmits signal (1 + noise) Receiver decision threshold is 0.5 BER is given by: P b = Q(0.5 / σ) , where σ = √(N₀ / 2) Using SNR = (0.5)² / N₀, we get: BER = Q(√(SNR / 2)) Theoretical BER vs ...

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...

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 ...

UGC NET Electronic Science Previous Year Question Papers

Home / Engineering & Other Exams / UGC NET 2022: Previous Year Question Papers ... UGC-NET (Electronics Science, Subject code: 88) UGC Net Electronic Science Question Paper With Answer Key Download Pdf [December 2024] UGC Net Electronic Science Question Paper With Answer Key Download Pdf [June 2024] UGC Net Electronic Science Question Paper With Answer Key Download Pdf [December 2023] UGC Net Electronic Science Question Paper With Answer Key Download Pdf [June 2023] UGC Net Electronic Science Question Paper With Answer Key Download Pdf [December 2022] UGC Net Electronic Science Question Paper With Answer Key Download Pdf [June 2022] UGC Net Electronic Science Question Paper With Answer Key Download Pdf [December 2021] UGC Net Electronic Science Question With Answer Key Download Pdf [June 2020] UGC Net Electronic Science Question With Answer Key Download Pdf [December 2019] UGC Net Elec...

Theoretical BER vs SNR for m-ary PSK and QAM

Relationship Between Bit Error Rate (BER) and Signal-to-Noise Ratio (SNR) The relationship between Bit Error Rate (BER) and Signal-to-Noise Ratio (SNR) is a fundamental concept in digital communication systems. Here’s a detailed explanation: BER (Bit Error Rate): The ratio of the number of bits incorrectly received to the total number of bits transmitted. It measures the quality of the communication link. SNR (Signal-to-Noise Ratio): The ratio of the signal power to the noise power, indicating how much the signal is corrupted by noise. Relationship The BER typically decreases as the SNR increases. This relationship helps evaluate the performance of various modulation schemes. BPSK (Binary Phase Shift Keying) Simple and robust. BER in AWGN channel: BER = 0.5 × erfc(√SNR) Performs well at low SNR. QPSK (Quadrature...

MATLAB code for BER vs SNR for M-QAM, M-PSK, QPSk, BPSK, ...

🧮 MATLAB Code for BPSK, M-ary PSK, and M-ary QAM Together 🧮 MATLAB Code for M-ary QAM 🧮 MATLAB Code for M-ary PSK 📚 Further Reading MATLAB Script for BER vs. SNR for M-QAM, M-PSK, QPSK, BPSK % Written by Salim Wireless clc; clear; close all; num_symbols = 1e5; snr_db = -20:2:20; psk_orders = [2, 4, 8, 16, 32]; qam_orders = [4, 16, 64, 256]; ber_psk_results = zeros(length(psk_orders), length(snr_db)); ber_qam_results = zeros(length(qam_orders), length(snr_db)); for i = 1:length(psk_orders) psk_order = psk_orders(i); for j = 1:length(snr_db) data_symbols = randi([0, psk_order-1], 1, num_symbols); modulated_signal = pskmod(data_symbols, psk_order, pi/psk_order); received_signal = awgn(modulated_signal, snr_db(j), 'measured'); demodulated_symbols = pskdemod(received_signal, psk_order, pi/psk_order); ber_psk_results(i, j) = sum(data_symbols ~= demodulated_symbols) / num_symbols; end end for i...

Theoretical vs. simulated BER vs. SNR for ASK, FSK, and PSK

📘 Overview 🧮 Simulator for calculating BER 🧮 MATLAB Codes for calculating theoretical BER 🧮 MATLAB Codes for calculating simulated BER 📚 Further Reading BER vs. SNR denotes how many bits in error are received for a given signal-to-noise ratio, typically measured in dB. Common noise types in wireless systems: 1. Additive White Gaussian Noise (AWGN) 2. Rayleigh Fading AWGN adds random noise; Rayleigh fading attenuates the signal variably. A good SNR helps reduce these effects. Simulator for calculating BER vs SNR for binary ASK, FSK, and PSK Calculate BER for Binary ASK Modulation Enter SNR (dB): Calculate BER Calculate BER for Binary FSK Modulation Enter SNR (dB): Calculate BER Calculate BER for Binary PSK Modulation Enter SNR (dB): Calculate BER BER vs. SNR Curves MATLAB Code for Theoretical BER % The code is written by SalimWireless.Com clc; clear; close all; % SNR v...