You are on page 1of 2

to=0.

1;
ts=0.0001;
fs=1/ts;
fc=250;
a=0.8;

%sampling interval
%sample frequency
%carrier wave frequency
%loop for the two values of to

t=0:ts:to;
N=to/ts;
%%%%%PART-1
%defining and plotting m(t) and u(t)
m=sinc(100*t);
c=cos(2*pi*fc*t);
u=(1+a*m).*cos(2*pi*fc*t);

%number of samples
%message signal

figure(1);
subplot(211);
plot(t,m);
title('message signal m(t)');
xlabel('t');
ylabel('m(t)');
subplot(212);
plot(t,u);
title('modulated signal u(t)');
xlabel('t');
ylabel('u(t)');
%%%%%PART-2
% Generating 2,000 samples of a Gaussian random variable with zero mean
% and variance 2 using Box-Muller method.
mean=0;
variance=2;
x=rand(2,2000);
x1=x(1,:);
x2=x(2,:);
z1 = mean+sqrt(variance)*(sqrt(-2*log(x1)).*sin(2*pi*x2));
%z2 = mean+sigma*(sqrt(-2*log(u1)).*cos(2*pi*u2));
wc=z1(1,1:1000);
ws=z1(1,1001:2000);
sigma=[0.1 1 2];
figure(2);
for i=1:3
%loop for taking different sigma
sigma1=sigma(i);
for k=1:1000
r(i,k)=u(k)+sigma1*(wc(k)*cos(2*pi*fc*t(k))-ws(k)*sin(2*pi*fc*t(k)));
end
R = r(i,:);
subplot(3,1,i);
plot(R);
title(sprintf('Recieved signal sequence r(t) for sigma %1.1f',sigma1));
ylabel('R(t)');
end
%%%%%PART-3, PART-4, PART-5 and PART-6
figure(3);
for i=1:3
%loop for taking different sigma

sigma1=sigma(i);
mn=0;
smu2=0;
smn2=0;
for k=1:1000
e(i,k)=((1+a*m(k)+sigma1*wc(k))^2+(sigma1*ws(k))^2)^0.5;
mn=mn+e(i,k);
%summation of all the terms of e
n(k)=sigma1*(wc(k)*cos(2*pi*fc*t(k))-ws(k)*sin(2*pi*fc*t(k))); %noise signal
u2(k)=u(k)^2;
n2(k)=n(k)^2;
smu2=smu2+u2(k);
%summation of all the terms of u2
smn2=smn2+n2(k);
%summation of all the terms of n2
end
mnu2=smu2/N;
mnn2=smn2/N;
snr=mnu2/mnn2;

%snr=expectatn(u^2)/expectatn(n^2)

E = e(i,:);
%finding the dc offset
DC=mn/N;
%DC offset is the mean of the e(t)
%plotting the envelop and comparing with msg
subplot(3,1,i);
plot(m);
hold on;
plot(E,'r');
hold off;
title(sprintf('Envelop detector e(t) and m(t) compared for sigma %1.1f',sigm
a1));
ylabel('e(t)');
disp(sprintf('DC offset for sigma %1.1f is %1.3f',sigma1,DC));
disp(sprintf('SNR for sigma %1.1f is %1.3f \n',sigma1,snr))
end

You might also like