Skip to content

Instantly share code, notes, and snippets.

@sritasngh
Created July 19, 2020 13:46
Show Gist options
  • Save sritasngh/09a2f0ae4512fb9d96537404b7da12db to your computer and use it in GitHub Desktop.
Save sritasngh/09a2f0ae4512fb9d96537404b7da12db to your computer and use it in GitHub Desktop.
Write a code in MATLAB to obtain output form the expression for the amplitude modulation (DSB-C) signals, where message signal is m(t)=5 sin(2 π 100t) and carrier signal c(t)= 10 sin(2 π 1500t).
%DSB-SC modulation
Am=5; %amplitude of message signal
Ac=5; %amplitude of carrier wave
fm=100; %frequency of message signal(Hz)
fc=1500; %frequency of carrier wave (Hz)
F=10000; %sampling frequency (Hz)
T=1/F;
t=0:T:0.1; %time vector
%1.Message signal
figure(1);
subplot(311); %plot at 1st position in a 3-by-1 grid
m=Am*sin(2*pi*fm*t);
plot(t,m); xlabel('t(sec)'); ylabel('m(t)');
title('Message signal Vs Time');
%Spectrum of message signal
n=length(m); %length returns period of the message signal
M=fftshift(fft(m,n));
%zero-centered fast fourier transform
f=F*[-n/2:n/2-1]/n; %zero-centered frequency range
figure(2);
subplot(311);
plot(f,abs(M));xlabel('f(Hz)'); ylabel('M(f)');
title('Spectrum of Message signal');
%2.Carrier wave
c=Ac*sin(2*pi*fc*t);
figure(1);
subplot(312); %creates axis at 2nd place on a 3-by-1 grid
plot(t,c); xlabel('t(sec'); ylabel('c(t)');
title('Carrier signal Vs Time')
%Spectrum of carrier wave
N=length(c);
C=fftshift(fft(c,N));
f=F*[-N/2:N/2-1]/N;
figure(2);
subplot(312);
plot(f,abs(C)); xlabel('f(Hz)'); ylabel('C(f)');
title('Spectrum of Carrier wave');
%3.DSB-SC modulation
x_dsbsc=m.*c; %DSB-C signal
figure(1);
subplot(313); %creates axis at 3rd place on a 3-by-1 grid
plot(t,x_dsbsc);xlabel('t(sec)'); ylabel('x_d_s_b_-_s_c(t)');
title('DSB-SC signal Vs Time');
%Spectrum of DSB-SC modulated signal
l=length(x_dsbsc);
X_dsbsc=fftshift(fft(x_dsbsc,l));
figure(2);
subplot(313);
plot(f,abs(X_dsbsc)); xlabel('f(Hz)');ylabel('X_d_s_b__s_c(f)');
title('Spectrum of DSB-SC modulated signal');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment