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
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
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
Fig 3: PSK Modulation and Demodulation
Interactive Modulation Simulator
Launch the web-based tool to simulate digital modulation techniques.
Launch Simulator →