UTP Category 6 Response
% MATLAB Code for RS coding and decoding
clc;
clear all;
close all;
n=7; k=3; % Codeword and message word lengths
m=3; % Number of bits per symbol
msg = gf([5 2 3; 0 1 7;3 6 1],m) % Two k-symbol message words
% message vector is defined over a Galois field where the number must
%range from 0 to 2^m-1
codedMessage = rsenc(msg,n,k) % Two n-symbol codewords
dmin=n-k+1 % display dmin
t=(dmin-1)/2 % diplay error correcting capability of the code
% Generate noise – Add 2 contiguous symbol errors with first word;
% 2 discontiguous symbol errors with second word and 3 distributed symbol
% errors to last word
noise=gf([0 0 0 2 3 0 0 ;6 0 1 0 0 0 0 ;5 0 6 0 0 4 0],m)
received = noise+codedMessage
%dec contains the decoded message and cnumerr contains the number of
%symbols errors corrected for each row. Also if cnumerr(i) = -1 it indicates
%that the ith row contains unrecoverable error
[dec,cnumerr] = rsdec(received,n,k)
% print the original message for comparison
msg
msg = GF(2^3) array. Primitive polynomial = D^3+D+1 (11 decimal)
Array elements =
5 2 3
0 1 7
3 6 1
codedMessage = GF(2^3) array. Primitive polynomial = D^3+D+1 (11 decimal)
Array elements =
5 2 3 5 4 4 2
0 1 7 6 6 0 7
3 6 1 7 4 0 2
dmin =
5
t =
2
noise = GF(2^3) array. Primitive polynomial = D^3+D+1 (11 decimal)
Array elements =
0 0 0 2 3 0 0
6 0 1 0 0 0 0
5 0 6 0 0 4 0
received = GF(2^3) array. Primitive polynomial = D^3+D+1 (11 decimal)
Array elements =
5 2 3 7 7 4 2
6 1 6 6 6 0 7
6 6 7 7 4 4 2
dec = GF(2^3) array. Primitive polynomial = D^3+D+1 (11 decimal)
Array elements =
5 2 3
0 1 7
6 6 7
cnumerr =
2
2
-1
msg = GF(2^3) array. Primitive polynomial = D^3+D+1 (11 decimal)
Array elements =
5 2 3
0 1 7
3 6 1
% 64B/66B Block Encoding
close all;
clear all;
clc;
msg = randint(1,64)
t1 = 0:63;
t2 = 0:65;
pre=input(‘whether Data (0) or Control+Data Bits (1) ‘);
if pre == 0
code = [ 0 1 msg]
else
code = [ 1 0 msg]
end
figure
subplot(2,1,1)
stairs(t1, msg,’b’)
xlabel(‘Number of bits’)
ylabel(‘Amplitude’)
title(’64B/66B Block Coding’)
legend(’64B’)
grid on;
hold on;
subplot(2,1,2)
stairs(t2, code,’g’)
grid on;
legend(’66B’)
title(’64B/66B Block Coding’)
xlabel(‘Number of bits’)
ylabel(‘Amplitude’)
msg =
Columns 1 through 11
1 1 0 1 0 0 0 0 0 0 0
Columns 12 through 22
0 0 1 0 1 1 0 1 0 0 0
Columns 23 through 33
1 1 0 0 1 1 0 0 1 0 0
Columns 34 through 44
0 0 1 1 0 1 1 1 0 1 1
Columns 45 through 55
1 1 1 1 0 0 0 0 1 0 0
Columns 56 through 64
0 0 1 0 1 1 1 0 0
whether Data (0) or Control+Data Bits (1) 0
code =
Columns 1 through 11
0 1 1 1 0 1 0 0 0 0 0
Columns 12 through 22
0 0 0 0 1 0 1 1 0 1 0
Columns 23 through 33
0 0 1 1 0 0 1 1 0 0 1
Columns 34 through 44
0 0 0 0 1 1 0 1 1 1 0
Columns 45 through 55
1 1 1 1 1 1 0 0 0 0 1
Columns 56 through 66
0 0 0 0 1 0 1 1 1 0 0
l = fec.ldpcenc
l =
% LDPC Encoder
clear all;
close all;
clc;
% Construct a LDPC encoder object
i = [1 3 2 4 1 2 3 3 4]; % row indices of 1s
j = [1 1 2 2 3 4 4 5 6]; % column indices of 1s
H = sparse(i,j,ones(length(i),1)) % parity-check matrix H
l = fec.ldpcenc(H)
% Generate a random binary message
msg = randint(1,l.NumInfoBits,2)
% Encode the message
codeword = encode(l, msg)
% Verify the parity checks (which should be a zero vector)
paritychecks = mod(l.ParityCheckMatrix * codeword’, 2)
H =
l =
msg =
codeword =
paritychecks =
h = fec.ldpcdec
h =
% LDPC Decoder
clear all;
close all;
clc;
i = [1 3 2 4 1 2 3 3 4]; % row indices of 1s
j = [1 1 2 2 3 4 4 5 6]; % column indices of 1s
H = sparse(i,j,ones(length(i),1)) % parity-check matrix H
l = fec.ldpcdec(H)
H =
l =
h = modem.pammod(‘M’,16)
h =
h = modem.pamdemod(‘M’,16)
h =
% NRZ
function [U]=nrz(a)
% ‘a’ is input data sequence
% U = Unipolar
% Wave formatting
% Example: Take
closeall;
clearall;
clc;
a=[1 0 1 1 0 1 1];
% Unipolar
U=a;
n = length(a);
% Plotting Waves
bpuls(U)
axis( [1 n+2 -2 2] )
title(‘Unipolar NRZ’)
xlabel(‘Time’)
ylabel(‘Amplitude’)
grid on;
% Spetra Calculation, Taking 512 points FFT
f=1000*(0:256)/512;
% unipolar
yu=fft(U, 512);
pu=yu.*conj(yu)/512;
% Power spectra PLOT
figure;
plot(f,pu(1:257),’-k’,’linewidth’,2)
hold on
title(‘Power Spectra Plot’)
function bpuls(a)
n=length(a);
b=a;
b(n+1)=b(n); %retaining last value for entire last duration
stairs(b,’linewidth’,2)
axis([1 length(b) min(b)-0.5 max(b)+0.5])
% Current ISO Cat-6 Channel Specifications
clc;
clear all;
close all;
freq = [ 1 4 10 16 20 31.25 62.5 100 125 155.52 175 200 250 ];
atten = -1*[ 2.2 4.2 6.5 8.3 9.3 11.7 16.9 21.7 24.5 27.6 29.5 31.7 36.0 ];
prprNEXT = -1*[ 72.7 63.0 56.6 53.2 51.6 48.4 43.4 39.9 38.3 36.7 35.8 34.8 33.1 ];
PSNEXT = -1*[ 70.3 60.5 54.0 50.6 49.0 45.7 40.6 37.1 35.4 33.8 32.9 31.9 30.2 ];
prprELFEXT = -1*[ 63.2 51.2 43.2 39.1 37.2 33.3 27.3 23.2 21.3 19.4 18.4 18.4 17.2 ];
PSELFEXT = -1*[ 60.2 48.2 40.2 36.1 34.2 30.3 24.3 20.2 18.3 16.4 15.4 15.4 14.2 ];
ReturnLoss = -1*[ 19.0 19 19 19 19 17.1 14.1 12.0 11.0 10.1 9.6 9.0 8.0 ];
PhaseDelay = -1*[ 580 563 556.8 554.5 553.6 552.1 550.3 549.4 549 548.7 548.6 548.4 548.2];
DelaySkew = -1*[ 50.0 50 50 50 50 50 50 50 50 50 50 50 50 ];
figure;
semilogy(freq,atten,’b’);
hold on;
grid on;
semilogy(freq,prprNEXT,’r’);
semilogy(freq,PSNEXT,’c’);
semilogy(freq,prprELFEXT,’g’);
semilogy(freq,PSELFEXT,’m’);
semilogy(freq,ReturnLoss,’k’);
semilogy(freq,PhaseDelay,’–b’);
semilogy(freq,DelaySkew,’y’);
title(‘Category 6 Cable Channel Specifications’);
xlabel(‘Frequency in MHz’);
ylabel(‘Loss in dB’);
xlim = [0.0 250.0];
ylim = [0 -40];
legend(‘Attenuation’,’NEXT’,’PSNEXT’,’ELFEXT’,’PSELFEXT’,’Return Loss’,’Phase Delay’,’Delay Skew’);
% Performance of Cat 6 UTP Cable
clc;
close all;
clear all;
freq = [ 0.772 1.0 4.0 8.0 10.0 16.0 20.0 25.0 31.25 62.5 100.0 200.0 250.0 ];
InsertnLoss = [ -1.8 -2.0 -3.8 -5.3 -6.0 -7.6 -8.5 -9.5 -10.7 -15.4 -19.8 -29.0 -32.8 ];
NEXT = [ -76.0 -74.3 -65.3 -60.8 -59.3 -56.2 -54.8 -53.3 -57.9 -47.4 -44.3 -39.8 -38.3 ];
PSNEXT = [ -74.0 -72.3 -63.3 -58.8 -57.3 -54.2 -52.8 -51.3 -49.9 -45.4 -42.3 -37.8 -36.3 ];
ELFEXT = [ -70.0 -67.8 -55.8 -49.7 -47.8 -43.7 -41.8 -39.8 -37.9 -31.9 -27.8 -21.8 -19.8 ];
PSELFEXT = [ -67.0 -64.8 -52.8 -46.7 -44.8 -40.7 -38.8 -36.8 -34.9 -28.9 -24.8 -18.8 -16.8 ];
ReturnLoss = [ 0 -20.0 -23.0 -24.5 -25.0 -25.0 -25.0 -24.3 -23.6 -21.5 -20.1 -18.0 -17.3 ];
LCL = [ 0 -40.0 -40.0 -40.0 -40.0 -38.0 -37.0 -36.0 -35.1 -32.0 -30.0 -27.0 -26.0 ];
figure;
semilogy(freq,InsertnLoss,’b’);
hold on;
grid on;
semilogy(freq,NEXT,’r’);
semilogy(freq,PSNEXT,’c’);
semilogy(freq,ELFEXT,’g’);
semilogy(freq,PSELFEXT,’m’);
semilogy(freq,ReturnLoss,’k’);
semilogy(freq,LCL,’y’);
title(‘Frequency Response of Category 6 Cable’);
xlabel(‘Frequency in MHz’);
ylabel(‘Loss in dB’);
xlim = [0.0 250.0];
ylim = [0 -40];
legend(‘Insertion Loss’,’NEXT’,’PSNEXT’,’ELFEXT’,’PSELFEXT’,’Return Loss’,’LCL’);
% Reed-Solomon Errors
% with AWGN Channel
% Plot of BER vs SNR
clear all;
clc;
close all;
snr = 0:1:15;
n = 0.5; %over sampling rate
M = 4; % no. of symbols
k = log2(M); % no. of bits per symbol
Ebno = snr – 10*log10(k) + 10*log10(n);
% Theoritical performance without encoder
bit = berawgn(Ebno,‘psk’,M,‘diff’);
% msg length
K = 13;
% codeword length
N = (2^M)-1;
%Theoritical performance with RS encoder
berub = bercoding(Ebno,‘RS’,‘hard’,N,K);
% Plotting BER vs SNR
semilogy(snr,bit,‘r’);
hold on;
semilogy(snr,berub,‘g’);
grid on;
legend(‘No Encoder’,‘RS Encoder’);
xlabel(‘SNR’);
ylabel(‘BER’);
hold on;