SlideShare a Scribd company logo
1 of 12
Download to read offline
%Part of Telecommunication simulations course, Spring 2006
%Harri Saarnisaari, CWC
%We simulate uncoded BER of BPSK modulated
data as a function of SNR
%-in an AWGN channel
%-in a Rayleigh fading channel
%-in an AWGN channel when direct sequence spreading
is used
%and compare results to the theoretical ones.
%We assume coherent receiver and perfect
synchronization.
-------------------------------------------------
%set used SNR values
%SNR (Eb/No) values in decibels
SNR=[0:2:14]'; %column vector
%SNR in linear scale
snr=10.^(SNR/10);
-------------------------------------------------
%we create initial zero vectors for BER
BER1=zeros(length(SNR),1);
BER2=BER1;
BER3=BER1;
-----------------------------------------------
%we need a DS-code, we create a random, complex
one, length Nc
%elements +-1 +- j*1
Nc=32;
%note that all parameters are defined as variables
%their change afterwards is easy
%(no need to change it every place, just once)
ds=(2*round(rand(Nc,1))-1)+j*(2*round(rand(Nc,1))-
1); %ds-code
%plot the ds signal
plot([real(ds) imag(ds)]),
axis([0 Nc -1.1 1.1])
title('real and imaginary parts of DS code'),
legend('real','imag'),pause
--------------------------------------------------
%we use symbol energy normalized to 1
%thus, DS energy is normalized to 1 (it is a pulse
waveform)
ds=ds/norm(ds);
%check this
ds_energy=norm(ds)^2,pause
(NOTE: normalization is a usual trick)
--------------------------------------------------
%Monte Carlo loop starts here
%some initial values
%totally Nmax symbols
Nmax=1000; %maximum number of iterations
Nerr=100; %minimum number of errors
for k=1:length(SNR), %we do MC trials for each SNR
for l=1:Nmax, %MC loop
-------------------------------------------------
%DATA
%we create data as vectors of length Ns symbols
%and thus use MATLAB's vector processing
capabilities
%in addition to for loops (since too long vectors
are problems
%to some versions of MATLAB)
Ns=100;
data=2*round(rand(Ns,1))-1;
%data is random and generated again and again for
each MC trial
--------------------------------------------------
%totally Ns * Nmax symbols, if 100*1000 = 100 000
%results rather reliable down to 1e-4
-------------------------------------------------
%plot data
if l==1 & k==1, %we plot/see things only once, at
the first round
plot(data),title('data'),axis([0 Ns -1.1
1.1]),pause,
end
-------------------------------------------------
%MODULATION
%BPSK signal
bpsk=data;
%DS spread signal
DS=kron(data,ds); %length Ns*Nc
( kron: Kronecker product, element matrices of
kron(A,B) are A(i,j)B )
----------------------------------------------
%plot first 2 symbols of ds-modulated signal
if l==1 & k==1
plot([real(DS) imag(DS)]),title('2 symbols of DS
modulated signal'),
axis([0 2*Nc -1/sqrt(Nc) 1/sqrt(Nc)]),pause,
end
-------------------------------------------------
%CHANNELS
%This is the place to set SNR.
%Since symbol energy is 1 and noise variance is 1,
%SNR of symbol/noise sample is 0 dB.
%Thus, we have to multiply symbol or divide noise
to obtain desired SNR.
%Since snr is power variable we have to
multiply/divide by
%sqrt(snr) to have amplitude coefficient.
------------------------------------------------
%noise gereration
%for BPSK
n=1/sqrt(2)*(randn(Ns,1)+j*randn(Ns,1));
%Since complex noise is generated by two real noise
sequences the
%total variance is 2 x variance of one sequence
(now 1). If we multiply
%by 1/sqrt(2) the total variance of noise becomes
1.
%This is two sided noise spectral density No in BER
equations.
%we check this
if l==1 & k==1,
var_n=norm(n)^2, pause
end
%This should be Ns since we sum Ns variables.
%Since n is a realization of a random process,
%the result is not exact.
%Average of repeated trials gives more exact
result.
---------------------------------------------------
%noise for DS-BPSK
%Since signal is longer (by factor Nc) we need
different noise.
n2=1/sqrt(2)*(randn(Ns*Nc,1)+j*randn(Ns*Nc,1));
%noise is random and we generate it again and again
for each MC trial
---------------------------------------------------
%AWGN BPSK
Bpsk=sqrt(snr(k))*data+n; %snr is Eb/N0 in BER
equations
if l==1 & k==1,
plot([real(Bpsk) data])
legend('real part of signal','data'),
title('BPSK signal in noise'),pause
end
--------------------------------------------
%AWGN DS-BPSK
Ds=sqrt(snr(k))*DS+n2;
(this works since DS energy is normalized to 1)
---------------------------------------------
%Rayleigh fading BPSK signal
%first we create taps for each symbol
taps=1/sqrt(2)*(randn(Ns,1)+j*randn(Ns,1));
%these are zero mean unit variance complex Gaussian
variables
Bpsk_r=sqrt(snr(k))*abs(taps).*data+n; %SIGNAL
%notice usage of elementwise vector or matrix
product .*
if l==1 & k==1,
plot([real(Bpsk_r) data])
legend('real part of signal','data'),
title('BPSK signal in noise & fading
channel'),pause
end
-------------------------------------------------
%difference between AWGN and Rayleigh channel
if l==1 & k==1,
plot(abs([Bpsk Bpsk_r]))
legend('AWGN','RAYLEIGH'),
title('BPSK in AWGN & Rayleigh fading
channel'),pause
end
%variations on envelope are larger in fading
channels
%deeper nulls and also higher peaks
---------------------------------------------------
%DEMODULATION
%you have to know how these signals are demodulated
%coherent + synchronized reception
---------------------------------------------------
%BPSK
r1=real(Bpsk); %demodulated signal, soft decision
%because phase is 0, if phase is h
%r1=real(Bpsk*exp(-j*2*pi*h)); i.e., phase is
cancelled
--------------------------------------------------
%BPSK in fading channel
r2=real(Bpsk_r);
------------------------------------------------
%DS-BPSK
%here we need MF to the DS code before taking the
real part
%different ways to do it
%we select correlation approach where each code
length block is
%multiplied by complex conjugate of the code
for v=1:Ns, %we have Ns blocks
r3(v)=real(ds'*Ds((v-1)*Nc+1:v*Nc));
end
r3=r3(:);
---------------------------------------------------
%demodulated symbols are actually MF output peaks
%separated by Nc samples
if l==1 & k==1,
plot(real(filter(conj(ds(Nc:-1:1)),1,DS)))
legend('without noise')
title('DS-BPSK signal after MF over 6 symbols'),
axis([0 6*Nc -3 3]),pause
end
-------------------------------------------------
%different demodulated symbols
if l==1 & k==1,
plot([r1 r2 r3])
legend('AWGN','Rayleigh','DS'),
title('demodulated symbols'),pause
end
%BPSK and DS are close (as they should be)
%we can run this at high SNR to see it closely
---------------------------------------------
%hard decisions, converts soft demodulated symbols
to sequence of +-1
%AWGN
d1=find(r1>=0);d2=find(r1<0);
r1(d1)=1;r1(d2)=-1;
%Rayl
d1=find(r2>=0);d2=find(r2<0);
r2(d1)=1;r2(d2)=-1;
%DS
d1=find(r3>=0);d2=find(r3<0);
r3(d1)=1;r3(d2)=-1;
%plot example
if l==1 & k==1,
plot([r1 r2 r3])
legend('AWGN','Rayleigh','DS'),
axis([0 Ns -1.1 1.1]),
title('demodulated symbols after hard decisions')
pause
end
--------------------------------------------------
%BER analysis
%errors in the current MC run
Ber1=length(find((data-r1)~=0)); %number of errors
in AWGN
Ber2=length(find((data-r2)~=0)); %number of errors
in Rayleigh
Ber3=length(find((data-r3)~=0)); %number of errors
in DS-BPSK
if k==1 & l==1,
errors=[Ber1 Ber2 Ber3],pause
end
---------------------------------------------------
%we add errors to previous error counts, initially
zero
%index k is for SNRs
BER1(k)=BER1(k)+Ber1; %AWGN
BER2(k)=BER2(k)+Ber2; %Rayleigh
BER3(k)=BER3(k)+Ber3; %DS-BPSK
-------------------------------------------------
%we stop MC trials if minimum number of errors is
%obtained in all systems
if BER1(k)>Nerr & BER2(k)>Nerr & BER3(k)>Nerr,
break %terminates the innermost loop
end
end %end MC
------------------------------------------------
%we calculate BER by dividing number of successful
trials
%by their total number
BER1(k)=BER1(k)/Ns/l;
BER2(k)=BER2(k)/Ns/l;
BER3(k)=BER3(k)/Ns/l;
end %ends SNR loop
--------------------------------------------------
%all simulated BERs and corresponding SNR in a
matrix
BER=[SNR BER1 BER2 BER3]
------------------------------------------------
%finally we compute theoretical values and compare
them to simulation results
%AWGN BER is function of sqrt(2*SNR)
The_awgn=.5*erfc(sqrt(2*snr)/sqrt(2));
%Rayleigh BER is different function of SNR
The_rayl=.5*(1-sqrt(snr./(1+snr)));
%note elementwise division ./
-------------------------------------------------
%logarithmic plot (y-axis)
semilogy(SNR,[The_awgn The_rayl BER1 BER2 BER3])
xlabel('SNR [dB]')
ylabel('BER')
axis([0 SNR(length(SNR)) 1e-6 .5])
grid on
legend('Theor AWGN','Theor
Rayl.','AWGN','Rayl.','DS-BPSK')
%simulated and theoretical results are close,
especially if total number of
%symbols is large enough
%BPSK and DS-BPSK perform similarly (as they should
now)
%Rayleigh fading channel is much more difficult
environment than AWGN
%over 10 dB extra power is needed in transmission
to have equal results (BER)
%10 dB more = 10 times higher power, e.g., from 1 W
to 10 W

More Related Content

What's hot

A MODIFIED DIRECTIONAL WEIGHTED CASCADED-MASK MEDIAN FILTER FOR REMOVAL OF RA...
A MODIFIED DIRECTIONAL WEIGHTED CASCADED-MASK MEDIAN FILTER FOR REMOVAL OF RA...A MODIFIED DIRECTIONAL WEIGHTED CASCADED-MASK MEDIAN FILTER FOR REMOVAL OF RA...
A MODIFIED DIRECTIONAL WEIGHTED CASCADED-MASK MEDIAN FILTER FOR REMOVAL OF RA...cscpconf
 
Stability and pole location
Stability and pole locationStability and pole location
Stability and pole locationssuser5d64bb
 
Image enhancement and interpretation
Image enhancement and interpretationImage enhancement and interpretation
Image enhancement and interpretationDocumentStory
 
Circuit Network Analysis - [Chapter4] Laplace Transform
Circuit Network Analysis - [Chapter4] Laplace TransformCircuit Network Analysis - [Chapter4] Laplace Transform
Circuit Network Analysis - [Chapter4] Laplace TransformSimen Li
 
Suspension system modeling buss
Suspension system modeling bussSuspension system modeling buss
Suspension system modeling bussMinhhau Tran
 
電路學 - [第八章] 磁耦合電路
電路學 - [第八章] 磁耦合電路電路學 - [第八章] 磁耦合電路
電路學 - [第八章] 磁耦合電路Simen Li
 
Computer architecture, a quantitative approach (solution for 5th edition)
Computer architecture, a quantitative approach (solution for 5th edition)Computer architecture, a quantitative approach (solution for 5th edition)
Computer architecture, a quantitative approach (solution for 5th edition)Zohaib Ali
 

What's hot (9)

A MODIFIED DIRECTIONAL WEIGHTED CASCADED-MASK MEDIAN FILTER FOR REMOVAL OF RA...
A MODIFIED DIRECTIONAL WEIGHTED CASCADED-MASK MEDIAN FILTER FOR REMOVAL OF RA...A MODIFIED DIRECTIONAL WEIGHTED CASCADED-MASK MEDIAN FILTER FOR REMOVAL OF RA...
A MODIFIED DIRECTIONAL WEIGHTED CASCADED-MASK MEDIAN FILTER FOR REMOVAL OF RA...
 
Chapter 7 1
Chapter 7 1Chapter 7 1
Chapter 7 1
 
Stability and pole location
Stability and pole locationStability and pole location
Stability and pole location
 
Image enhancement and interpretation
Image enhancement and interpretationImage enhancement and interpretation
Image enhancement and interpretation
 
Circuit Network Analysis - [Chapter4] Laplace Transform
Circuit Network Analysis - [Chapter4] Laplace TransformCircuit Network Analysis - [Chapter4] Laplace Transform
Circuit Network Analysis - [Chapter4] Laplace Transform
 
Suspension system modeling buss
Suspension system modeling bussSuspension system modeling buss
Suspension system modeling buss
 
APSA LEC 9
APSA LEC 9APSA LEC 9
APSA LEC 9
 
電路學 - [第八章] 磁耦合電路
電路學 - [第八章] 磁耦合電路電路學 - [第八章] 磁耦合電路
電路學 - [第八章] 磁耦合電路
 
Computer architecture, a quantitative approach (solution for 5th edition)
Computer architecture, a quantitative approach (solution for 5th edition)Computer architecture, a quantitative approach (solution for 5th edition)
Computer architecture, a quantitative approach (solution for 5th edition)
 

Viewers also liked

Viewers also liked (7)

Matlab based project topics
Matlab based project topicsMatlab based project topics
Matlab based project topics
 
Voltage unbalance and harmonics compensation for islanded microgrid inverters
Voltage unbalance and harmonics compensation for islanded microgrid invertersVoltage unbalance and harmonics compensation for islanded microgrid inverters
Voltage unbalance and harmonics compensation for islanded microgrid inverters
 
Mini Project- Communications Link Simulation
Mini Project- Communications Link SimulationMini Project- Communications Link Simulation
Mini Project- Communications Link Simulation
 
LTE Uplink Power Control
LTE Uplink Power ControlLTE Uplink Power Control
LTE Uplink Power Control
 
Signal Detection Theory
Signal Detection TheorySignal Detection Theory
Signal Detection Theory
 
Introduction to Pharmacovigilance Signal Detection
Introduction to Pharmacovigilance Signal DetectionIntroduction to Pharmacovigilance Signal Detection
Introduction to Pharmacovigilance Signal Detection
 
Projects list for ece & eee
Projects list for ece & eeeProjects list for ece & eee
Projects list for ece & eee
 

Similar to Simulation example with matlab

Matlab kod taslağı
Matlab kod taslağıMatlab kod taslağı
Matlab kod taslağıMerve Cvdr
 
107069260 trabajo-final-de-estructuras-ii
107069260 trabajo-final-de-estructuras-ii107069260 trabajo-final-de-estructuras-ii
107069260 trabajo-final-de-estructuras-iiEdwin Torres C
 
6 radar range-doppler-angular loops
6 radar range-doppler-angular loops6 radar range-doppler-angular loops
6 radar range-doppler-angular loopsSolo Hermelin
 
171220027 Kaushal Verma.pdf
171220027 Kaushal Verma.pdf171220027 Kaushal Verma.pdf
171220027 Kaushal Verma.pdfsaiusa5444
 
OPTIMIZED RATE ALLOCATION OF HYPERSPECTRAL IMAGES IN COMPRESSED DOMAIN USING ...
OPTIMIZED RATE ALLOCATION OF HYPERSPECTRAL IMAGES IN COMPRESSED DOMAIN USING ...OPTIMIZED RATE ALLOCATION OF HYPERSPECTRAL IMAGES IN COMPRESSED DOMAIN USING ...
OPTIMIZED RATE ALLOCATION OF HYPERSPECTRAL IMAGES IN COMPRESSED DOMAIN USING ...Pioneer Natural Resources
 
射頻電子 - [第一章] 知識回顧與通訊系統簡介
射頻電子 - [第一章] 知識回顧與通訊系統簡介射頻電子 - [第一章] 知識回顧與通訊系統簡介
射頻電子 - [第一章] 知識回顧與通訊系統簡介Simen Li
 
Help with root locus homework1
Help with root locus homework1Help with root locus homework1
Help with root locus homework1Assignmentpedia
 
Experiment3_DCS-21BEC0384Adityabonnerjee
Experiment3_DCS-21BEC0384AdityabonnerjeeExperiment3_DCS-21BEC0384Adityabonnerjee
Experiment3_DCS-21BEC0384AdityabonnerjeeAdityaBonnerjee21BEC
 
Measures of dispersion - united world school of business
Measures of dispersion -  united world school of businessMeasures of dispersion -  united world school of business
Measures of dispersion - united world school of businessUnitedworld School Of Business
 
"optrees" package in R and examples.(optrees:finds optimal trees in weighted ...
"optrees" package in R and examples.(optrees:finds optimal trees in weighted ..."optrees" package in R and examples.(optrees:finds optimal trees in weighted ...
"optrees" package in R and examples.(optrees:finds optimal trees in weighted ...Dr. Volkan OBAN
 
Homework 1 of Optical Semiconductor
Homework 1 of Optical SemiconductorHomework 1 of Optical Semiconductor
Homework 1 of Optical SemiconductorLê Đại-Nam
 
Digital Communication
Digital CommunicationDigital Communication
Digital CommunicationPartha_bappa
 
射頻電子 - [第三章] 史密斯圖與阻抗匹配
射頻電子 - [第三章] 史密斯圖與阻抗匹配射頻電子 - [第三章] 史密斯圖與阻抗匹配
射頻電子 - [第三章] 史密斯圖與阻抗匹配Simen Li
 
Econometric Analysis 8th Edition Greene Solutions Manual
Econometric Analysis 8th Edition Greene Solutions ManualEconometric Analysis 8th Edition Greene Solutions Manual
Econometric Analysis 8th Edition Greene Solutions ManualLewisSimmonss
 

Similar to Simulation example with matlab (20)

Matlab kod taslağı
Matlab kod taslağıMatlab kod taslağı
Matlab kod taslağı
 
107069260 trabajo-final-de-estructuras-ii
107069260 trabajo-final-de-estructuras-ii107069260 trabajo-final-de-estructuras-ii
107069260 trabajo-final-de-estructuras-ii
 
6 radar range-doppler-angular loops
6 radar range-doppler-angular loops6 radar range-doppler-angular loops
6 radar range-doppler-angular loops
 
171220027 Kaushal Verma.pdf
171220027 Kaushal Verma.pdf171220027 Kaushal Verma.pdf
171220027 Kaushal Verma.pdf
 
48
4848
48
 
OPTIMIZED RATE ALLOCATION OF HYPERSPECTRAL IMAGES IN COMPRESSED DOMAIN USING ...
OPTIMIZED RATE ALLOCATION OF HYPERSPECTRAL IMAGES IN COMPRESSED DOMAIN USING ...OPTIMIZED RATE ALLOCATION OF HYPERSPECTRAL IMAGES IN COMPRESSED DOMAIN USING ...
OPTIMIZED RATE ALLOCATION OF HYPERSPECTRAL IMAGES IN COMPRESSED DOMAIN USING ...
 
射頻電子 - [第一章] 知識回顧與通訊系統簡介
射頻電子 - [第一章] 知識回顧與通訊系統簡介射頻電子 - [第一章] 知識回顧與通訊系統簡介
射頻電子 - [第一章] 知識回顧與通訊系統簡介
 
Help with root locus homework1
Help with root locus homework1Help with root locus homework1
Help with root locus homework1
 
redes neuronais
redes neuronaisredes neuronais
redes neuronais
 
S_parameters.pdf
S_parameters.pdfS_parameters.pdf
S_parameters.pdf
 
Experiment3_DCS-21BEC0384Adityabonnerjee
Experiment3_DCS-21BEC0384AdityabonnerjeeExperiment3_DCS-21BEC0384Adityabonnerjee
Experiment3_DCS-21BEC0384Adityabonnerjee
 
Measures of dispersion - united world school of business
Measures of dispersion -  united world school of businessMeasures of dispersion -  united world school of business
Measures of dispersion - united world school of business
 
Dispersion
DispersionDispersion
Dispersion
 
EEL316: ASK
EEL316: ASKEEL316: ASK
EEL316: ASK
 
"optrees" package in R and examples.(optrees:finds optimal trees in weighted ...
"optrees" package in R and examples.(optrees:finds optimal trees in weighted ..."optrees" package in R and examples.(optrees:finds optimal trees in weighted ...
"optrees" package in R and examples.(optrees:finds optimal trees in weighted ...
 
Homework 1 of Optical Semiconductor
Homework 1 of Optical SemiconductorHomework 1 of Optical Semiconductor
Homework 1 of Optical Semiconductor
 
Digital Communication
Digital CommunicationDigital Communication
Digital Communication
 
射頻電子 - [第三章] 史密斯圖與阻抗匹配
射頻電子 - [第三章] 史密斯圖與阻抗匹配射頻電子 - [第三章] 史密斯圖與阻抗匹配
射頻電子 - [第三章] 史密斯圖與阻抗匹配
 
Rtutorial
RtutorialRtutorial
Rtutorial
 
Econometric Analysis 8th Edition Greene Solutions Manual
Econometric Analysis 8th Edition Greene Solutions ManualEconometric Analysis 8th Edition Greene Solutions Manual
Econometric Analysis 8th Edition Greene Solutions Manual
 

Recently uploaded

Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jisc
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxPooja Bhuva
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxEsquimalt MFRC
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17Celine George
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...Amil baba
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxannathomasp01
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...Nguyen Thanh Tu Collection
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxUmeshTimilsina1
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxJisc
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Jisc
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsKarakKing
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentationcamerronhm
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptxMaritesTamaniVerdade
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 

Recently uploaded (20)

Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptx
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 

Simulation example with matlab

  • 1. %Part of Telecommunication simulations course, Spring 2006 %Harri Saarnisaari, CWC %We simulate uncoded BER of BPSK modulated data as a function of SNR %-in an AWGN channel %-in a Rayleigh fading channel %-in an AWGN channel when direct sequence spreading is used %and compare results to the theoretical ones. %We assume coherent receiver and perfect synchronization. ------------------------------------------------- %set used SNR values %SNR (Eb/No) values in decibels SNR=[0:2:14]'; %column vector %SNR in linear scale snr=10.^(SNR/10); ------------------------------------------------- %we create initial zero vectors for BER BER1=zeros(length(SNR),1); BER2=BER1; BER3=BER1; -----------------------------------------------
  • 2. %we need a DS-code, we create a random, complex one, length Nc %elements +-1 +- j*1 Nc=32; %note that all parameters are defined as variables %their change afterwards is easy %(no need to change it every place, just once) ds=(2*round(rand(Nc,1))-1)+j*(2*round(rand(Nc,1))- 1); %ds-code %plot the ds signal plot([real(ds) imag(ds)]), axis([0 Nc -1.1 1.1]) title('real and imaginary parts of DS code'), legend('real','imag'),pause -------------------------------------------------- %we use symbol energy normalized to 1 %thus, DS energy is normalized to 1 (it is a pulse waveform) ds=ds/norm(ds); %check this ds_energy=norm(ds)^2,pause (NOTE: normalization is a usual trick) -------------------------------------------------- %Monte Carlo loop starts here %some initial values %totally Nmax symbols Nmax=1000; %maximum number of iterations Nerr=100; %minimum number of errors for k=1:length(SNR), %we do MC trials for each SNR for l=1:Nmax, %MC loop
  • 3. ------------------------------------------------- %DATA %we create data as vectors of length Ns symbols %and thus use MATLAB's vector processing capabilities %in addition to for loops (since too long vectors are problems %to some versions of MATLAB) Ns=100; data=2*round(rand(Ns,1))-1; %data is random and generated again and again for each MC trial -------------------------------------------------- %totally Ns * Nmax symbols, if 100*1000 = 100 000 %results rather reliable down to 1e-4 ------------------------------------------------- %plot data if l==1 & k==1, %we plot/see things only once, at the first round plot(data),title('data'),axis([0 Ns -1.1 1.1]),pause, end -------------------------------------------------
  • 4. %MODULATION %BPSK signal bpsk=data; %DS spread signal DS=kron(data,ds); %length Ns*Nc ( kron: Kronecker product, element matrices of kron(A,B) are A(i,j)B ) ---------------------------------------------- %plot first 2 symbols of ds-modulated signal if l==1 & k==1 plot([real(DS) imag(DS)]),title('2 symbols of DS modulated signal'), axis([0 2*Nc -1/sqrt(Nc) 1/sqrt(Nc)]),pause, end ------------------------------------------------- %CHANNELS %This is the place to set SNR. %Since symbol energy is 1 and noise variance is 1, %SNR of symbol/noise sample is 0 dB. %Thus, we have to multiply symbol or divide noise to obtain desired SNR. %Since snr is power variable we have to multiply/divide by %sqrt(snr) to have amplitude coefficient. ------------------------------------------------
  • 5. %noise gereration %for BPSK n=1/sqrt(2)*(randn(Ns,1)+j*randn(Ns,1)); %Since complex noise is generated by two real noise sequences the %total variance is 2 x variance of one sequence (now 1). If we multiply %by 1/sqrt(2) the total variance of noise becomes 1. %This is two sided noise spectral density No in BER equations. %we check this if l==1 & k==1, var_n=norm(n)^2, pause end %This should be Ns since we sum Ns variables. %Since n is a realization of a random process, %the result is not exact. %Average of repeated trials gives more exact result. --------------------------------------------------- %noise for DS-BPSK %Since signal is longer (by factor Nc) we need different noise. n2=1/sqrt(2)*(randn(Ns*Nc,1)+j*randn(Ns*Nc,1)); %noise is random and we generate it again and again for each MC trial ---------------------------------------------------
  • 6. %AWGN BPSK Bpsk=sqrt(snr(k))*data+n; %snr is Eb/N0 in BER equations if l==1 & k==1, plot([real(Bpsk) data]) legend('real part of signal','data'), title('BPSK signal in noise'),pause end -------------------------------------------- %AWGN DS-BPSK Ds=sqrt(snr(k))*DS+n2; (this works since DS energy is normalized to 1) --------------------------------------------- %Rayleigh fading BPSK signal %first we create taps for each symbol taps=1/sqrt(2)*(randn(Ns,1)+j*randn(Ns,1)); %these are zero mean unit variance complex Gaussian variables Bpsk_r=sqrt(snr(k))*abs(taps).*data+n; %SIGNAL %notice usage of elementwise vector or matrix product .* if l==1 & k==1, plot([real(Bpsk_r) data]) legend('real part of signal','data'), title('BPSK signal in noise & fading channel'),pause end -------------------------------------------------
  • 7. %difference between AWGN and Rayleigh channel if l==1 & k==1, plot(abs([Bpsk Bpsk_r])) legend('AWGN','RAYLEIGH'), title('BPSK in AWGN & Rayleigh fading channel'),pause end %variations on envelope are larger in fading channels %deeper nulls and also higher peaks --------------------------------------------------- %DEMODULATION %you have to know how these signals are demodulated %coherent + synchronized reception --------------------------------------------------- %BPSK r1=real(Bpsk); %demodulated signal, soft decision %because phase is 0, if phase is h %r1=real(Bpsk*exp(-j*2*pi*h)); i.e., phase is cancelled -------------------------------------------------- %BPSK in fading channel r2=real(Bpsk_r); ------------------------------------------------
  • 8. %DS-BPSK %here we need MF to the DS code before taking the real part %different ways to do it %we select correlation approach where each code length block is %multiplied by complex conjugate of the code for v=1:Ns, %we have Ns blocks r3(v)=real(ds'*Ds((v-1)*Nc+1:v*Nc)); end r3=r3(:); --------------------------------------------------- %demodulated symbols are actually MF output peaks %separated by Nc samples if l==1 & k==1, plot(real(filter(conj(ds(Nc:-1:1)),1,DS))) legend('without noise') title('DS-BPSK signal after MF over 6 symbols'), axis([0 6*Nc -3 3]),pause end -------------------------------------------------
  • 9. %different demodulated symbols if l==1 & k==1, plot([r1 r2 r3]) legend('AWGN','Rayleigh','DS'), title('demodulated symbols'),pause end %BPSK and DS are close (as they should be) %we can run this at high SNR to see it closely --------------------------------------------- %hard decisions, converts soft demodulated symbols to sequence of +-1 %AWGN d1=find(r1>=0);d2=find(r1<0); r1(d1)=1;r1(d2)=-1; %Rayl d1=find(r2>=0);d2=find(r2<0); r2(d1)=1;r2(d2)=-1; %DS d1=find(r3>=0);d2=find(r3<0); r3(d1)=1;r3(d2)=-1; %plot example if l==1 & k==1, plot([r1 r2 r3]) legend('AWGN','Rayleigh','DS'), axis([0 Ns -1.1 1.1]), title('demodulated symbols after hard decisions') pause end --------------------------------------------------
  • 10. %BER analysis %errors in the current MC run Ber1=length(find((data-r1)~=0)); %number of errors in AWGN Ber2=length(find((data-r2)~=0)); %number of errors in Rayleigh Ber3=length(find((data-r3)~=0)); %number of errors in DS-BPSK if k==1 & l==1, errors=[Ber1 Ber2 Ber3],pause end --------------------------------------------------- %we add errors to previous error counts, initially zero %index k is for SNRs BER1(k)=BER1(k)+Ber1; %AWGN BER2(k)=BER2(k)+Ber2; %Rayleigh BER3(k)=BER3(k)+Ber3; %DS-BPSK ------------------------------------------------- %we stop MC trials if minimum number of errors is %obtained in all systems if BER1(k)>Nerr & BER2(k)>Nerr & BER3(k)>Nerr, break %terminates the innermost loop end end %end MC ------------------------------------------------
  • 11. %we calculate BER by dividing number of successful trials %by their total number BER1(k)=BER1(k)/Ns/l; BER2(k)=BER2(k)/Ns/l; BER3(k)=BER3(k)/Ns/l; end %ends SNR loop -------------------------------------------------- %all simulated BERs and corresponding SNR in a matrix BER=[SNR BER1 BER2 BER3] ------------------------------------------------ %finally we compute theoretical values and compare them to simulation results %AWGN BER is function of sqrt(2*SNR) The_awgn=.5*erfc(sqrt(2*snr)/sqrt(2)); %Rayleigh BER is different function of SNR The_rayl=.5*(1-sqrt(snr./(1+snr))); %note elementwise division ./ -------------------------------------------------
  • 12. %logarithmic plot (y-axis) semilogy(SNR,[The_awgn The_rayl BER1 BER2 BER3]) xlabel('SNR [dB]') ylabel('BER') axis([0 SNR(length(SNR)) 1e-6 .5]) grid on legend('Theor AWGN','Theor Rayl.','AWGN','Rayl.','DS-BPSK') %simulated and theoretical results are close, especially if total number of %symbols is large enough %BPSK and DS-BPSK perform similarly (as they should now) %Rayleigh fading channel is much more difficult environment than AWGN %over 10 dB extra power is needed in transmission to have equal results (BER) %10 dB more = 10 times higher power, e.g., from 1 W to 10 W