communication - Matlab Code for BER Calculation in a Optical Wireless System -
i simulated visible light communication (vlc) system awgn (additive white gaussian noise) channel , plotted ber (bit error rate) against ebno. used led (light emitting diode) impulse response , convolved signal produced transmitting. results not ok. means ber fixed or 0.5. pam-dmt (pulse amplitude modulation-discrete multi-tone) system transmitter 50*50 array of leds. input binary sequence modulated pam modulator. used make ofdm symbols pam-dmt algorithm. ofdm symbols modulated led intensity , transmitted channel. @ receiver side, after demodulating received symbols, received binary sequence compared input binary sequence calculate ber. in each ofdm symbol, there data carriers, pilot symbol carriers , null carriers. think problem scheme use cut extended length (made convolving led input led impulse response) of transmitted signal @ receiver side. me if wrong? in advance.
here matlab code:
clear,clc; close all; %% k=4;m=2^k; %4 bits per pam symbol% c=3*1e8; %m/ns f_3db=15e6;%1/ns n=32; r=0.54;%responsivity @ a/w% ro=0.8;% reflection coefficient ar=1e-4; index=1.5; carier_freqspac=f_3db/n; t_sym=1/f_3db;%the time of pam symbol 0.5us or 500ns. tb=t_sym/k; rb=1/tb; t_ifft=1/carier_freqspac; l_cp=n/4; t_cp=t_sym*l_cp; t_ofdmsym=t_ifft+t_cp; %ofdm symbol duration 4us% l_ofdm_sym=n+l_cp; n_pilot_carrier=n/16; n_null=n/16; n_data_carrier=n-n_null-n_pilot_carrier; nofdm=2e4; ttran_ofdm_sym=((n_data_carrier+n_pilot_carrier)*t_sym)+t_cp; rb_ofdm=((n_data_carrier+n_pilot_carrier)*k)/ttran_ofdm_sym;% @ b/s hpammod=comm.pammodulator(m,'bitinput',true); hpam_demod=comm.pamdemodulator(m,'bitoutput',true); %pilots in 1st half if n==32; ps=[1]; elseif n==64; ps=[-1 1]; elseif n==128; ps=[-1 -1 1 1]; end; input_b=randi([0,1],nofdm*(n_data_carrier/2)*k,1); n_bit=length(input_b); pam_sym=step(hpammod,input_b); n_pamsym=n_bit/k; pam_sym=reshape(pam_sym,n_data_carrier/2,nofdm); pam_sym_ps_1st=[]; if n==32; i=1:nofdm; pam_sym_ps_1st=1j.*[0;pam_sym(1:14,i);ps(1)]; pam_sym_ps_1st=[pam_sym_ps_1st pam_sym_ps_1st]; pam_sym_ps_2nd=circshift(conj(flipud(pam_sym_ps_1st)),1); pam_sym_ps_2nd=[pam_sym_ps_2nd pam_sym_ps_2nd]; end; elseif n==64; i=1:nofdm; pam_sym_ps_1st=1j.*[0;pam_sym(1:14,i);ps(1);0;pam_sym(15:28,i);ps(2)]; pam_sym_ps_1st=[pam_sym_ps_1st pam_sym_ps_1st]; pam_sym_ps_2nd=circshift(conj(flipud(pam_sym_ps_1st)),1); pam_sym_ps_2nd=[pam_sym_ps_2nd pam_sym_ps_2nd]; end; elseif n==128; i=1:nofdm; pam_sym_ps_1st=1j.* [0;pam_sym(1:14,i);ps(1);0;pam_sym(15:28,i);ps(2);0;pam_sym(29:42,i);ps(3);0;pam_sym(43:56,i);ps(4)]; pam_sym_ps_1st=[pam_sym_ps_1st pam_sym_ps_1st]; pam_sym_ps_2nd=circshift(conj(flipud(pam_sym_ps_1st)),1); pam_sym_ps_2nd=[pam_sym_ps_2nd pam_sym_ps_2nd]; end; end; ifft_in=[pam_sym_ps_1st;pam_sym_ps_2nd]; ifft_out=ifft(ifft_in,n); cp=ifft_out(n-l_cp+1:n,:); ofdm_sym=[cp;ifft_out]; ofdm_sym1=reshape(ofdm_sym,l_ofdm_sym*nofdm,1);% p/s% uni_ofdm_sym=(ofdm_sym1+abs(ofdm_sym1))./2; % t=0:t_sym:100e-9;%ns t=0:t_sym:100e-9;%ns n_led=2500; hled=(n_led).*exp((-2*pi*f_3db).*t); hled=hled./sum(hled); ledin=48e-6*n_led+uni_ofdm_sym; optsig=r.*conv(ledin,hled); l=length(optsig)-length(ofdm_sym1); ebno_db=0:20; snr_db=ebno_db+10*log10((n/n+l_cp))... +10*log10(((n_data_carrier+n_pilot_carrier)/n))+10*log10(k); ber=zeros(1,length(snr_db)); rr=1:length(snr_db); inoisy=awgn(optsig,snr_db(rr),'measured'); inoisy1=inoisy((1+floor(l/2)):(floor(l/2)+length(ofdm_sym1))); inoisy22=reshape(inoisy1,l_ofdm_sym,nofdm); fft_in=inoisy22(l_cp+1:n+l_cp,:); fft_out=fft(fft_in,n); if n==32; fft_out2=fft_out(2:15,:); ps=fft_out(16,:); hprim=ps/ps; elseif n==64; f1=fft_out(2:15,:); f2=fft_out(18:31,:); fft_out2=[f1;f2]; ps1=fft_out(16,:)/ps(1);ps2=fft_out(32,:)/ps(2); hprim=[ps1;ps2]; elseif n==128; f1=fft_out(2:15,:); f2=fft_out(18:31,:); f3=fft_out(34:47,:); f4=fft_out(50:63,:); fft_out2=[f1;f2;f3;f4]; ps1=fft_out(16,:)/ps(1);ps2=fft_out(32,:)/ps(2);ps3=fft_out(48,:)/ps(3);ps4=fft_out(64,:)/ps(4); hprim=[ps1;ps2;ps3;ps4]; end; fft_out3=2.*imag(fft_out2); fft_out4=reshape(fft_out3,n_data_carrier*0.5*nofdm,1); demoded_sig=step(hpam_demod,fft_out4); ber1=xor(input_b,demoded_sig); ber(1,rr)=sum(ber1)/length(ber1) end; semilogy(ebno_db,ber,'g-s','linewidth',2.5,'markersize',8);grid on;
Comments
Post a Comment