Untitled

 avatar
BeEeDoOo
plain_text
a month ago
1.6 kB
4
Indexable
clc; clear; close all;

%% Parameters
fs = 10000;  % Sampling frequency
T = 1;       % Signal duration in seconds
t = 0:1/fs:T; % Time vector
fm = 10;     % Message frequency in Hz
fc = 200;    % Carrier frequency in Hz
Am = 1;      % Message amplitude
Ac = 1;      % Carrier amplitude
kf = 50;     % Frequency deviation for FM
kp = pi/2;   % Phase deviation for PM

%% Message Signal
m = Am * cos(2 * pi * fm * t);

%% AM Modulation and Demodulation
am_modulated = (Ac + m) .* cos(2 * pi * fc * t);
am_demodulated = abs(hilbert(am_modulated)) - Ac;

%% FM Modulation and Demodulation
fm_modulated = cos(2 * pi * fc * t + 2 * pi * kf * cumsum(m) / fs);
fm_demodulated = [0 diff(unwrap(angle(hilbert(fm_modulated))))] * fs / (2 * pi * kf);

%% PM Modulation and Demodulation
pm_modulated = cos(2 * pi * fc * t + kp * m);
pm_demodulated = [0 diff(unwrap(angle(hilbert(pm_modulated))))] / kp;

%% Plot Results
figure;
subplot(4,1,1);
plot(t, m, 'b');
title('Message Signal'); xlabel('Time (s)'); ylabel('Amplitude'); grid on;

subplot(4,1,2);
plot(t, am_modulated, 'r'); hold on;
plot(t, am_demodulated, 'g');
title('AM: Modulated (Red) & Demodulated (Green)'); xlabel('Time (s)'); ylabel('Amplitude'); grid on;

subplot(4,1,3);
plot(t, fm_modulated, 'r'); hold on;
plot(t, fm_demodulated, 'g');
title('FM: Modulated (Red) & Demodulated (Green)'); xlabel('Time (s)'); ylabel('Amplitude'); grid on;

subplot(4,1,4);
plot(t, pm_modulated, 'r'); hold on;
plot(t, pm_demodulated, 'g');
title('PM: Modulated (Red) & Demodulated (Green)'); xlabel('Time (s)'); ylabel('Amplitude'); grid on;
Editor is loading...
Leave a Comment