MATLAB Code
clear; close all; clc;
%% Parameters
Fs = 1000; % Sampling frequency
T = 2; % Duration
t = 0:1/Fs:T-1/Fs;
fm = 5; % Message frequency
fc = 100; % Carrier frequency
%% Baseband signal
m = cos(2*pi*fm*t);
%% Hilbert transform
mh = imag(hilbert(m));
%% Analytic signal
ma = m + 1j*mh;
%% Envelope and instantaneous phase
envelope = abs(ma);
phase = unwrap(angle(ma));
%% I/Q modulation
I = m;
Q = mh;
USB = I .* cos(2*pi*fc*t) ...
- Q .* sin(2*pi*fc*t);
LSB = I .* cos(2*pi*fc*t) ...
+ Q .* sin(2*pi*fc*t);
%% Ordinary DSB-SC
DSB = m .* cos(2*pi*fc*t);
%% Plot everything
figure('Color','w');
subplot(4,2,1)
plot(t,m,'b')
grid on
title('Baseband m(t)')
xlabel('Time (s)')
subplot(4,2,2)
plot(t,mh,'r')
grid on
title('Hilbert transform m̂(t)')
xlabel('Time (s)')
subplot(4,2,3)
plot(t,real(ma),'b')
hold on
plot(t,imag(ma),'r')
grid on
title('Analytic signal: I + jQ')
legend('I=m(t)','Q=m̂(t)')
xlabel('Time (s)')
subplot(4,2,4)
plot(t,envelope,'k')
grid on
title('Instantaneous amplitude |m_a(t)|')
xlabel('Time (s)')
subplot(4,2,5)
plot(t,DSB)
grid on
title('DSB-SC: m(t)cos(\omega_c t)')
xlabel('Time (s)')
subplot(4,2,6)
plot(t,USB)
grid on
title('USB')
xlabel('Time (s)')
subplot(4,2,7)
plot(t,LSB)
grid on
title('LSB')
xlabel('Time (s)')
subplot(4,2,8)
plot(I,Q)
axis equal
grid on
title('I/Q plane')
xlabel('I')
ylabel('Q')
%% Frequency spectra
figure('Color','w');
N = length(t);
f = (-N/2:N/2-1)*(Fs/N);
M = fftshift(abs(fft(m))/N);
DSBspec = fftshift(abs(fft(DSB))/N);
USBspec = fftshift(abs(fft(USB))/N);
LSBspec = fftshift(abs(fft(LSB))/N);
subplot(4,1,1)
plot(f,M)
xlim([-150 150])
grid on
title('Baseband spectrum')
subplot(4,1,2)
plot(f,DSBspec)
xlim([-150 150])
grid on
title('DSB-SC spectrum')
subplot(4,1,3)
plot(f,USBspec)
xlim([-150 150])
grid on
title('USB spectrum')
subplot(4,1,4)
plot(f,LSBspec)
xlim([-150 150])
grid on
title('LSB spectrum')
xlabel('Frequency (Hz)')