Professional Documents
Culture Documents
Matlab Exercise #2 Ali Sider 1111829: Faculty of Engineering Electrical Engineering Department
Matlab Exercise #2 Ali Sider 1111829: Faculty of Engineering Electrical Engineering Department
Matlab Exercise #2 Ali Sider 1111829: Faculty of Engineering Electrical Engineering Department
Matlab Exercise #2
Ali Sider
1111829
clear,clc;
t=0:0.001:5;
%Asking the user about values
prompt = 'What is the value of frequency of the modulation signal? ';
Fm = input(prompt);
prompt = 'What is the value of frequency of the carrier signal? ';
Fc = input(prompt);
prompt = 'What is the value of modulation index? ';
M = input(prompt);
m=cos(2*pi*Fm*t); %Modulating Signal
c=cos(2*pi*Fc*t);%Carrier Sinal
s=(1+M.*cos(2*pi*Fm*t)).*cos(2*pi*Fc*t); %Am Signal
env= abs(1 + M.*cos(2*pi*Fm*t));%Envelop
figure %The plot of Am signal & envelop in Time Domain
plot(t,s,'r',t,env);grid;
xlabel('t');
ylabel('Signal Amplitude In Volts');
title('Am Signal');
%Plot in Frequency domain
N=10000; %Number of samples
dt=0.01; %t axis sampling interval
df=1/N/dt; % f-axis sampling interval
tAxis=dt*( -ceil((N-1)/2):N-1-ceil((N-1)/2) ); %t-axis
fAxis=df*( -ceil((N-1)/2):N-1-ceil((N-1)/2) ); %Frequency axis
s=(1+M*cos(2*pi*Fm*tAxis)).*cos(2*pi*Fc*tAxis);
s=ifftshift(s);
f=abs(fft(s));
f=fftshift(f);
figure %The plot of Am signal in Frequency Domain
plot(fAxis, f);grid;
xlabel('f');
ylabel('S(f)');
title('AM signal in the frequency domain');
%values for the components of the envelope detector
c=0.01*(10^-6);%let the capacitance c=0.01^10-6
r=1./(Fc.*c);%Value of the resistance
T=r*c;%Taw
Tchar=0.63*T;%the charging time
Tdischar=0.37*T;%the discharging time
%%%Create the envelope detector%%%%
Vc=zeros(1,length(s));
Vc(1)=0; %inital voltage
%The demodulated signal
for k=2:length(s)
if (s(k)>(Vc(k-1)))
Vc(k)=s(k);
else
Vc(k)=Vc(k-1)-0.023*Vc(k-1);
end
end
figure
plot(t,Vc);grid;
Am Signal
1.5
0.5
-0.5
-1
-1.5
0.5
1.5
2.5
t
3.5
4.5
30
40
50
5000
S(f)
4000
3000
2000
1000
0
-50
-40
-30
-20
-10
0
f
10
20