Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a MATLAB code to modulate and demodulate the signal generated in MATLAB. Y

ID: 2081889 • Letter: W

Question

Write a MATLAB code to modulate and demodulate the signal generated in MATLAB. You should write the code for DSB, SSB and AM techniques for the following signal:

I got the signal to graph but I can not get it to demodulate correctly. I am not sure what I'm doing wrong. Here is what i have so far:

syms t n;

T = 10e-3;
f1 = 1/T

A_0 = (1/T)*(int(t,t,0,4e-3)+...
int(-4*t+20e-3,t,4e-3,5e-3)+...
int(-t+5e-3,t,5e-3,9e-3)+...
int(4*t-40e-3,t,9e-3,10e-3));

A_n = (2/T)*(int(t*cos(2*pi*n*f1*t),t,0,4e-3)+...
int((-4*t+20e-3)*cos(2*pi*n*f1*t),t,4e-3,5e-3)+...
int((-t+5e-3)*cos(2*pi*n*f1*t),t,5e-3,9e-3)+...
int((4*t-40e-3)*cos(2*pi*n*f1*t),t,9e-3,10e-3));

B_n = (2/T)*(int(t*sin(2*pi*n*f1*t),t,0,4e-3)+...
int((-4*t+20e-3)*sin(2*pi*n*f1*t),t,4e-3,5e-3)+...
int((-t+5e-3)*sin(2*pi*n*f1*t),t,5e-3,9e-3)+...
int((4*t-40e-3)*sin(2*pi*n*f1*t),t,9e-3,10e-3));

N = 20
for n = 1 : N
An(n) = eval(A_n);
Bn(n) = eval(B_n);
end

for k = 1:N
Fun(k) = An(k)*cos((2*pi*k*f1)*t)+Bn(k)*sin((2*pi*k*f1)*t);
end

%The above code is the signal shown in the picture.

Fun = A_0+sum(Fun);
t = 0:5e-4:50e-3;
subplot (3,1,1)
plot(t,eval(Fun))
title ('Modulating Signal');
xlabel ('time(sec)');
ylabel ('Amplitude(V)');

Am=5; % Amplitude of modulating signal
fa=2000; % Frequency of modulating signal
fc =10*fa;
Ta=1/fa; % Time period of modulating signal
t=0:Ta/999:6*Ta; % Total time for simulation
ym=Am*cos(2*pi*fa*t); % Equation of modulating signal
figure(1)
subplot(3,1,2);
plot(t,ym), grid on;
title ('Carrier Signal');
xlabel ('Time(sec)');
ylabel ('Amplitude(V)');


m =.5

Ac=eval(Fun);

y=Ac.*(1+m.*sin(2*pi*fa.*t)).*sin(2*pi*fc.*t); % Equation of Amplitude
%modulated signal
subplot(3,1,3);
plot(t,y);
title ('Amplitude Modulated Signal');
xlabel ('Time(sec)');
ylabel ('Amplitude(V)');
grid on;

md = y.*(cos(2*pi*fc.*t));
[b,a]= butter(2,0.1);
mf = filter(b,a,md);
figure(2);
plot(t,mf)

-10 v(t) t, ms

Explanation / Answer

Following is the way you can execute the code

% task 1
fc=154000;
% task 2
fm=fc/10;
fs=100*fc;
t=0:1/fs:4/fm;
xc=cos(2*pi*fc*t);
xm=cos(2*pi*fm*t);
figure(1)
subplot(2,1,1),plot(t,xc);
title('carrier signal of 154 khz');
xlabel('time (sec)');
ylabel('amplitude');
subplot(2,1,2),plot(t,xm);
title('message signal of 15.4 khz');
xlabel('time (sec)');
ylabel('amplitude');
% DSB-SC MODULATION
z1= xm.*xc;
figure(2)
% task 3.1
subplot(2,1,1),plot(t,z1);
title('DSB-SC MODULATION IN TIME DAOMAIN');
xlabel('time (sec)');
ylabel('amplitude');
% task 3.2
l1=length(z1);
f=linspace(-fs/2,fs/2,l1);
Z1=fftshift(fft(z1,l1)/l1);
subplot(2,1,2),plot(f,abs(Z1));
title('DSB SC MODULATION IN FREQUENCY DOMAIN');
xlabel('frequency(hz)');
ylabel('amplitude');
axis([-200000 200000 0 0.3]);
% task 3.3 demodulation
s1=z1.*xc;
S1=fftshift(fft(s1,length(s1))/length(s1));
figure(3)
plot(f,abs(S1));
title(' demodulated signal IN FREQUENCY DOMAIN before filtring');
xlabel('frequency(hz)');
ylabel('amplitude');
axis([-200000 200000 0 0.3]);
hold on
Hlp=1./sqrt(1+(f./fc).^(2*100));
plot(f,Hlp,'g');
title(' frequency response of low pass filter');
xlabel('frequency(hz)');
ylabel('amplitude');
axis([-200000 200000 0 2]);
% task 3.4
E1=Hlp.*S1;
figure(4)
subplot(2,1,1),plot(f,E1);
title(' Recover signal IN FREQUENCY DOMAIN after filtring');
xlabel('frequency(hz)');
ylabel('amplitude');
axis([-200000 200000 0 0.3]);
e1=ifft(ifftshift(E1))*length(E1);
subplot(2,1,2),plot(t,(1/0.5)*e1);
title(' Recover signal IN Time DOMAIN after filtring');
xlabel('time(sec)');
ylabel('amplitude');

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote