Matlab Code For Mtech
Matlab Code For Mtech
Matlab Code For Mtech
AIM
THEORY
b)BPSK demodulation
The incoming modulated BPSK signal is multiplied with carrier signal generated from
the carrier generator. The output of the multiplier contents high frequency and low
frequency components. The integrator blocks integrate multiplier output. With help of
comparator by comparing threshold values input data is received.
In QPSK, the data bits to be modulated are grouped into symbols, each containing two bits, and
each symbol can take on one of four possible values: 00, 01, 10, or 11. During each symbol
interval, the modulator shifts the carrier to one of four possible phases corresponding to the four
possible values of the input symbol. In the ideal case, the phases are each 90 degrees apart, and
these phases are usually selected such that the signal constellation matches the configuration
shown in Figure 9.1. Practical QPSK modulators are often implemented using structures similar
to the one shown in Figure 9.2. This structure uses the trigonometric identity
where
R = sqrtroot( I 2 + Q2)
= tan1( Q/ I)
a) QPSK modulation
The binary bit stream or massage signal is pass through line coding like bipolar NRZ signal
represent at binary values 0 and 1 respectively then multiplied with two term real and
imaginary carrier signal carry the information bit stream. Phase can be changes accordance
with binary bit 1 and 0 respectively such way modulation signal is phase changes
b) QPSK demodulation
We want get our original bit stream thatsModulated signal multiplier with high frequency
and low frequencies component and passing through the integrator carrier signal and
Integrate signal to desired which in form of original information content signal then pass
through comparator with upper limit set at 1 and lower limit set to 0. It compare with output
of integrator blocks. And get original information
Differential phase shift keying (DPSK) is a common form of phase modulation that conveys data
by changing the phase of the carrier wave. As mentioned for BPSK and QPSK there is an
ambiguity of phase if the constellation is rotated by some effect in the communications
channel through which the signal passes. This problem can be overcome by using the data
to change rather than set the phase.
For example, in differentially encoded BPSK a binary '1' may be transmitted by adding 180 to
the current phase and a binary '0' by adding 0 to the current phase. Another variant of DPSK is
Symmetric Differential Phase Shift keying, SDPSK, where encoding would be +90 for a '1' and
90 for a '0'.
In differentially encoded QPSK (DQPSK), the phase-shifts are 0, 90, 180, 90 corresponding
to data '00', '01', '11', '10'. This kind of encoding may be demodulated in the same way as for
non-differential PSK but the phase ambiguities can be ignored. Thus, each received symbol is
demodulated to one of the points in the constellation and a comparator then computes the
difference in phase between this received signal and the preceding one. The difference encodes
the data as described above. Symmetric Differential Quadrature Phase Shift Keying (SDQPSK)
is like DQPSK, but encoding is symmetric, using phase shift values of 135, 45, +45 and
+135.
The modulated signal is shown below for both DBPSK and DQPSK as described above. In the
figure, it is assumed that the signal starts with zero phase, and so there is a phase shift in both
signals at .Analysis shows that differential encoding approximately doubles the error rate
compared to ordinary -PSK but this may be overcome by only a small increase in . Furthermore,
this analysis (and the graphical results below) are based on a system in which the only corruption
is additive white Gaussian noise (AWGN). However, there will also be a physical channel
between the transmitter and receiver in the communication system. This channel will, in general,
introduce an unknown phase-shift to the PSK signal; in these cases the differential schemes can
yield a better error-rate than the ordinary schemes which rely on precise phase information.
PROGRAM
clc
clear all;
N=10^6;
T=1;
os=5;
fs=5/T;
Eb_NO_dB = [0:10];
for ii=1:length(Eb_NO_dB)
ip= rand(1,N)>0.5;
s=2*ip-1;
sU=[s;zeros(os-1,length(s))];
sU=sU(:).';
sFilt=1/sqrt(os)*conv(sU,ones(1,os));
sFilt=sFilt(1:N*os);
n=1/sqrt(2)*[randn(1,N*os)+1i*randn(1,N*os)];
y=sFilt + 10^(-Eb_NO_dB(ii)/20)*n;
yFlit=conv(y,ones(1,os));
ysamp=yFlit(os:os:N*os);
ipHat=real(ysamp)>0;
nErr(ii)=size(find([ip-ipHat]),2)
end
simBer=nErr/N;
theoryBer=0.5*erfc(sqrt(10.^(Eb_NO_dB/10)));
close all
figure
semilogy(Eb_NO_dB,theoryBer,'bs-','linewidth',1);
hold on
semilogy(Eb_NO_dB,simBer,'mx-','linewidth',2);
axis([0 10 10^-5 0.5])
grid on
legend('theory','sim-(matched filter )');
xlabel('Eb/No,dB');
ylabel('bit error rate');
title('bit error probability curve for bpsk modulatio');
OBSERVATION
RESULT
Designed and implemented bpsk and obtained the bit error curve for bpsk modulation
AIM
2. To plot and compare theoretical and simulated BER v/s SNR curve for BPSK modulation.
THEORY
Rayleigh and Rician fading channels are useful models of real-world phenomena in
wireless communications. These phenomena include multipath scattering effects, time
dispersion, and Doppler shifts that arise from relative motion between the transmitter and
receiver.
The figure below depicts direct and major reflected paths between a stationary radio
transmitter and a moving receiver. The shaded shapes represent reflectors such as buildings.
The major paths result in the arrival of delayed versions of the signal at the receiver. In
addition, the radio signal undergoes scattering on a local scale for each major path. Such local
scattering is typically characterized by a large number of reflections by objects near the mobile.
These irresolvable components combine at the receiver and give rise to the phenomenon known
as multipath fading. Due to this phenomenon, each major path behaves as a discrete fading path.
Typically, the fading process is characterized by a Rayleigh distribution for a nonline-of-sight
path and a Rician distribution for a line-of-sight path.
The relative motion between the transmitter and receiver causes Doppler shifts. Local
scattering typically comes from many angles around the mobile. This scenario causes a range of
Doppler shifts, known as the Doppler spectrum. The maximum Doppler shift corresponds to the
local scattering components whose direction exactly opposes the mobile's trajectory.
The performance (Eb/N0 Vs BER) of BPSK modulation (with coherent detection) over
Rayleigh Fading channel and its comparison over AWGN channel is simulated here. The
received signal y can be represented as
y=hx+n
where n is the noise contributed by AWGN which is Gaussian distributed with zero mean
and unit variance and h is the Rayleigh Fading response with zero mean and unit variance. (For a
simple AWGN channel without Rayleigh Fading the received signal is represented as y=x+n).
y^=y/h=(hx+n)/h=x+z
here z is still an AWGN noise except for the scaling factor 1/h. Now the detection of x can be
performed in a manner similar to the detection in AWGN channels.
The input binary bits to the BPSK modulation system are detected as
r=real(y^)=real(x+z)
d^=1,if r>0
d^=0,if r<0
Theoretical BER:
The theoretical BER for BPSK modulation scheme over Rayleigh fading channel (with AWGN
noise) is given by
The theoretical BER for BPSK modulation scheme over an AWGN channel is given here for
comparison
The following model is used for the simulation of BPSK over Rayleigh Fading channel and its
comparison with AWGN channel
ALGORITHM
Step 1: Define Frame Length and range of snr over which to simulate.
Step 8: Finally plot the BER Vs. SNR(dB) Curve on logarithmic scale.
PROGRAM
clear all;
clc;
close all
% Transmitter
ip = rand(1,N)>0.5; % generating 0,1 with equal probability
s = 2*ip-1; % BPSK modulation 0 -> -1; 1 -> 0
for ii = 1:length(Eb_N0_dB)
% equalization
yHat = y./h;
end
% plot
close all
figure
semilogy(Eb_N0_dB,theoryBerAWGN,'cd-','LineWidth',2);
hold on
semilogy(Eb_N0_dB,theoryBer,'bp-','LineWidth',2);
semilogy(Eb_N0_dB,simBer,'mx-','LineWidth',2);
axis([-3 35 10^-5 0.5])
grid on
legend('AWGN-Theory','Rayleigh-Theory', 'Rayleigh-Simulation');
xlabel('Eb/No, dB');
ylabel('Bit Error Rate');
title('BER for BPSK modulation in Rayleigh channel');
OBSERVATION
RESULT
Design and plotted communication through a fading channel. Curves for theoretical and
simulated results of Rayleigh fading channel is obtained.
AIM
To design and plot spreaded data and despreaded data for three users in same communication
channel using CDMA technology.
THEORY
Direct-sequence spread spectrum for CDMA involves multiplying the data to be transmitted by a
pseudo-random sequence of -1's and 1's. This spreads the original signal into a much wider band,
hence the term spread-spectrum. The original data can be restored by the receiver using a de-
spreading technique. This involves de-spreading the received signal with the pseudo-random
sequence respective to the original signal. To do this, the transmitted and received sequences
must be synchronized.
CDMA uses orthogonal coding to allow multiple users to access a channel simultaneously. An
advantage of CDMA is that it is possible to keep increasing the number of users for a system.
The limiting factor of CDMA is the error rate, which increases with each added user. Each user
has a pseudo-random noise (PN) sequence that is orthogonal to other users' PN sequences. Their
cross-correlation is close to 0. The orthogonality of the codes ensures that each signal's
transmitter-receiver pair will only deal with its corresponding signal; in other words, the receiver
for a particular signal will see any other signal going through the channel as simply noise, and
this will eliminate multiple-access interference.
In direct sequence spread spectrum, there are two types of spreading sequences: short and long.
In short spreading sequences, the spreading sequence is periodic with a period equal to the
processing gain. As a result, the same short sequence is used to modulate each symbol which is
transmitted. Examples of short spreading sequences are Walsh Codes and Gold Codes. In long
spreading sequences, the spreading sequence is either a periodic or has a period which is much
longer than the processing gain.
ALGORITHM
The FIR filter design process via window functions can be split into several steps:
Step 1: Defining the data and the pseudo code for three different users.
Step 3: Obtain the spreaded data by XOR the data and the pseudo code.
Step 4: Plot the data, spreading sequence and spreaded data for three users.
Step 5: Obtain the despreaded data by XOR the spreaded data and the pseudo code.
PROGRAM
clc;
clear all;
close all;
spread=[];
data=[1 0 0 0;0 0 0 0;1 1 1 1];
pseudo_code=[1 0 1 0;0 1 1 1; 1 1 1 1];
k=1;
[r,c]=size(data);
[r1,c1]=size(pseudo_code);
for l=1:r
k=1;
for i=1:c
for j=1:c1
spread(l,k)=xor(data(1,i),pseudo_code(1,j))
k=k+1;
end
end
end
figure;
subplot(431)
stem(data(1,:));
title('orginal data of 1');
subplot(432)
stem(pseudo_code(1,:));
title('spreading sequence 1');
subplot(433)
stem(spread(1,:));
title('spreaded sequence 1');
subplot(434)
stem(data(2,:));
title('orginal data of 2');
subplot(435)
stem(pseudo_code(2,:));
title('spreading sequence 2');
subplot(436)
stem(spread(2,:));
title('spreaded sequence 2');
subplot(437)
stem(data(3,:));
%demodulator%
i=1;
k=1;
los=length(spread);
while k<los
s=0;
for j=1:c1
temp(1,j)=xor(spread(1,k),pseudo_code(1,j));
k=k+1;
s=s+temp(1,j);
end
if (s==0)
h2(1,i)=0;
else
h2(1,i)=1;
end
i=i+1;
end
despreaded_signal=h2;
%plotting despreaded signal%
subplot(414)
stem(despreaded_signal);
title('despreaded signal')
OBSERVATIONS
RESULT
Designed and plotted spreaded data and despreaded data for three users in same communication
channel using CDMA technology.
AIM
THEORY
With h as the impulse response and x and y input and output signals. The matched filter is
nothing else than a correlator that correlates with a given signal pattern.It has a impulse response
which is just the time reverse of the signal pattern.So by the way: If signal pattern have
measured, reverse it and set this as impulse response of a FIR filter. There is no need to do this in
the frequency domain if you have measurement in the time domain (both approaches are
equivalent but one is more error prone than the other).
y (t )= x ( t ) .h (t+ )dt
ALGORITHM
(b) Upsample by inserting zeros and the convolve with rectangular filter
(d) Convolve the received samples with matched filter, and extract output at time T
(e) Perform hard decision decoding and count the bit errors
(f) Repeat for multiple values of and plot the simulation and theoretical results.
PROGRAM
clc;
clear all;
close all;
N=10^5;
T=1;
os=5;
fs=5/T;
Eb_NO_dB=[0:10];
for i1=1:length(Eb_NO_dB)
%transmitter%
ip=rand(1,N)>0.5;
s=2*ip-1;
sU=[s;zeros(os-1,length(s))];
sU=sU(:).';
sFilt=1/sqrt(os)*conv(sU,ones(1,os));
sFilt=sFilt(1:N*os);
n=1/sqrt(2)*[randn(1,N*os)+j*randn(1,N*os)];
%noise addition
y=sFilt+10^(-Eb_NO_dB(i1)/20)*n;
%matched filter
yFilt=conv(y,ones(1,os));
ySamp=yFilt(os:os:N*os);
ipHat=real(ySamp)>0;
nErr(i1)=size(find([ip-ipHat]),2);
end
simBer=nErr/N;
theoryBer=0.5*erfc(sqrt(10.^(Eb_NO_dB/10)));
%plot
close all;
figure
semilogy(Eb_NO_dB,theoryBer,'bs-','linewidth',1);
hold on
semilogy(Eb_NO_dB,simBer,'mx-','linewidth',2);
axis([0 10 10^-5 0.5])
grid on
legend('theory','sim-(matched filter)');
xlabel('Eb/NO,dB');
ylabel('bit error rate');
title('bit error rate probability for bpsk');
OBSERVATION
RESULT
OFDM TRANSEIVER
AIM
THEORY
Ofdm modulation
In OFDM transmitter N complex-value source symbols Xk k=0,1,...N-1, which can come from
any constellation, such as QPSK or QAM, are modulated onto N orthogonal subcarriers - inverse
Fourier-Transform complex exponentials evaluated at subcarrier frequencies fk :
In a digital transmitter t=nTs where Ts is the sampling period. Subcarriers frequencies are
uniformly distributed:
N-sample long x sequence is called OFDM symbol and its duration is equal to N*Ts.
Ofdm demodulation
ADC at the receiver receives an analog signal which is a result of convolution of the transmitted
OFDM symbol x(t) with the channel impulse response plus noise:
OFDM demodulation takes a form of Fast-Fourier Transform of the sampled received signal r(t)
(after removal of Ng samples of the guard interval):
After channel estimation which yields complex-valued channel attenuation factors Hk at each
subcarriers frequency the decoded k-th transmitted data symbol can be obtained through the
following transformation:
ALGORITHM
The ofdm transeiver design process can be split into several steps:
PROGRAM
% OFDM Code
close all
clear all
clc
%%
% Generating and coding data
t_data=randint(9600,1)';
x=1;
si=1; %for BER rows
%%
for d=1:100;
data=t_data(x:x+95);
x=x+96;
k=3;
n=6;
s1=size(data,2); % Size of input matrix
j=s1/k;
%%
% Convolutionally encoding data
constlen=7;
codegen = [171 133]; % Polynomial
trellis = poly2trellis(constlen, codegen);
codedata = convenc(data, trellis);
%%
%Interleaving coded data
s2=size(codedata,2);
j=s2/4;
matrix=reshape(codedata,j,4);
%%
% Binary to decimal conversion
dec=bi2de(intlvddata','left-msb');
%%
%16-QAM Modulation
M=16;
y = qammod(dec,M);
% scatterplot(y);
%%
% Pilot insertion
lendata=length(y);
pilt=3+3j;
nofpits=4;
k=1;
for i=(1:13:52)
pilt_data1(i)=pilt;
for j=(i+1:i+12);
pilt_data1(j)=y(k);
k=k+1;
end
end
for i=1:52
pilt_data(i+6)=pilt_data1(i);
end
%%
% IFFT
ifft_sig=ifft(pilt_data',64);
%%
% Adding Cyclic Extension
cext_data=zeros(80,1);
cext_data(1:16)=ifft_sig(49:64);
for i=1:64
cext_data(i+16)=ifft_sig(i);
end
%%
% Channel
% SNR
o=1;
for snr=0:2:50
%%
% RECEIVER
%%
%Removing Cyclic Extension
for i=1:64
rxed_sig(i)=ofdm_sig(i+16);
end
%%
% FFT
ff_sig=fft(rxed_sig,64);
%%
% Pilot Synch%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for i=1:52
synched_sig1(i)=ff_sig(i+6);
end
k=1;
for i=(1:13:52)
for j=(i+1:i+12);
synched_sig(k)=synched_sig1(j);
k=k+1;
end
end
% scatterplot(synched_sig)
%%
% Demodulation
dem_data= qamdemod(synched_sig,16);
%%
% Decimal to binary conversion
bin=de2bi(dem_data','left-msb');
bin=bin';
%%
% De-Interleaving
%%
%Decoding data
n=6;
k=3;
decodedata =vitdec(deintlvddata,trellis,5,'trunc','hard'); % decoding datausing veterbi decoder
rxed_data=decodedata;
%%
% Calculating BER
rxed_data=rxed_data(:)';
errors=0;
c=xor(data,rxed_data);
errors=nnz(c);
% for i=1:length(data)
%
%
% if rxed_data(i)~=data(i);
% errors=errors+1;
%
% end
% end
BER(si,o)=errors/length(data);
o=o+1;
%%
% Time averaging for optimum results
ber(1,col)=ber(1,col)+BER(row,col);
end
end
ber=ber./100;
%%
figure
i=0:2:48;
semilogy(i,ber);
title('BER vs SNR');
ylabel('BER');
xlabel('SNR (dB)');
grid on
OBSERVATIONS
RESULT
AIM
THEORY
Diversity techniques can be used to improve system performance in fading channels. Instead of
transmitting and receiving the desired signal through one channel, L copies of the desired signal
through M different channels are received. There are several different types of diversity
techniques that are commonly used in wireless communication systems
Frequency diversity
Time diversity
Another approach to achieve diversity is to transmit the desired signal in M different time
periods, i.e., each symbol is transmitted M times, Figure 2, where s(t) is the equivalent lowpass
of the transmitted signal, and W is weighting factor. The intervals between the transmission of
the same symbol should be determined in such a way to achieve the least coherence of time
intervals (t)c so that different copies of the same symbols undergo independent fading. The
optimal combination can be obtained by the maximum ratio of combinations. We notice that
sending the same symbol M times is as applying the (M,1) repetition code. In fact, non-trivial
coding can be also used. Error control coding with interlacing can be an effective way to combat
time selective (fast) fading.
Space diversity
The third method to achieve diversity is to use M antennas to receive M copies of transferred
signal, Figure 3. The antennas should be located far enough from each other to achieve that
received copies of the signal have independent fading. Unlike frequency diversity and time
diversity, it is not necessary to have additional processing at the end of transmission. It is not
necessary to reserve additional transmission band or additional transmission time.
Diversity transmission is based on the principle of using multiple copies of the transmitted
signals that are statistically independent. The most commonly used techniques of combining
signals after application of diversity techniques are: Selection Combining, SC, (which means a
choice of branch with the best signal-to-noise ratio), Maximum Ratio Combining, MRC, (or
combining with a maximum signal-to-noise ratio), Equal Gain Combining, EGC, (combining
with the equal contribution of all branches), Switch and Stay Combining, SSC, (simple
combining by switching the signals), as well as various hybrid techniques of signal combining.
Selection Combining, SC
SC is the simplest and most commonly used method for combining signals in Diversity system,
which is based on choosing the branch with the most favourable SNR, Figure 4.
When applying EGC technique of combining signals, phase-changes of signals in all diversity
branches are compensated, and then signals are summed, Figure 5
MRC is the optimal linear technique of signal combination in the Diversity system, which
provides the best statistical results in limiting the impact of fading. The signal in each of
Diversity branches is, before summarizing, multiplied by the matching weighting factor, thus
equating phases of all signals, and the branches with more favorable SNR are taken with greater
contribution, Figure 7. This ensures that the signal with more power has greater contribution in
the received sum of signals. Therefore, it is necessary to have measurement of SNR in all
branches.
ALGORITHM
PROGRAM
%% Implementation of diversity techniques
Method1:
clc;
clear all;
close all;
N=10^4; % number of bits or symbols
%transmitter
ip=rand(1,N)>0.5; %generating 0,1 with equal probability
s=2*ip-1; % BPSK modulation 0->-1; 1->0
nRx=[1:20];
for jj=1:length(nRx)
n= 1/sqrt(2)*[randn(nRx(jj),N)+ 1i*randn(nRx(jj),N)]; %white guasian noice
h= 1/sqrt(2)*[randn(nRx(jj),N)+ 1i*randn(nRx(jj),N)]; %Rayleigh channel
%effective SNR
EbN0EffSim(jj)=mean(hSel.*conj(hSel));
EbN0EffTheory(jj)=sum(1./[1:nRx(jj)]);
end
%plot
close all
figure
plot(nRx,10*log10(EbN0EffSim), 'bp-', 'Linewidth',2);
hold on
plot(nRx,10*log10(EbN0EffTheory), 'gd-','linewidth',2);
axis([1 20 0 6])
grid on;
legend('theory','sim');
xlabel('no: of receive antenna');
ylabel('effective snr, dB');
title('snr improvement with selection compining')
OBSERVATION:-
Method 2:
%transmitter
ip=rand(1,N)>0.5; %generating 0,1 with equal probability
s=2*ip-1; % BPSK modulation 0->-1; 1->0
nRx=[1:20];
Eb_N0_dB=[25]; %multiple Eb/N0 values
for jj=1:length(nRx)
for ii=1:length(Eb_N0_dB)
n= 1/sqrt(2)*[randn(nRx(jj),N)+ j*randn(nRx(jj),N)]; %white guasian noice
h= 1/sqrt(2)*[randn(nRx(jj),N)+ j*randn(nRx(jj),N)]; %Rayleigh channel
%effective SNR
EbN0EffSim(ii,jj)=mean(yHat.*conj(yHat))/nRx(jj);
EbN0EffTheory(ii,jj)=(1+(nRx(jj)-1)*pi/4);
end
end
%plot
close all
figure
plot(nRx,10*log10(EbN0EffSim), 'gd-', 'Linewidth',2);
hold on
plot(nRx,10*log10(EbN0EffTheory), 'bp-','linewidth',2);
axis([1 20 0 14])
grid on;
legend('theory','sim');
xlabel('no: of receive antenna');
ylabel('SNR gain, dB');
title('snr improvement with selection compining')
OBSERVATION:-
Method 3:
for jj=1:length(nRx)
for ii=1:length(Eb_N0_dB)
n= 1/sqrt(2)*[randn(nRx(jj),N)+ j*randn(nRx(jj),N)]; %white guasian noice
h= 1/sqrt(2)*[randn(nRx(jj),N)+ j*randn(nRx(jj),N)]; %Rayleigh channel
%effective SNR
EbN0EffSim(ii,jj)=mean(abs(yHat));
EbN0EffTheory(ii,jj)=nRx(jj);
end
end
%plot
close all
figure
plot(nRx,10*log10(EbN0EffTheory), 'bd-', 'Linewidth',2);
hold on
plot(nRx,10*log10(EbN0EffSim), 'mp-','linewidth',2);
axis([1 20 0 16])
grid on;
legend('theory','sim');
xlabel('no: of receive antenna');
ylabel('SNR gain, dB');
title('snr improvement with Ratio compining')
OBSERVATION:-
RESULT