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
Fig 1: ASK Modulation and Demodulation
MATLAB Code for FSK Modulation and Demodulation
Fig 2: FSK Modulation and Demodulation
MATLAB Code for PSK Modulation and Demodulation
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.
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.