Download - assn5

Transcript

to=0.1;ts=0.0001; %sampling intervalfs=1/ts; %sample frequencyfc=250; %carrier wave frequencya=0.8; %loop for the two values of tot=0:ts:to;N=to/ts; %number of samples%%%%%PART-1%defining and plotting m(t) and u(t)m=sinc(100*t); %message signalc=cos(2*pi*fc*t);u=(1+a*m).*cos(2*pi*fc*t);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-6figure(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',sigma1)); 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