Skip to main content

MATLAB Code for ASK, FSK, and PSK (with Online Simulator)


MATLAB Code for ASK, FSK, and PSK

Comprehensive implementation of digital modulation and demodulation techniques with simulation results.




MATLAB Code for ASK Modulation and Demodulation

% The code is written by SalimWireless.Com clc; clear all; close all; % Parameters Tb = 1; fc = 10; N_bits = 10; Fs = 100 * fc; Ts = 1/Fs; samples_per_bit = Fs * Tb; rng(10); binary_data = randi([0, 1], 1, N_bits); t_overall = 0:Ts:(N_bits * Tb) - Ts; message_signal_overall = zeros(1, length(t_overall)); ask_signal_overall = zeros(1, length(t_overall)); carrier_template = sqrt(2/Tb) * sin(2*pi*fc*(0:Ts:Tb-Ts)); for i = 1:N_bits current_bit = binary_data(i); t_segment_indices = ((i-1)*samples_per_bit + 1) : (i*samples_per_bit); if current_bit == 1 message_segment = ones(1, samples_per_bit); else message_segment = zeros(1, samples_per_bit); end ask_segment = carrier_template .* message_segment; message_signal_overall(t_segment_indices) = message_segment; ask_signal_overall(t_segment_indices) = ask_segment; end
ASK Output

Fig 1: ASK Modulation and Demodulation

MATLAB Code for FSK Modulation and Demodulation

% The code is written by SalimWireless.Com clc; clear; close all; % Parameters Fs = 1000; fc1 = 20; fc2 = 50; Tb = 1; num_bits = 10; Ts = 1/Fs; samples_per_bit = Fs * Tb; rng(20); bits = randi([0, 1], 1, num_bits); t_bit = 0:Ts:Tb-Ts; modulated_signal = []; for bit = bits if bit == 0 modulated_signal = [modulated_signal sin(2*pi*fc1*t_bit)]; else modulated_signal = [modulated_signal sin(2*pi*fc2*t_bit)]; end end
FSK Output

Fig 2: FSK Modulation and Demodulation

MATLAB Code for PSK Modulation and Demodulation

% The code is written by SalimWireless.Com clc; clear all; close all; carrier_frequency = 10; bit_duration = 1; sampling_frequency = 1000; Ts = 1/sampling_frequency; samples_per_bit = sampling_frequency * bit_duration; rng(30); bit_stream = randi([0, 1], 1, 8); t_bit = 0:Ts:bit_duration-Ts; psk_signal = []; for bit = bit_stream if bit == 0 psk_signal = [psk_signal sin(2*pi*carrier_frequency*t_bit + 0)]; else psk_signal = [psk_signal sin(2*pi*carrier_frequency*t_bit + pi)]; end end
PSK Output

Fig 3: PSK Modulation and Demodulation

Understanding the MATLAB Implementation

Key Variables

  • Fs: Sampling frequency (must be > 2x carrier frequency).
  • Tb: Bit duration (defines how long each symbol lasts).
  • rng(10): Ensures your random bit generation is reproducible.

The Logic

The code uses a for loop to iterate through the bitstream. Depending on the bit value (0 or 1), it selects the appropriate carrier frequency or phase, effectively performing Hard-Decision Mapping.

Common MATLAB Errors & Fixes

1. "Undefined function or variable": Ensure you are running the script in the same folder where your variables are saved. Use clc; clear all; at the top.

2. Aliasing in Plots: If your waveforms look "jagged," increase the Fs (Sampling Frequency) to at least 10 times the carrier frequency.

3. Toolboxes: These codes run on base MATLAB, but for advanced BER analysis, you may need the Communication Toolbox.

Interactive Modulation Simulator

Launch the web-based tool to simulate digital modulation techniques.

Simulator Launch Simulator →

Modulation Parameter Changed Noise Immunity Complexity
ASK Amplitude Low (Highly susceptible) Simplest
FSK Frequency High (Robust) Moderate
PSK Phase Very High Highest (Requires Coherent Detection)

From Simulation to Hardware

While these MATLAB scripts simulate digital modulation in a vacuum, real-world deployment requires considering AWGN (Additive White Gaussian Noise). If you are moving to hardware like USRP (Universal Software Radio Peripheral) or RTL-SDR, you must implement Pulse Shaping (like Root-Raised Cosine) to limit bandwidth occupancy. Want to read more about raised cosine filter? Click here.

Frequently Asked Questions

Which is better: ASK, FSK, or PSK?

PSK is generally superior for high-speed data because it is the most bandwidth-efficient and noise-resistant, though it requires more complex receiver hardware.

How do I calculate BER in MATLAB?

You can use the biterr function in MATLAB to compare the transmitted bitstream with the demodulated bitstream to calculate the Bit Error Rate.


📚 Further Reading


Effect of Noise (AWGN) on ASK, FSK, and PSK

The modulated signal, x(t), is propagated through a physical communication medium—such as a wireless interface or fiber-optic cabling—where it is subject to various channel impairments. Consequently, the resulting received signal, y(t), constitutes a degraded representation of the original transmission.

This relationship is mathematically characterized by the general received signal model in the presence of fading and noise:

y(t) = h(t) · x(t) + n(t)

Where:

  • x(t) denotes the transmitted modulated signal;
  • h(t) represents the multiplicative fading characteristics of the channel;
  • n(t) signifies the Additive White Gaussian Noise (AWGN) superimposed on the signal.

Read More: Effect of AWGN on ASK→   Effect of AWGN on FSK→   Effect of AWGN on PSK→   GET MATLAB Code 


Effect of Rayleigh Fading on ASK, FSK, and PSK

This technical analysis details the lifecycle of a signal within a digital communication system, focusing on the transition from the message signal to final recovery. To facilitate long-distance transmission, information is modulated onto high-frequency carriers. However, as the signal traverses a physical medium, it encounters significant degradation modeled by the following time-domain relationship:

y(t) = [h(t)] ∗ s(t) + w(t)

In this model, h(t) represents the Channel Impulse Response—specifically Rayleigh Fading—while w(t) signifies Additive White Gaussian Noise (AWGN). The text distinguishes between these two impairments: AWGN is a constant thermal noise that reduces the signal-to-noise ratio (SNR) across all frequencies, whereas Rayleigh Fading is a stochastic process caused by multipath propagation. In urban or indoor environments, signal reflections create "deep fades," resulting in rapid fluctuations of signal strength.

The performance impact is most visible in the Bit Error Rate (BER). While BER in an AWGN channel decreases exponentially with higher power, fading channels exhibit a much slower, linear decay. For instance, at 0 dB SNR using BPSK modulation, the BER effectively doubles from 0.078 (AWGN) to 0.16 (Rayleigh).

To combat these effects, systems employ Equalization to reverse channel distortion and Diversity Techniques (spatial, temporal, or frequency) to ensure redundancy.

Read More: Impact of Rayleigh Fading on BPSK



Contact Us

Name

Email *

Message *

Popular Posts

Design of CMOS Flip-Flops (SR, D, JK)

Design of CMOS Flip-Flops (SR, D, JK) A flip-flop or latch is a circuit with two stable states, used to store state information. It is the basic storage element in sequential logic and a fundamental building block in digital electronics systems, including computers and communication devices. Flip-flops and latches act as data storage elements for states, pulse counting, and synchronization of variably-timed input signals to a reference clock. Flip-flops can be transparent/opaque (latches) or clocked (synchronous, edge-triggered). Latches are level-sensitive, while flip-flops are edge-sensitive. In sequential logic, the output depends on current inputs and previous states. Fig.1 shows a sequential circuit combining a combinational block and a memory element. ...

Q-function in BER vs SNR Calculation (with Simulation)

Q-function in BER vs. SNR Calculation In digital communications and signal processing, the Q-function plays a significant role in predicting system reliability. It allows engineers to quantify the probability that Gaussian noise will exceed a specific threshold, causing a bit error. What is the Q-function? The Q-function is a mathematical function representing the tail probability of the standard normal (Gaussian) distribution. It is the complementary cumulative distribution function (CCDF) of a standard Gaussian distribution. Q(x) = (1 / √(2Ï€)) ∫â‚“∞ e^(-t² / 2) dt The Role of the Q-function in BER vs. SNR The Q-function is the standard tool for calculating BER in systems like BPSK or QPSK over AWGN (Additive White Gaussian Noise) channels. For BPSK: In BPSK, we transmit +√E b (bit 1) and -√E b (bit 0). The decision boundary is set at 0 . If -√E b was sent, an error occurs if noise r > √...

BER vs SNR for M-ary QAM, M-ary PSK, QPSK, BPSK, ...(MATLAB Code + Simulator)

Bit Error Rate (BER) & SNR Guide Analyze communication system performance with our interactive simulators and MATLAB tools. 📘 Theory 🧮 Simulators 💻 MATLAB Code 📚 Resources BER Definition SNR Formula BER Calculator MATLAB Comparison 📂 Explore M-ary QAM, PSK, and QPSK Topics ▼ 🧮 Constellation Simulator: M-ary QAM 🧮 Constellation Simulator: M-ary PSK 🧮 BER calculation for ASK, FSK, and PSK 🧮 Approaches to BER vs SNR Calculation What is Bit Error Rate (BER)? The BER indicates how many corrupted bits are received compared to the total number of bits sent. It is the primary figur...

Channel Impulse Response (CIR) (with MATLAB + Simulator)

📘 Overview & Theory 📘 How CIR Affects the Signal 🧮 Online Channel Impulse Response Simulator 🧮 MATLAB Codes 📚 Further Reading What is the Channel Impulse Response (CIR)? The Channel Impulse Response (CIR) is a concept primarily used in the field of telecommunications and signal processing. It provides information about how a communication channel responds to an impulse signal. It describes the behavior of a communication channel in response to an impulse signal. In signal processing, an impulse signal has zero amplitude at all other times and amplitude ∞ at time 0 for the signal. Using a Dirac Delta function, we can approximate this. Fig: Dirac Delta Function The result of this calculation is that all frequencies are responded to equally by δ(t) . This is crucial since we never know which frequenci...

FFT Butterfly Method Explained (with Simulations)

4-Point FFT Using Butterfly Method Given: x[n] = {0, 1, 2, 3} Step 1: Split into Even & Odd Even indices: x e = {x[0], x[2]} = {0, 2} Odd indices: x o = {x[1], x[3]} = {1, 3} Step 2: 2-point DFT For any {a, b}: DFT = {a + b, a - b} Even Part (E): {0+2, 0-2} = {2, -2} Odd Part (O): {1+3, 1-3} = {4, -2} Step 3: Combine Using Butterfly X[k] = E[k] + W 4 k O[k] X[k + 2] = E[k] - W 4 k O[k] Twiddle Factors (N=4): W 4 0 = 1, W 4 1 = -j Final Calculations: X[0] = E[0] + W 4 0 O[0] = 2 + (1)(4) = 6 X[2] = E[0] - W 4 0 O[0] = 2 - (1)(4) = -2 X[1] = E[1] + W 4 1 O[1] = -2 + (-j)(-2) = -2 + 2j X[3] = E[1] - W 4 1 O[1] = -2 - (-j)(-2) = -2 - 2j Final Answer: X[k] = {6, -2 + 2j, -2, -2 - 2j} 8-Point FFT Using Butterfly Method Given: x[n] = {0,1,2,3,4,5,6,7} Step 1: Split into Bit-Reversed Order To perform DIT-FFT, split the 8 points into pairs of two: Group A: {x[0], x[4]} = {0, 4}...

Frequency Bands : EHF, SHF, UHF, VHF, HF, MF, LF, VLF and Their Uses

Frequency Bands >> EHF, SHF, UHF, VHF, HF, MF, LF... Frequency Bands and Their Uses 1. Extremely High Frequency (EHF) 30 - 300 GHz Uses 5G Networks 5G millimeter wave band 6G and beyond (Experimental) RADAR 2. Super High Frequency (SHF) 3 - 30 GHz Uses Ultra-wideband (UWB) Airborne RADAR Satellite Communication Microwave Link Communication or SATCOM 3. Ultra High Frequency (UHF) 300 - 3000 MHz Uses Satellite Communication Television Surveillance Navigation aids Also, read important wireless communication terms 4....

FM Bandwidth and FM Band Explained

FM radio uses the frequency band from 88 MHz to 108 MHz , which is a 20 MHz-wide spectrum . This is the range of carrier frequencies available to stations. 108 MHz − 88 MHz = 20 MHz However, a single FM station occupies only about 200 kHz . This is the bandwidth of the modulated FM signal. 1. Why One FM Station Needs ~200 kHz FM uses frequency modulation . The bandwidth depends on how far the carrier swings. Carson's Rule gives the approximate FM bandwidth: B = 2 ( Δf + f m ) ...

UGC NET Electronic Science Previous Year Question Papers with Solutions

Home / Engineering & Other Exams / UGC NET 2026 PYQ ⬇️ Download Papers and Solutions 📋 Exam Pattern 💡 Preparation Tips ❓ FAQs 📊 Exam Highlights: Electronic Science (88) Feature Details Junior Research Fellowship (JRF) ₹37,000 + HRA per month Eligibility M.Sc/M.Tech in Electronics (55%) Validity of Certificate JRF (3 Years) | Lectureship (Lifetime) 📥 Download UGC NET Electronics PDFs Complete collection of previous year question papers, answer keys and explanations for Subject Code 88. Start Downloading 📂 View All Question Papers June 2025 - Question Paper Download PDF June 2025 - Solved Paper + Explanation ...