ber_cal

4
% This code determines the Bit Error Rate (BER) of a optical link % comprising a Fiber Bragg Gratings sensor. %--------------FBG NARROW-BAND FILTER ------------------------- % This script design a FBG narrowband filter. The Bragg wavelength shift % is due in this code to the application of a pression on the FBG. A % pression of 10 bars correspond to a shift of 7.5 picometers or to a force % of 1N over 1 mm². Let us consider % the effect of forces of 20 40 60 % and 100N. % Filter parameters clear all close all clc format long lambdashift = 7.5*1e-12*[20 40 60 100]; for ii = 1 : length(lambdashift) lambda(ii) = 1525e-9-lambdashift(ii); lambda_s(ii) = 10*lambda(ii); deltalambda = 100e-12; lambda1(ii) = lambda(ii)-deltalambda; lambda2(ii) = lambda(ii)+deltalambda; end lambda_c = [lambda1' lambda2']; M = 4000; % ------ Filter design --------------------------------- figure [d1, c1] = butter(2, lambda_c(1,:)/(lambda_s(1)/2), 'stop'); [h,ff] = freqz(d1, c1, M, lambda_s(1)); plot(ff,20 * log10(abs(h)),'g','linewidth',1.5) grid on; hold on [d2, c2] = butter(2, lambda_c(2,:)/(lambda_s(2)/2), 'stop'); [h,ff] = freqz(d2, c2, M, lambda_s(2)); plot(ff,20 * log10(abs(h)),'r','linewidth',1.5) [d3, c3] = butter(2, lambda_c(3,:)/(lambda_s(3)/2), 'stop'); [h,ff] = freqz(d3, c3, M, lambda_s(3)); plot(ff,20 * log10(abs(h)),'b','linewidth',1.5) [d4, c4] = butter(2, lambda_c(4,:)/(lambda_s(4)/2), 'stop'); [h,ff] = freqz(d4, c4, M, lambda_s(4)); plot(ff,20 * log10(abs(h)),'k','linewidth',1.5) hold off xlabel('Wavelength (nm)') ylabel('Magnitude (dB)') title ('FBG stopband filter') axis([1510e-9 1540e-9 -145 20]) legend('1','2','3','4') 1

description

BER determination

Transcript of ber_cal

Page 1: ber_cal

% This code determines the Bit Error Rate (BER) of a optical link% comprising a Fiber Bragg Gratings sensor.

%--------------FBG NARROW-BAND FILTER -------------------------

% This script design a FBG narrowband filter. The Bragg wavelength shift% is due in this code to the application of a pression on the FBG. A% pression of 10 bars correspond to a shift of 7.5 picometers or to a force% of 1N over 1 mm². Let us consider % the effect of forces of 20 40 60% and 100N.

% Filter parameters

clear allclose allclcformat long

lambdashift = 7.5*1e-12*[20 40 60 100];for ii = 1 : length(lambdashift)

lambda(ii) = 1525e-9-lambdashift(ii);

lambda_s(ii) = 10*lambda(ii);deltalambda = 100e-12;lambda1(ii) = lambda(ii)-deltalambda;lambda2(ii) = lambda(ii)+deltalambda;

end

lambda_c = [lambda1' lambda2'];

M = 4000;

% ------ Filter design ---------------------------------

figure[d1, c1] = butter(2, lambda_c(1,:)/(lambda_s(1)/2), 'stop');[h,ff] = freqz(d1, c1, M, lambda_s(1));plot(ff,20 * log10(abs(h)),'g','linewidth',1.5)grid on;hold on

[d2, c2] = butter(2, lambda_c(2,:)/(lambda_s(2)/2), 'stop');[h,ff] = freqz(d2, c2, M, lambda_s(2));plot(ff,20 * log10(abs(h)),'r','linewidth',1.5)

[d3, c3] = butter(2, lambda_c(3,:)/(lambda_s(3)/2), 'stop');[h,ff] = freqz(d3, c3, M, lambda_s(3));plot(ff,20 * log10(abs(h)),'b','linewidth',1.5)

[d4, c4] = butter(2, lambda_c(4,:)/(lambda_s(4)/2), 'stop');[h,ff] = freqz(d4, c4, M, lambda_s(4));plot(ff,20 * log10(abs(h)),'k','linewidth',1.5)hold offxlabel('Wavelength (nm)')ylabel('Magnitude (dB)')title ('FBG stopband filter')axis([1510e-9 1540e-9 -145 20])legend('1','2','3','4')

1

Page 2: ber_cal

% ---------------- BER DETERMINATION ---------------------------

% -----------------Digital Modulant signal ---------------------td = 9e-4; % signal durationt=0:1/1e7:td-1/1e7; % Time vector

lambda_c = 1550e-9;c = 3e8;f_c = c/lambda_c;fm = 1e6;s = 0.5*(1+square(2*pi*fm*t));

b=s;% --------------- ASK Modulation ----------------------------------n = length(b);f1=1;f2=f_c;Fs = 1e7;t=0:1/Fs:1e-4-1/Fs;

sa1=sin(2*pi*f2*t);E1=sum(sa1.^2);sa1=sa1/sqrt(E1);sa0=0*sin(2*pi*f1*t);

ask=[];

for i=1:nif b(i)==1

ask=[ask sa1];else

ask=[ask sa0];

endendfiguresubplot(211)stairs(0:10,[b(1:10) b(10)],'linewidth',1.5)axis([0 10 -0.5 1.5])title('Message Bits');grid onsubplot(212)tb=0:1/1000:10-1/1000;plot(tb, ask(1:10*1000),'b','linewidth',1.5)title('ASK Modulation');grid on

%------------------ AWGN channel design and filtering --------------

askf1 = filter(d1,c1,ask);askf2 = filter(d2,c2,ask);askf3 = filter(d3,c3,ask);askf4 = filter(d4,c4,ask);for snr=0:20

askn1=awgn(askf1,snr);askn2=awgn(askf2,snr);askn3=awgn(askf3,snr);askn4=awgn(askf4,snr);

% ------------ ASK Detection (Demodulation)-----------------A1=[]; A2=[]; A3=[];A4=[];

for i=1:n% First filterif sum(sa1.*askn1(1+1000*(i-1):1000*i)) > 0.5

A1=[A1 1];

2

Page 3: ber_cal

elseA1=[A1 0];

end% 2nd Filterif sum(sa1.*askn2(1+1000*(i-1):1000*i)) > 0.5

A2=[A2 1];else

A2=[A2 0];end% 3rd Filter

if sum(sa1.*askn3(1+1000*(i-1):1000*i)) > 0.5A3=[A3 1];

elseA3=[A3 0];

end

% 4th Filterif sum(sa1.*askn4(1+1000*(i-1):1000*i)) > 0.5

A4=[A4 1];else

A4=[A4 0];

endend

% ---------------- ASK BER Determination --------------------

errA1=0; errA2=0; errA3=0;errA4=0;

for i=1:nif A1(i)==b(i)

errA1=errA1;else

errA1=errA1+1;end

if A2(i)==b(i)errA2=errA2;

elseerrA2=errA2+1;

end

if A3(i)==b(i)errA3=errA3;

elseerrA3=errA3+1;

end

if A4(i)==b(i)errA4=errA4;

elseerrA4=errA4+1;

end

endBER_A1(snr+1)=errA1/n;BER_A2(snr+1)=errA2/n;BER_A3(snr+1)=errA3/n;BER_A4(snr+1)=errA4/n;

end% ------------------ Theoretical ASK BER Calculation --------------

Eo_No = 0:23;a = 2/5/pi; % scale factortheoBer = 0.5*erfc(sqrt((a*(10.^(Eo_No/10)))));

3

Page 4: ber_cal

figuresemilogy(0:20,BER_A1, 'b-','linewidth',1.5)grid on;hold onsemilogy(0:20,BER_A2,'r','linewidth',1.5)semilogy(0:20,BER_A3, 'k','linewidth',1.5)semilogy(0:20,BER_A4, 'm','linewidth',1.5)semilogy(0:23,theoBer,'g*-','linewidth',1.5);xlabel('Eo/No(dB)')ylabel('BER')title('BER vs Eo/No')axis([0 16 1e-4 1])hold offlegend('20 N','40 N','60 N','100 N', 'Theoretical BER');

Published with MATLAB® 7.9

4