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

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







Admin & Author: Salim

s

  Website: www.salimwireless.com
  Interests: Signal Processing, Telecommunication, 5G Technology, Present & Future Wireless Technologies, Digital Signal Processing, Computer Networks, Millimeter Wave Band Channel, Web Development
  Seeking an opportunity in the Teaching or Electronics & Telecommunication domains.
  Possess M.Tech in Electronic Communication Systems.


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. It is defined as,  In mathematics, BER = (number of bits received in error / total number of transmitted bits)  On the other hand, SNR ...

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   Simulator for Calculating Bandwidth of ASK, FSK, and PSK The baud rate represents the number of symbols transmitted per second. Both baud rate and bit rate a...

Constellation Diagrams of ASK, PSK, and FSK

📘 Overview 🧮 Online Simulator for constellation diagrams of ASK, FSK, and PSK 🧮 Theory 🧮 MATLAB Codes 🧮 Simulator for constellation diagrams of m-ary PSK 🧮 Simulator for constellation diagrams of m-ary QAM 📚 Further Reading 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: +√Eb​ or -√Eb (they differ by 180 degree phase shift), where Eb​ is the energy per bit. These signals represent binary 0 and 1.    Simulator for BASK, BPSK, and BFSK Constellation Diagrams ...

RMS Delay Spread, Excess Delay Spread and Multi-path ...

📘 Overview 🧮 Multipath Components or MPCs 🧮 Excess Delay spread 🧮 Power delay Profile 🧮 RMS Delay Spread 🧮 Simulator for Calculating RMS Delay Spread 🧮 Why is there significant multipath in the case of very high frequencies? 🧮 Why RMS Delay Spread is essential for wireless communication? 🧮 Why the Power Delay Profile is essential? 🧮 MATLAB Codes 📚 Further Reading Signal Processing RMS Delay Spread, Excess Delay Spread, and Multipath... RMS Delay Spread, Excess Delay Spread, and Multipath (MPCs) The fundamental distinction between wireless and wired connections is that in wireless connections signal reaches at receiver thru multipath signal propagation rather than directed transmission like co-axial cable. Wireless Communication has no set communication path between the transmitter and the receiver. The line of sight path, also known as the LOS path, is the shortest and most direc...

MATLAB Code for Pulse Amplitude Modulation (PAM) and Demodulation

📘 Overview & Theory 🧮 MATLAB Code for Pulse Amplitude Modulation and Demodulation of an Analog Signal 🧮 MATLAB Code for Pulse Amplitude Modulation and Demodulation of an Analog Signal (2) 🧮 MATLAB Code for Pulse Amplitude Modulation and Demodulation of Digital data 🧮 Simulation results for comparison of PAM, PWM, PPM, DM, and PCM 🧮 Other Pulse Modulation Techniques (e.g., PWM, PPM, DM, and PCM) 📚 Further Reading   Pulse Amplitude Modulation (PAM) & Demodulation of an Analog Message Signal MATLAB Script clc; clear all; close all; fm= 10; % frequency of the message signal fc= 100; % frequency of the carrier signal fs=1000*fm; % (=100KHz) sampling frequency (where 1000 is the upsampling factor) t=0:1/fs:1; % sampling rate of (1/fs = 100 kHz) m=1*cos(2*pi*fm*t); % Message signal with period 2*pi*fm (sinusoidal wave signal) c=0.5*square(2*pi*fc*t)+0.5; % square wave with period 2*pi*fc s=m.*c; % modulated signal (multiplication ...

Relationship between Gaussian and Rayleigh distributions

📘 Introduction, Gaussian Distribution, Relationship Between Gaussian and Rayleigh Distribution 🧮 How to mitigate Rayleigh fading? 🧮 Equalizer to reduce Rayleigh Fading (or Multi-path Effects) in MATLAB 🧮 MATLAB Code for Effects of AWGN and Rayleigh Fading in Wireless Communication 🧮 Simulator for the effect of AWGN and Rayleigh Fading on a BPSK Signal 📚 Further Reading Wireless Signal Processing Gaussian and Rayleigh distributions ...   The Rayleigh distribution in classical fading models (like wireless communication) arises from modeling the real and imaginary parts of a complex baseband signal as independent, zero-mean Gaussian random variables — under specific assumptions . 1. Gaussian Distribution  The Gaussian distribution has a lot of applications in wireless communication. Since noise in wireless communication systems is unpredictable, we frequently assume that it has a Gaussian distribution...

Difference between AWGN and Rayleigh Fading

📘 Introduction, AWGN, and Rayleigh Fading 🧮 Simulator for the effect of AWGN and Rayleigh Fading on a BPSK Signal 🧮 MATLAB Codes 📚 Further Reading Wireless Signal Processing Gaussian and Rayleigh Distribution Difference between AWGN and Rayleigh Fading 1. Introduction Rayleigh fading coefficients and AWGN, or additive white gaussian noise [↗] , are two distinct factors that affect a wireless communication channel. In mathematics, we can express it in that way.  Fig: Rayleigh Fading due to multi-paths Let's explore wireless communication under two common noise scenarios: AWGN (Additive White Gaussian Noise) and Rayleigh fading. y = h*x + n ... (i) Symbol '*' represents convolution. The transmitted signal  x  is multiplied by the channel coefficient or channel impulse response (h)  in the equation above, and the symbol  "n"  stands for the white Gaussian noise that is added to the si...

MATLAB Codes for Various types of beamforming | Beam Steering, Digital...

Beamforming Techniques MATLAB Codes for Beamforming... The mathematical [↗] and theoretical aspects of beamforming [↗] have already been covered. We'll talk about coding in MATLAB in this tutorial so that you may generate results for different beamforming approaches. Let's go right to the content of the article. In analog beamforming, certain codebooks are employed on the TX and RX sides to select the best beam pairs. Because of their beamforming gains, communication created through the strongest beams from both the TX and RX side enhances spectrum efficiency. Additionally, beamforming gain directly impacts SNR improvement. Wireless communication system capacity = bandwidth*log2(1+SNR) bits/s. Thus, the capacity or overall throughput of the system increases. MATLAB Script %Written by Salim Wireless %Visit www.salimwireless.com for study materials on wireless communication %or, if you want to learn how to code in MATLAB clear all;...