a step-by-step guide to signal modulation and demodulation using MATLAB, including code examples, visualizations, and explanations for common modulation techniques like AM, FM, ASK, FSK, and QAM.
Here’s a step-by-step guide to signal modulation and demodulation using MATLAB, including code examples, visualizations, and explanations for common modulation techniques like AM, FM, ASK, FSK, and QAM.
1. Amplitude Modulation (AM)
Theory: The message signal modulates the amplitude of a high-frequency carrier wave.
Code:
Fs = 1000; % Sampling frequency (Hz) t = 0:1/Fs:1; % Time vector (1 second) Fc = 100; % Carrier frequency (Hz) % Message signal (5 Hz sine wave) fm = 5; message = 0.5*sin(2*pi*fm*t); % AM Modulation carrier = cos(2*pi*Fc*t); modulated_AM = (1 + message) .* carrier; % AM Demodulation (envelope detection) envelope = abs(hilbert(modulated_AM)) - 1; % Remove DC offset % Plot figure; subplot(3,1,1); plot(t, message); title('Message Signal'); subplot(3,1,2); plot(t, modulated_AM); title('AM Modulated Signal'); subplot(3,1,3); plot(t, envelope); title('Demodulated Signal');
Output:
2. Frequency Modulation (FM)
Theory: The message signal modulates the frequency of the carrier wave.
Code:
Fs = 1000; t = 0:1/Fs:1; Fc = 100; fm = 5; message = 0.5*sin(2*pi*fm*t); % FM Modulation frequency_deviation = 25; % Hz modulated_FM = fmmod(message, Fc, Fs, frequency_deviation); % FM Demodulation demodulated_FM = fmdemod(modulated_FM, Fc, Fs, frequency_deviation); % Plot figure; subplot(3,1,1); plot(t, message); title('Message Signal'); subplot(3,1,2); plot(t, modulated_FM); title('FM Modulated Signal'); subplot(3,1,3); plot(t, demodulated_FM); title('Demodulated Signal');
Output:
3. Digital Modulation: Amplitude Shift Keying (ASK)
Theory: Binary data modulates the amplitude of the carrier (e.g., 1 = carrier ON, 0 = carrier OFF).
Code:
Fs = 1000; t = 0:1/Fs:1; Fc = 100; % Generate random bits bits = randi([0 1], 1, 10); % 10 bits message = repelem(bits, 100); % Repeat each bit for 100 samples % ASK Modulation modulated_ASK = message .* cos(2*pi*Fc*t); % ASK Demodulation (non-coherent) envelope = abs(hilbert(modulated_ASK)); demodulated_bits = envelope > 0.5; % Threshold detection % Plot figure; subplot(3,1,1); stem(bits); title('Original Bits'); subplot(3,1,2); plot(t, modulated_ASK); title('ASK Modulated Signal'); subplot(3,1,3); plot(t, demodulated_bits); title('Demodulated Bits');
Output:
4. Digital Modulation: Quadrature Amplitude Modulation (QAM)
Theory: Combines amplitude and phase modulation to transmit multiple bits per symbol.
Code:
M = 16; % 16-QAM n = 1000; % Number of symbols Fs = 1000; Fc = 100; % Generate random symbols data = randi([0 M-1], 1, n); modulated_QAM = qammod(data, M); % Add noise (simulate channel) SNR = 20; % dB received = awgn(modulated_QAM, SNR, 'measured'); % Demodulate demodulated_QAM = qamdemod(received, M); % Plot constellation scatterplot(modulated_QAM); title('16-QAM Constellation');
Output:
5. Key Functions & Toolboxes
- Analog Modulation:
ammod
,amdemod
(Amplitude Modulation).fmmod
,fmdemod
(Frequency Modulation).
- Digital Modulation:
qammod
,qamdemod
(QAM).pskmod
,pskdemod
(Phase Shift Keying).
- Toolboxes: Requires Communications Toolbox for advanced functions like
qammod
.
6. Summary
- AM/FM: Suitable for analog signals.
- ASK/FSK/QAM: Used in digital communication systems.
- MATLAB’s built-in functions simplify modulation/demodulation.
- Visualizations (time-domain plots, constellation diagrams) help validate results.
Let me know if you need help with specific modulation schemes or error analysis