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


Contact Us

Name

Email *

Message *

Popular Posts

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

UGC NET Electronic Science June 2025 Question Paper with Answer Key & Detailed Solutions

Home / UGC NET PYQ / June 2025 Solved UGC NET Electronic Science June 2025 Question Paper with Answer Key and Full Explanations 📥 Download Question Paper (PDF) 2025 2024 2023 2022 2021 2020 Explanations 1.  Answer: Option (3) For forming a p-type semiconductor, the dopant must be a trivalent impurity (three valence electrons) so that it creates acceptor levels and holes become the majority carriers. Among the given elements, boron (B) is a group-III element (trivalent). Arsenic (As) and phosphorus (P) are group-V (pentavalent) donors that produce n-type material, and germanium (Ge) is a group-IV element usually used as the semiconductor, not as an acceptor dopant. Hence, doping an intrinsic semiconductor with B produces a p-type semiconductor. 2.  Answer: Option (4) The ohmic resistance of a JFET at zero gate bias is given by the standard relation: R DS(on) = V P / I DSS ...

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

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

UGC NET Electronic Science December 2024 Question Paper with Answer Key & Detailed Solutions

Home / UGC NET PYQ / June 2025 Solved UGC NET Electronic Science December 2024 Question Paper with Answer Key and Full Explanations 📥 Download Question Paper (PDF) 2025 2024 2023 2022 2021 2020 Q.1 Answer: Option (3) Q.2 Answer: Option (3) Solution 1. JMP SHORT LABEL Intrasegment (within the same code segment). Direct jump. ❌ Not intersegment indirect. 2. JMP 5000H:2000H Intersegment (far jump because both CS and IP are specified). Direct jump (address is explicitly given). ❌ Not indirect. 3. JMP [2000H] The destination address is taken from memory location 2000H. This is indirect. In 8086, a far indirect jump can use a memory operand containing both IP and CS (depending on operand size), making it an intersegment indirect jump. ✅ Correct answer. 4. JMP [BX] Indirect jump through memory addressed by BX. Usually intrasegment (near indirect jump). ❌ Not in...

Constellation Diagrams of ASK, PSK, and FSK (with MATLAB Code + Simulator)

Constellation Diagrams: ASK, FSK, and PSK Comprehensive guide to signal space representation, including interactive simulators and MATLAB implementations. 📘 Overview 🧮 Simulator ⚖️ Theory Q-function 📚 Resources 📂 Other Topics: M-ary PSK & QAM Diagrams ▼ 🧮 Simulator for M-ary PSK Constellation 🧮 Simulator for M-ary QAM Constellation 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 phas...

Theoretical BER vs SNR for binary ASK, FSK, and PSK (with MATLAB Code + Simulator)

📘 Overview & Theory 🧮 MATLAB Codes 🧮 Q-function 📚 Further Reading Bit Error Rate (BER) Equations In ASK, noise directly affects the signal amplitude, making it the most vulnerable since the data is carried in amplitude changes. In FSK, data is represented by frequency variations, and because noise typically impacts amplitude more than frequency, FSK is more robust than ASK. In PSK, data is encoded in the signal phase, and BPSK specifically uses 180-degree phase shifts, creating the greatest separation between signal points and therefore achieving the lowest bit error rate (BER) for the same power level. BER formulas for ASK, FSK, and PSK modulation schemes. ASK BER = 0.5 × erfc(0.5 × √SNR) FSK BER = 0.5 × erfc(√(SNR / 2)) PSK BER = 0.5 × erfc(√SNR) ...