TIES328 Matlab Exercise 1: Zhdizhan@student - Jyu.fi
TIES328 Matlab Exercise 1: Zhdizhan@student - Jyu.fi
TIES328:Matlab exercise 1
By Di Zhang
[email protected]
Matlab exercise
• Introduction
rand: abs:
randn: real: for
round: find:
sqrt: length: if
norm: erfc:
Check the Matlab documentation for explanation.
e.g. https://se.mathworks.com/help/search.html?submitsearch=&qdoc=real
Link Level Simulation
(BPSK case)
• We simulate uncoded BER of BPSK modulate
data as a function of SNR
– in an AWGN channel
– in a Rayleigh fading channel
– Plot and see the signals from Tx, passing through
different channels, and BER at Rx.
Introduction -- Link
Introduction -- Data
Introduction -- Data
data=2*round(rand(Ns,1))-1
Introduction -- Data
Introduction -- Data
Introduction -- Modulation
Bpsk=sqrt(snr(k))*data
Introduction -- Noise
Introduction – Channel
AGWN
Additive white Gaussian noise (AWGN) is a basic noise model used in Information theory to
mimic the effect of many random processes that occur in nature. The modifiers denote specific
characteristics:
Additive because it is added to any noise that might be intrinsic to the information system.
White refers to the idea that it has uniform power across the frequency band for the information
system. It is an analogy to the color white which has uniform emissions at all frequencies in
the visible spectrum.
Gaussian because it has a normal distribution in the time domain with an average time domain
value of zero.
n=1/sqrt(2)*(randn(Ns,1)+j*randn(Ns,1));
Bpsk=sqrt(snr(k))*data+n
Introduction – Channel
AGWN
Introduction – Channel
Rayleigh
Introduction – Channel taps=1/sqrt(2)*(randn(Ns,
%these are zero mean unit
Gaussian variables
Bpsk_r=sqrt(snr(k))*abs(ta
Rayleigh %SIGNAL
Rayleigh fading models assume that the magnitude of a signal that has passed
through such a transmission medium (also called acommunications channel) will
vary randomly, or fade, according to a Rayleigh distribution — the radial component
of the sum of two uncorrelatedGaussian random variables.
taps=1/sqrt(2)*(randn(Ns,1)+j*randn(Ns,1));
Bpsk_r=sqrt(snr(k))*abs(taps).*data + n
Introduction – Channel
Rayleigh
Introduction – Demodulation
Bpsk=sqrt(snr(k))*data+n
Bpsk_r=sqrt(snr(k))*abs(taps).*data+n
Introduction – Rx
Rayleigh
Introduction – Demodulation
d1=find(r1>=0); d1=find(r2>=0);
d2=find(r1<0); d2=find(r2<0);
r1(d1)=1;r1(d2)=-1; r2(d1)=1;r2(d2)=-1;
ADWG Rayleigh
Introduction – Demodulation
Introduction – BER
Ber1=length(find((data-r1)~=0));
%number of errors in AWGN
Ber2=length(find((data-r2)~=0));
%number of errors in Rayleigh
BER1(k)=BER1(k)+Ber1; %AWGN
BER2(k)=BER2(k)+Ber2; %Rayleigh
BER1(k)=BER1(k)/Ns/l;
BER2(k)=BER2(k)/Ns/l;
Introduction – received BER
Introduction – theoritical BER
%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
Link Level Simulation (BPSK case)
%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
Link Level Simulation (BPSK case)
%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
Link Level Simulation (BPSK case)
%---------------------------------------------------
%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
• end % end of MC
Link Level Simulation (BPSK case)
%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;
• end % end SNR loop
%all simulated BERs and corresponding SNR in a matrix
• BER=[SNR BER1 BER2];
%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)));
%logarithmic plot (y-axis)
• semilogy(SNR,[The_awgn The_rayl BER1 BER2])
• xlabel('SNR [dB]')
• ylabel('BER')
• axis([0 SNR(length(SNR)) 1e-4 .5])
• grid on
• legend('Theor AWGN','Theor Rayl.','AWGN','Rayl.')