Matlab code for DSB_SC.
clc;
clear all;
fs=30000;%sampling frequency
t=0:(1/fs):0.01;
fc=2000;%carrier frequency
fm=400;%message frequency
ac=1;%carrier signal amplitude
am=1;%message signal amplitude
carrier=ac*sin(2*pi*fc*t);
msg=am*sin(2*pi*fm*t);
dsb_sc = msg .* carrier;
figure;
subplot(4,1,1);
plot(t, msg, 'b');
title('Message Signal');
xlabel('Time (s)');
ylabel('Amplitude');
subplot(4,1, 2);
plot(t, carrier, 'r');
title('Carrier Signal');
xlabel('Time (s)');
ylabel('Amplitude');
subplot(4,1, 3);
plot(t, dsb_sc, 'k');
title('DSB-SC Modulated Signal');
xlabel('Time (s)');
ylabel('Amplitude');
%Code for demodulation
local_osc = sin(2*pi*fc*t);
demodulated =dsb_sc.* local_osc;
Fc_lp=500;
[b, a] = butter(6, Fc_lp/(fs/2)); % 6th order Butterworth filter
recovered_message = filter(b, a, demodulated);
% Plotting the demodulated signal and the recovered message
subplot(4,1,4);
plot(t, recovered_message, 'g');
title('Recovered Message Signal');
xlabel('Time (s)');
ylabel('Amplitude');
msg_fft=abs(fftshift(fft(msg)));%fourier transform of the message
f=linspace(-fs/2,fs/2,length(msg_fft));
figure;
subplot(3,1,1);
plot(f,msg_fft/max(msg_fft),'r');
title('Message signal');
xlabel('Frequency(Hz)');
ylabel('Amplitude');
carrier_fft=abs(fftshift(fft(carrier)));%fourier transform of the carrier
f=linspace(-fs/2,fs/2,length(carrier_fft));
subplot(3,1,2);
plot(f,carrier_fft/max(carrier_fft),'r');
title('carrier signal');
xlabel('Frequency(Hz)');
ylabel('Amplitude');
dsb_sc_fft=abs(fftshift(fft(dsb_sc)));%fourier transform of the dsb_sc signal
f=linspace(-fs/2,fs/2,length(dsb_sc_fft));
subplot(3,1,3);
plot(f,dsb_sc_fft/max(dsb_sc_fft),'b');
title('dsb_sc signal');
xlabel('Frequency(Hz)');
ylabel('Amplitude');
Report Question:
1. Run the code and discuss the outputs.
2. Discuss why there is a phase reversal in dsb_sc modulated output.
Matlab Code for SSB_SC.
clc;
clear all;
fs=30000;%sampling frequency
t=0:(1/fs):0.01;
fc=2000;%carrier frequency
fm=400;%message frequency
ac=1;%carrier signal amplitude
am=1;%message signal amplitude
carrier1=ac*sin(2*pi*fc*t);
msg1=am*sin(2*pi*fm*t);
msg2=am*cos(2*pi*fm*t);% 90 degree shifted msg
carrier2=ac*cos(2*pi*fc*t);% 90 degree shifted carrier
modulated_1=msg1.*carrier1;%DSB-Sc signal
modulated_2=msg2.*carrier2;%DSB-Sc signal
lsb_signal=modulated_1+modulated_2;%lower sideband signal
usb_signal=modulated_1-modulated_2;%upper sideband signal
figure;
subplot(3,2,1);
plot(t,msg1,'r');
title('Message signal');
xlabel('time(s)');
ylabel('Amplitude');
subplot(3,2,2);
plot(t,carrier1,'r');
title('Carrier signal');
xlabel('time(s)');
ylabel('Amplitude');
subplot(3,2,3);
plot(t,lsb_signal,'b');
title('Lower sideband');
xlabel('time(s)');
ylabel('Amplitude');
subplot(3,2,4);
plot(t,usb_signal,'g');
title('Upper sideband');
xlabel('time(s)');
ylabel('Amplitude');
%%demodulation of ssb_sc
demodulated_signal=usb_signal.*carrier1;
fc_lp=600; %cutoff frequency of the LPF
[b,a]=butter(6,fc_lp/(fs/2));
message=filter(b,a,demodulated_signal);
subplot(3,2,5);
plot(t,message);
title('Demodulated Output');
xlabel('time(s)');
ylabel('Amplitude');
msg_fft=abs(fftshift(fft(msg1)));%fourier transform of the message
f=linspace(-fs/2,fs/2,length(msg_fft));
figure;
subplot(4,1,1);
plot(f,msg_fft/max(msg_fft),'r');
title('Message signal');
xlabel('Frequency(Hz)');
ylabel('Amplitude');
carrier_fft=abs(fftshift(fft(carrier1)));%fourier transform of the carrier
f=linspace(-fs/2,fs/2,length(carrier_fft));
subplot(4,1,2);
plot(f,carrier_fft/max(carrier_fft),'r');
title('carrier signal');
xlabel('Frequency(Hz)');
ylabel('Amplitude');
lsb_fft=abs(fftshift(fft(lsb_signal)));%fourier transform of the LSB signal
f=linspace(-fs/2,fs/2,length(lsb_fft));
subplot(4,1,3);
plot(f,lsb_fft/max(lsb_fft),'b');
title('Lower sideband');
xlabel('Frequency(Hz))');
ylabel('Amplitude');
usb_fft=abs(fftshift(fft(usb_signal)));%fourier transform of the USB signal
f=linspace(-fs/2,fs/2,length(usb_fft));
subplot(4,1,4);
plot(f,usb_fft/max(usb_fft),'g');
title('Upper sideband');
xlabel('Frequency(Hz)');
ylabel('Amplitude');
Report Question:
1. Run the code and discuss the outputs.
2. Compare the results with the output for the built-in function for ssb signal generator.
3. Discuss whether both DSB_SC and SSB_SC signal can be demodulated by envelop
detection. If not, mention the reasons.