% EE-202 Lab Experiment 6 H. Saadat, Fall 2002 % AM Modulation and envelope detection of AM f0 = input('Enter the message signal frequency in Hz, f_o = '); % The message signal fc = input('Enter the carrier frequency in Hz, f_c = '); % Carrier signal R=100000; CU = input('Enter capacitance in micro Farad, C = '); C = CU*10^-6; tau=R*C; fs=20*fc; Ts=1/fs; t=0:Ts:2/f0; %t=[1:2^13]/fs; x = cos(2*pi*f0*t); cs= cos(2*pi*fc*t); x_AM = (1+0.7*x).*cs; % Amplitude modulated signal n=length(x_AM); x_AMRect = x_AM; for k=1:n if x_AMRect(k) < 0 x_AMRect(k) = 0; else, end end figure('Units','normalized', ... 'Color',[0.8 0.8 0.8], ... 'Position',[0.09 0.1 0.8 0.8], ... 'Tag','EE202 Envelop Detector'); subplot(3,1,1), plot(t, cs,'b', t,x,'r'), grid on title(['Message frequency f_0 = ', num2str(f0),... ' Hz, Carrier frequency f_c = ', num2str(fc),... ' Hz, R = ', num2str(R/1000), ' K\Omega, C = ', num2str(CU),' \muF']) legend('Carrier','Message', 4) subplot(3,1,2), plot(t, x_AM, 'm'), grid on title('AM Signal'); xlabel('t, s'), ylabel('x_{AM}') % Envelope detection of AM x_o=x_AM*0; for k=2:length(x_o) x_o(k)=x_o(k-1)-(x_o(k-1)/(fs*R*C)); if (x_o(k) < x_AM(k)) x_o(k)=x_AM(k); end; end; subplot(3,1,3), plot(t,x_AMRect,'m',t,x_o,'b'); grid on xlabel('Time (sec)') title('Envelope Detector Output and Rectified AM Signal'); legend('Rectified AM signal', 'Envelope detector output', 4) axis([0 2/f0 -2 2])