- #1

thavamaran

- 42

- 0

Hi guys, this is my first work in optical and first simulation in matlab. I am sorry if there is mistake and I am really new to this.

Here is what I did, I am simulation an entire Radio Over Fiber system with Matlab, linear system.

Let me insert my code first,

%*****************************Defining constant parameter****************

%Rb = 1e+6; %bit rate

%Tb = 1/Rb; %bit duration / period

Num_bits = 1e4; %number of bits

nsamp = 20; %samples per symbols

%Tsamp = Tb/nsamp; %sampling rate, fsamp = 20MHz.

a = 0.2; %channel attenuation, dB/km

L = 20; % Length of fiber

Gain = 10; %Gain in dB

%*****************************Filter definations************************

snr_dB=0:20; %SNR in dB from 0 to 20

SNR=10.^(snr_dB./10); %SNR in linear scale

Tx_filter = ones(1,nsamp); %transmitter filter, in terms of

% h(t),match filter

Rx_filter = fliplr(Tx_filter/nsamp); % receiver filter (matched filter),

% flip from left to right to make

% it h(T-t), match filter

Tx_OOK = randint(1,Num_bits); % randomly generating 1 and 0 in a

% row of matrix for 1000

% column,basically ON-OFF keying

% with random bits

%*****************************Channel input*****************************

Tx_OOKin = 0+Tx_OOK; % Tx+with power, 0dBm,ideal.

%*****************************Channel properties************************

Txch = Tx_OOKin -(a*L); %Signal in channel, deducting with

%channel attenuation=4dB

Txout = 10.^(Txch./10); %Changing back the signal to linear

%scale

Tx_signal = rectpulse(Txout,nsamp); % generate rectpulse for nsamp time

% per symbol

%*****************************Receiver**********************************

for i=1:length(snr_dB)

%*****************************Match filtering***************************

MF_out = conv(Rx_signal,Rx_filter); %equivalent to y(t)=x(t)*h(t)

MF_out_downsamp = MF_out(nsamp:nsamp:end); %sampling and hold

%try without truncation

%*****************************Thresholding*******************************

Rxth = zeros(1,Num_bits); %Reset receiver before thresholding

Rxth(find(MF_out_downsamp>0.45))=1; %value above 0.45 equivalent to one

%at the receiver, thresholding.

%*****************************BER CALC**********************************

ber(i) = biterr(Tx_OOK,Rxth); %Matlab function for ber

%******************Theoritical BER CALC**********************************

ber_pr(i) = Qfunct(sqrt(SNR(i))); %theoritical for ber

end

figure;

semilogy(snr_dB,ber,'b'); %Simulation

hold on;

semilogy(snr_dB,ber_pr,'r');

xlabel('SNR(dB)');

ylabel('BER');[/CODE]

Above is my entire code, the part i bold, i dun really get the idea, i took it from my friend cause at the receiver part, i don't really have an idea of how to receive the signal for at least with 10 different SNR rate and plot BER. My friend used the Match filter, but i don't really have the exact idea how match filter works.

The Tx_filter and Rx_filter part i got it where we flip the entire input from transmitter and at the receiver. which is h(t) from transmitter becomes h(-t).

I have uploaded the output and the blue line on the plot is the output that i got

Here is what I did, I am simulation an entire Radio Over Fiber system with Matlab, linear system.

Let me insert my code first,

Code:

%Rb = 1e+6; %bit rate

%Tb = 1/Rb; %bit duration / period

Num_bits = 1e4; %number of bits

nsamp = 20; %samples per symbols

%Tsamp = Tb/nsamp; %sampling rate, fsamp = 20MHz.

a = 0.2; %channel attenuation, dB/km

L = 20; % Length of fiber

Gain = 10; %Gain in dB

%*****************************Filter definations************************

snr_dB=0:20; %SNR in dB from 0 to 20

SNR=10.^(snr_dB./10); %SNR in linear scale

Tx_filter = ones(1,nsamp); %transmitter filter, in terms of

% h(t),match filter

Rx_filter = fliplr(Tx_filter/nsamp); % receiver filter (matched filter),

% flip from left to right to make

% it h(T-t), match filter

Tx_OOK = randint(1,Num_bits); % randomly generating 1 and 0 in a

% row of matrix for 1000

% column,basically ON-OFF keying

% with random bits

%*****************************Channel input*****************************

Tx_OOKin = 0+Tx_OOK; % Tx+with power, 0dBm,ideal.

%*****************************Channel properties************************

Txch = Tx_OOKin -(a*L); %Signal in channel, deducting with

%channel attenuation=4dB

Txout = 10.^(Txch./10); %Changing back the signal to linear

%scale

Tx_signal = rectpulse(Txout,nsamp); % generate rectpulse for nsamp time

% per symbol

%*****************************Receiver**********************************

for i=1:length(snr_dB)

**Rx_signal = awgn(Tx_signal,snr_dB(i)+3-10*log10(nsamp),'measured');**%*****************************Match filtering***************************

MF_out = conv(Rx_signal,Rx_filter); %equivalent to y(t)=x(t)*h(t)

MF_out_downsamp = MF_out(nsamp:nsamp:end); %sampling and hold

%try without truncation

%*****************************Thresholding*******************************

Rxth = zeros(1,Num_bits); %Reset receiver before thresholding

Rxth(find(MF_out_downsamp>0.45))=1; %value above 0.45 equivalent to one

%at the receiver, thresholding.

%*****************************BER CALC**********************************

ber(i) = biterr(Tx_OOK,Rxth); %Matlab function for ber

%******************Theoritical BER CALC**********************************

ber_pr(i) = Qfunct(sqrt(SNR(i))); %theoritical for ber

end

figure;

semilogy(snr_dB,ber,'b'); %Simulation

hold on;

semilogy(snr_dB,ber_pr,'r');

xlabel('SNR(dB)');

ylabel('BER');[/CODE]

Above is my entire code, the part i bold, i dun really get the idea, i took it from my friend cause at the receiver part, i don't really have an idea of how to receive the signal for at least with 10 different SNR rate and plot BER. My friend used the Match filter, but i don't really have the exact idea how match filter works.

The Tx_filter and Rx_filter part i got it where we flip the entire input from transmitter and at the receiver. which is h(t) from transmitter becomes h(-t).

I have uploaded the output and the blue line on the plot is the output that i got