All All 'Enter The Length of Message Sequence:' 'Enter The Sampling Frequency:'
All All 'Enter The Length of Message Sequence:' 'Enter The Sampling Frequency:'
if(fs<(2*T)) stop end MSG1=randint(T,1,M); MSG2=randint(T,1,M); disp('MESSAGE SEQUENCE 1'); disp(MSG1); disp('MESSAGE SEQUENCE 2'); disp(MSG2); figure; subplot(2,2,1); stem(MSG1); title('MESSAGE SIGNAL 1'); subplot(2,2,2); stem(MSG2); title('MESSAGE SIGNAL 2'); x=round(rand(1,T)); b2=num2str(x(1)); b1=num2str(x(2)); b0=num2str(x(3)); b=strcat(b2,b1,b0); PN1=[]; cb1=b; for i=1:1:T NB1=[strcat(num2str(xor(cb1(2),cb1(3))),cb1(1),cb1(2))]; PN1=[PN1 str2num(cb1(3))]; cb1=NB1; end disp('PN sequence 1'); disp(PN1); y=round(rand(1,T)); c2=num2str(y(1)); c1=num2str(y(2)); c0=num2str(y(3));
c=strcat(c2,c1,c0); PN2=[];cb2=c; for j=1:1:T NB2=[strcat(num2str(xor(cb2(2),cb2(3))),cb2(1),cb2(2))]; PN2=[PN2 str2num(cb2(3))]; cb2 = NB2; end disp('PN SEQUENCE 2'); disp(PN2); subplot(2,2,3); stem(PN1); title('PN SEQUENCE 1'); subplot(2,2,4); stem(PN2); title('PN SEQUENCE 2'); PN1 = PN1*2-1; MSG1 = MSG1*2-1; SPR1 =[]; for i = 1:1:length(MSG1) SPR1 =[MSG1*PN1(i)]; end disp('SPREADED SEQUENCES 1'); disp(SPR1); PN2 = PN2*2-1; MSG2 = MSG2*2-1; SPR2=[]; for j = 1:1:length(MSG2) SPR2 = [MSG2*PN2(j)]; end disp ('SPREADED SEQUENCES 2'); disp(SPR2); SPR1=SPR1*2-1; SPR2=SPR2*2-1; SIG=SPR1+SPR2; disp('ADDED SPREADED SEQUENCE'); disp(SIG) % PLOT ADDED SIGNAL % figure;
subplot(2,2,1); stem(SIG); title('SPREADED SIGNAL') % generate CDMA signal CDMA=amodce(SIG,fs,'amdsb-tc',M); disp('CDMA SEQUENCE') disp(CDMA); % PLOT cdma SIGNAL subplot(2,2,2); stem(CDMA); title('CDMA SIGNAL') % AWGN addition(at the channel) AWGN=awgn(CDMA,T,'measured'); disp('CHANNEL SEQUENCE'); disp(AWGN); %plot CHANNEL signal subplot(2,2,3); stem(AWGN); title('CHANNEL SIGNAL'); %CDMA demodulation DEMOD=ademodce(AWGN,fs,'amdsb-tc',M); disp('DEMODULATED SEQUENCE') disp(DEMOD); %plot CDMA demodulation signal subplot(2,2,4);
stem(DEMOD); title('DEMODULATED SIGNAL'); % despreaded signal RSPR2=DEMOD-SPR1; disp('RECEIVED SPREADED SEQUENCE 2') disp(RSPR2); % decession of despreaded signal2 for k=1:1:length(RSPR2) if(RSPR2(k)>=0) RSPR2(k)=1; else RSPR2(k)=-1; end end disp('DECESSION SEQUENCE 2') disp(RSPR2); %PLOT DESPREADING figure; subplot(2,2,3); stem(RSPR2); title('DECESSION SIGNAL 2'); % DECODED MESSAGE SIGNAL 2 PN2=PN2*2-1; RSPR2=RSPR2*2-1; OTP2=[]; MSGO2=[]; for g=1:1:length(PN2) OTP2=[RSPR2./PN2(g)]; end for f=1:1:length(OTP2) if(OTP2(f)<=0)
MSGO2(f)=0; else MSGO2(f)=1; end end disp('DECODED MESSAGE SEQUENCE 2') disp(MSGO2); % PLOT DECODED MESSAGE SIGNAL subplot(2,2,4); stem(MSGO2); title('DECODED MESSAGE SIGNAL 2');
% DESPREADED SIGNAL RSPR1= DEMOD-SPR2; disp('RECEIVED SPREADED SEQUENCE 1') disp(RSPR2) % decession of despreaded signal 1 for u=1:1:length(SPR1) if(RSPR1*(u)>=0) RSPR1(u)=1; else RSPR1(u)=-1; end end disp('DECESSION SEQUENCE 1'); disp(RSPR1); % PLOT DESPREADING subplot(2,2,1); stem(RSPR1) title('DECESSION SIGNAL 1') % DECODED MESSAGE SIGNAL 1
PN1=PN1*2-1; RSPR1=RSPR1*2-1; OTP1=[]; MSGO1=[]; for l=1:1:length(PN1) OTP1=[RSPR1./PN1(l)]; end for h=1:1:length(OTP1) if(OTP1(h)<=0) MSO1(h)=0; else MSGO1(h)=1; end end disp('DECODED MESSAGE SEQUENCE 1'); disp(MSGO1); % plot decoded message signal 1 subplot(2,2,2); stem(MSGO1); title('DECODED MESSAGE SIGNAL 1');