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

Constellation Diagram of FSK in Detail

📘 Overview 🧮 Simulator for constellation diagram of FSK 🧮 Theory 🧮 MATLAB Code 📚 Further Reading 📚 BER vs SNR from Constellation   Binary bits '0' and '1' can be mapped to 'j' and '1' to '1', respectively, for Baseband Binary Frequency Shift Keying (BFSK) . Signals are in phase here. These bits can be mapped into baseband representation for a number of uses, including power spectral density (PSD) calculations. For passband BFSK transmission, we can modulate signal 'j' with a lower carrier frequency and signal '1' with a higher carrier frequency while transmitting over a wireless channel. Let's assume we are transmitting carrier signal fc1 for the transmission of binary bit '1' and carrier signal fc2 for the transmission of binary bit '0'. Simulator for 2-FSK Constellation Diagram Simulator for 2-FSK Constellation Diagram ...

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

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

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 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 figure of merit f...

Coherence Bandwidth and Coherence Time (with MATLAB + Simulator)

🧮 Coherence Bandwidth 🧮 Coherence Time 🧮 MATLAB Code s 📚 Further Reading For Doppler Delay or Multi-path Delay Coherence time T coh ∝ 1 / v max (For slow fading, coherence time T coh is greater than the signaling interval.) Coherence bandwidth W coh ∝ 1 / Ï„ max (For frequency-flat fading, coherence bandwidth W coh is greater than the signaling bandwidth.) Where: T coh = coherence time W coh = coherence bandwidth v max = maximum Doppler frequency (or maximum Doppler shift) Ï„ max = maximum excess delay (maximum time delay spread) Notes: The notation v max −1 and Ï„ max −1 indicate inverse proportionality. Doppler spread refers to the range of frequency shifts caused by relative motion, determining T coh . Delay spread (or multipath delay spread) determines W coh . Frequency-flat fading occurs when W coh is greater than the signaling bandwidth. Coherence Bandwidth Coherence bandwidth is...

Intel 8086 Transistor Count: Architecture, Specifications, and Comparison with Other Microprocessors

Intel 8086 Transistor Count: Architecture, Specifications, and Comparison with Other Microprocessors Intel 8086 Transistor Count: Complete Guide with Architecture and Processor Comparison The Intel 8086 microprocessor is one of the most important processors in computer history. Released in 1978 , it introduced the x86 architecture that still influences modern CPUs. One of the most frequently asked questions in computer architecture and microprocessor courses is: How many transistors are present in the Intel 8086? The commonly accepted answer is approximately 29,000 transistors . However, reverse-engineering studies have shown that the actual number of physical transistors is closer to 19,618 , while Intel's published figure includes programmable transistor locations used in ROM and PLA structures. Intel 8086 Transistor Count Metric Value Published transistor count ~29,000 Physical transistor count ~19,618 Release year 1978 Word ...

Online Simulator for ASK, FSK, and PSK

Interactive Digital Signal Processing (DSP) Tutorial and Simulator for ASK, FSK, and BPSK modulation techniques. Try our new Digital Signal Processing Simulator!   •   Interactive ASK, FSK, and BPSK tools updated for 2025. Start Now Digital Modulation Visualizer: ASK, FSK, & BPSK Simulator Learn and visualize binary modulation techniques (ASK, FSK, BPSK) in real-time with adjustable carrier and sampling parameters. Perfect for DSP students and engineers. 📡 ASK Simulator 📶 FSK Simulator 🎚️ BPSK Simulator 📚 More Topics ASK Modulator FSK Modulator BPSK Modulator More Topics 1. ASK (Amplitude Shift Keying) Simulat...