7.3 MATLAB Files

7.3.1 Probability of Error Calculation

 
 x=[0:0.01:100]; for i=100:1000 Pe(i)=0.01*sqrt(2/pi)*sum(exp(-0.5*x(i:10000).^2)); end 

7.3.2 Squared Root Nyquist Filter

 
 x=[-35:35]/7; alp=0.5; gx=(sin(pi*(1-alp)*x)+4*alp.*x.*cos(pi*(1+alp).*x))./(pi*x.*(1-(4*alp*x).^2)); gx(36)=(1-alp)+4*alp/pi; figure(1) plot(gx) xlabel('Filter Coefficients') [gf,w]=freqz(gx,1,100); figure(2) plot([1:100]/100*20e6, 20*log10(abs(gf))) grid xlabel('Frequency (Hz)') ylabel('Magnitude (dB)') 

7.3.3 Channel Capacity Calculation

 
 logh1=20*log10(abs(H1(1:1025))); logh2=20*log10(abs(H2(1:1025))); SNR1=logh1+140-72; SNR2=logh2+140-72; figure(4) plot(f,SNR1,f,SNR2) grid xlabel('Frequency (Hz)') ylabel('SNR (dB)') gtext('Loop #6') gtext('Loop #8') capci1=sum(log2(1+10.^(SNR1(204:512)/10)))*20e6/1025 capci2=sum(log2(1+10.^(SNR2(204:512)/10)))*20e6/1025 

7.3.4 HCS

 
 %Variable initialization gx=[1 1 1 0 1 0 1 0 1]; hx=[1 1 1 1 0 1 1 1]; FT=[0 0 0 0 0 0 0 0]; RSVD=[0]; PRI=[0 1 0]; SI=[0 1 0 0]; PE=[0 0 0 0 1 0 1 0]; HCS=[0 0 0 0 0 0 0 0]; FC=[FT RSVD PRI SI PE HCS]; DA=ceil(rand(1,48)*2-1); SA=ceil(rand(1,48)*2-1); FC2SA=[FC DA SA]; %Mathematically, the CRC value corresponding to a given frame %is defined by the following procedure. %  The first 8 bits of the input bit sequence are complemented. FC2SA(1:8)=bitcmp(FC2SA(1:8),1); %  The 128 bits of the sequence is multiplied by x^8 and %  divided %  by G(x), producing a remainder R(x) of degree <= 7. FC2SA=[FC2SA zeros(1,8)]; rx=FC2SA(1:8); for i=1:128     nm=[rx FC2SA(i+8)];     if nm(1)==1         rx=xor(nm(2:9),gx(2:9));     else         rx=nm(2:9);     end end %  R(x) is multiplied by H(x) to produce N(x) nx(1:8)=rx; for i=1:7     if hx(i+1)==1         nx(i+1:i+7)=xor(rx(1:7),nx(i+1:i+7));         nx(i+8)=rx(8);     else         nx(i+8)=0;     end end %  N(x) is divided by G(x), producing a remainder R'(x) of %  degree <= 7. rrx=nx(1:8); for i=1:7     nm=[rrx nx(i+8)];     if nm(1)==1         rrx=xor(nm(2:9),gx(2:9));     else         rrx=nm(2:9);     end end %  The bit sequence is complemented and the result is the CRC'. rrx=bitcmp(rrx,1); %The 8 bits of the CRC' are placed in the HCS field so that x^7 %is the least-significant bit of the octet and x^0 term is the %most-significant bit of the octet. The bits of the CRC' are %thus transmitted in the order x^7, x^6, .. x^1, x^0. 

7.3.5 CRC16

 
 %Variable initialization gx=[1 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 1]; x=ceil(rand(1,1000)*2-1); x=[x zeros(1,16)]; %Mathematically, the CRC value corresponding to a given frame %is defined by the following procedure. %  The first 16 bits of the input bit sequence are %  complemented. rx=bitcmp(x(1:16),1); %  The bit sequence is divided by G(x), producing a remainder %  R(x) of degree <= 15. for i=1:1000     nm=[rx x(i+16)];     if nm(1)==1         rx=xor(nm(2:17),gx(2:17));     else         rx=nm(2:17);     end end rx=bitcmp(rx,1); 

7.3.6 HomePNA 2.0 Transceiver

 
 %SYMBOL ENCODING SEQ16=[1 1 1 1 1 1 0 0 0 1 0 0 1 0 0 0 0 0 1 1 0 0 0 0 1 0 0 0 0 1 0 0]; PREA64=[SEQ16 SEQ16 SEQ16 SEQ16]; % Call for hcs.m routine hcs FC=[FT RSVD PRI SI PE rrx]; ET=ceil(rand(1,16)*2-1); EOF=[1 1 1 1 1 1 0 0]; PKT=[PREA64 FC DA SA ET EOF]; %2 Mbaud with zero insertion x=zeros(1,280); x(1:2:280)=PKT(2:2:280)*2-1; ak=x; y=zeros(1,280); y(1:2:280)=PKT(1:2:280)*2-1; bk=y; %MODULATION %7 times up sampling xup7=zeros(1,1960); xup7(1:7:1960)=x; yup7=zeros(1,1960); yup7(1:7:1960)=y; % Call for filter gx routine sqnqf7 xfilt=conv(xup7,gx); yfilt=conv(yup7,gx); t=[0:2128]/28e6; cos2pift=cos(2*pi*7e6*t); sin2pift=sin(2*pi*7e6*t); xcos=xfilt.*cos2pift(1:2030); ysin=yfilt.*sin2pift(1:2030); ft=xcos+ysin; %PASSING CHANNEL % Get channel impulse response load loop8 %loop8=zeros(100,1); %loop8(13:15)=[0.5 1 0.5]; ftlp=conv(loop8,ft); %DEMODULATION xlp=ftlp.*cos2pift; ylp=ftlp.*sin2pift; xlpf=2*conv(xlp,gx); ylpf=2*conv(ylp,gx); xlpfd=xlpf(70:7:2199); ylpfd=ylpf(70:7:2199); %EQUALIZER INITILIZATION rxx=zeros(20,20); ryy=zeros(20,20); rxy=zeros(20,20); ryx=zeros(20,20); rax=zeros(20,1); ray=zeros(20,1); rbx=zeros(20,1); rby=zeros(20,1); xk=zeros(20,1); yk=zeros(20,1); for i=1:128     xk(:,1)=xlpfd(i:i+19)';     yk(:,1)=ylpfd(i:i+19)';     rxx=rxx+xk*xk'/128;     ryy=ryy+yk*yk'/128;     rxy=rxy+xk*yk'/128;     ryx=ryx+yk*xk'/128;     rax=rax+ak(i)*xk/128;     ray=ray+ak(i)*yk/128;     rbx=rbx+bk(i)*xk/128;     rby=rby+bk(i)*yk/128; end eq=inv([rxx rxy; ryx ryy])*[rax' ray']'; eq1=inv([ryy ryx; rxy rxx])*[rby' rbx']'; eqi=eq(1:20)/2+eq1(1:20)/2; eqx=eq(21:40)/2-eq1(21:40)/2; %ADAPTIVE EQUALIZATION for i=1:280     xf=xlpfd(i:i+19);     yf=ylpfd(i:i+19);     xout(i)=xf*eqi+yf*eqx;     yout(i)=yf*eqi-xf*eqx;     e1=ak(i)-xout(i);     e2=bk(i)-yout(i);     eqi=eqi+0.001*xf'*e1;     eqx=eqx+0.001*yf'*e1;     eqi=eqi+0.001*yf'*e2;     eqx=eqx+0.001*xf'*e2; end figure(1) plot([1:280],xout) xlabel('Real Data') figure(2) plot([1:280],yout) xlabel('Imaginary Data') figure(3) plot([1:20],eqi,[1:20],eqx) xlabel('Equalizer Coefficients') %DATA RECOVERY for i=1:280     if xout(i)>0         xr(i)=1;     else         xr(i)=0;     end     if yout(i)>0         yr(i)=1;     else         yr(i)=0;     end end PKTR=zeros(1,280); PKTR(2:2:280)=xr(1:2:280); PKTR(1:2:280)=yr(1:2:280); 


Home Network Basis(c) Transmission Environments and Wired/Wireless Protocols
Home Networking Basis: Transmission Environments and Wired/Wireless Protocols
ISBN: 0130165115
EAN: 2147483647
Year: 2006
Pages: 97

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net