Generate Random Data with MATLAB
Generate Random Data with MATLAB
………
Anantapur Date :………………
Aim:-
To generate the random data at a given data rate.
Software Required:- Pc with MATLAB 7.0 or above
Theory:-
A maximum length sequence (MLS) is a type of pseudorandom binary
sequence.
They are bit sequences generated using maximal linear feedback shift
registers and are so called because they are periodic and reproduce every
binary sequence that can be reproduced by the shift registers (i.e., for
length-m registers they produce a sequence of length 2m − 1). A MLS is also
sometimes called an n-sequence or an m-sequence. MLSs are spectrally
flat, with the exception of a near-zero DC term.
These sequences may be represented as coefficients of irreducible
polynomials in a polynomial ring over Z/2Z.
Practical applications for MLS include measuring impulse responses (e.g., of
room reverberation). They are also used as a basis for deriving pseudo-
random sequences in digital communication systems that employ direct-
sequence spread spectrum and frequency-hopping spread spectrum
transmission systems, and in the efficient design of some MRI experiments
Generation of maximum length sequences
Figure 1: The next value of register a3 in a feedback shift register of
length 4 is determined by the modulo-2 sum of a0 and a1.
MLS are generated using maximal linear feedback shift registers. An MLS-
generating system with a shift register of length 4 is shown in Fig. 1. It can
be expressed using the following recursive relation:
where n is the time index, k is the bit register position, and + represents
modulo-2 addition.
Page No: 1
J.N.T.U. College of Engineering Exp. No: ….………
Anantapur Date :………………
As MLS are periodic and shift registers cycle through every possible binary
value (with the exception of the zero vector), registers can be initialized to
any state, with the exception of the zero vector.
A Gold code, also known as Gold sequence, is a type of binary
sequence, used in telecommunication (CDMA) and satellite navigation
(GPS). Gold codes are named after Robert Gold. Gold codes have bounded
small cross-correlations within a set, which is useful when multiple devices
are broadcasting in the same range. A set of Gold code sequences consists
of 2n − 1 sequences each one with a period of 2n − 1.
A set of Gold codes can be generated with the following steps. Pick two
maximum length sequences of the same length 2n − 1 such that their
absolute cross-correlation is less than or equal to 2(n + 2) / 2, where n is the
size of the LFSR used to generate the maximum length sequence (Gold '67).
The set of the 2n − 1 exclusive-ors of the two sequences in their various
phases (i.e. translated into all relative positions) is a set of Gold codes. The
highest absolute cross-correlation in this set of codes is 2(n + 2) / 2 + 1 for
even n and 2(n + 1) / 2 + 1 for odd n.
The exclusive or of two Gold codes from the same set is another Gold
code in some phase.
If l is odd, t = 2(l+1)/2 + 1, and
If l is even, t = 2(l+2)/2 + 1.
Thus, a Gold sequence formally is an arbitrary phase of a sequence in
the set G(u,v) defined by
G(u,v)= {u,v,u * v, u * Tv, u *T2 v, U * T(N-1) v}
Tk denotes the operator which shifts vectors cyclically to the left by k
places, * is the exclusive OR operator and u, v are m-sequences of period
generated by different primitive binary polynomials.
Matlab Program:-
clc;
clear all;
m=input('enter the size of shift registers m =');
N=2^m-1;
tt=-N+1:1:N;
x=ones(1,m);
Page No: 2
J.N.T.U. College of Engineering Exp. No: ….………
Anantapur Date :………………
x1=x;
taps1=input('enter the taps1 =');
taps2=input('enter the taps2 =');
for i=1:N
y1(i)=x1(m);
x2=xor12(x1,taps1);
x1=[x2 x1(1:m)];
end
%disp(y1);
%%%Test-1
T1=sum(y1);
disp('total number of of 1s in maximalseq1 1s');
disp(T1);
if(T1==2^(m-1))
disp('maximal sequence is exist between the selected taps1');
else
disp('maximal sequence is NOT exist between the selected taps1');
end
%%%test2
sy1=2*y1-1;
s1=correlation11(sy1,sy1);
figure(1);
plot(tt,s1);
title('Auto correlation of Maximal sequence1');
xlabel('no of samples---->');
ylabel('magnitude---->');
grid;
%%%2nd maximal sequences
for i=1:N
y2(i)=x(m);
x2=xor12(x,taps2);
x=[x2 x(1:m)];
end
%disp(y2);
%%%Test-1
T2=sum(y2);
disp('total number of of 1s in maximalseq2 1s');
disp(T2);
if(T2==2^(m-1))
disp('maximal sequence is exist between the selected taps2');
else
disp('maximal sequence is NOT exist between the selected taps2');
end
%%%test2
sy2=2*y2-1;
s2=correlation11(sy2,sy2);
figure(2);
plot(tt,s2);
title('Auto correlation of Maximal sequence2');
xlabel('no of samples---->');
Page No: 3
J.N.T.U. College of Engineering Exp. No: ….………
Anantapur Date :………………
ylabel('magnitude---->')
grid;
if(T1==T2)
%module-2 of 2'maximalseq is given as gold sequences(y)
y=xor(y1,y2);
g1=2*y-1;
%%%to check 3-value cross correlation function
x=correlation11(sy1,sy2);
figure(3);
plot(tt,x);
title('cross correlation of MLS1&MLS2');
xlabel('no of samples---->');
ylabel('magnitude---->')
grid;
%%% autocorrelation of gold sequences
xx=correlation11(g1,g1);
figure(4);
plot(tt,xx);
title('auto correlation of gold sequenceses');
xlabel('no of samples---->');
ylabel('magnitude---->')
grid;
disp('gold sequences is exist between the selected taps');
else
disp('gold sequences is NOT exist between the selected taps');
end
Page No: 4
J.N.T.U. College of Engineering Exp. No: ….………
Anantapur Date :………………
c(1)=xor(s(t(1)),s(t(2)));
for i=1:n-2
c(i+1)=xor(s(t(i+2)),c(i));
end
z=c(length(c));
end
correlation sub function:-
function res=correlation11(x,y)
%%%right shift operation
zzz=0;
for i=1:length(x)
rx=circshift(x,[1,i]);
z=y.*rx;
zz=sum(z);
zzz=[zzz zz];
end
zzz(:,1)=[];
Output Results:-
enter the size of shift registers m =7
enter the taps1 =[7 1]
enter the taps2 =[7 3]
total number of of 1s in maximalseq1 1s
64
maximal sequence is exist between the selected taps1
total number of of 1s in maximalseq2 1s
64
maximal sequence is exist between the selected taps2
gold sequences is exist between the selected taps
enter the MLsequence1 or MLSequence2 c=1
enter the No shift we want nn=23
Page No: 5
J.N.T.U. College of Engineering Exp. No: ….………
Anantapur Date :………………
Auto correlation of Maximal sequence1
140
120
100
80
magnitude---->
60
40
20
-20
-150 -100 -50 0 50 100 150
no of samples---->
120
100
magnitude---->
80
60
40
20
-20
-150 -100 -50 0 50 100 150
no of samples---->
10
5
magnitude---->
-5
-10
-15
-20
-150 -100 -50 0 50 100 150
no of samples---->
Page No: 6
J.N.T.U. College of Engineering Exp. No: ….………
Anantapur Date :………………
auto correlation of gold sequenceses
140
120
100
magnitude---->
80
60
40
20
-20
-150 -100 -50 0 50 100 150
no of samples---->
10
0
magnitude
-5
-10
-15
-20
-150 -100 -50 0 50 100 150
No of samples
Result:-
Thus the random data has been generated at a given data rate and the
outputs have been verified.
Page No: 7
J.N.T.U. College of Engineering Exp. No: ….………
Anantapur Date :………………
Page No: 8
J.N.T.U. College of Engineering Exp. No: ….………
Anantapur Date :………………
is exhibited by the assumption that the real and imaginary parts of the
response are modelled by independent and identically distributed zero-mean
Gaussian processes so that the amplitude of the response is the sum of two
such processes.
JAKE’S Model Diagram:-
Jakes' model:-
Jakes popularized a model for Rayleigh fading based on summing
sinusoids. Let the scatterers be uniformly distributed around a circle at
angles αn with k rays emerging from each scatterer. The Doppler shift on ray
n is and, with M such scatterers, the Rayleigh fading of the kth waveform
over time t can be modeled as: .
Here, and the and are model parameters with usually set to zero,
chosen so that there is no cross-correlation between the real and imaginary
parts of R(t): and used to generate multiple waveforms. If a single-path
channel is being modeled, so that there is only one waveform then can be
zero. If a multipath, frequency-selective channel is being modeled so that
multiple waveforms are needed, Jakes suggests that uncorrelated
waveforms are given by: .
Page No: 9
J.N.T.U. College of Engineering Exp. No: ….………
Anantapur Date :………………
In fact, it has been shown that the waveforms are correlated among
themselves — they have non-zero cross-correlation — except in special
circumstances. The model is also deterministic (it has no random element to
it once the parameters are chosen). A modified Jakes' model chooses
slightly different spacing for the scatterers and scales their waveforms using
Walsh-Hadamard sequences to ensure zero cross-correlation. Setting
And, Results in the following model, usually termed the Dent model or the
modified Jakes model:
The weighting functions Ak(n) are the kth Walsh-Hadamard sequence in
n. Since these have zero cross-correlation by design, this model results in
uncorrelated waveforms. The phases can be initialized randomly and have
no effect on the correlation properties. The Fast Walsh transform can be
used to efficiently generate samples using this model.
The Jakes' model also popularized the Doppler spectrum associated
with Rayleigh fading, and, as a result, this Doppler spectrum is often termed
Jakes' spectrum.
Program:-
Clear all;
v=input('MU speed in m/s....5, 10, 15, 20, 25,..>');
numpaths = 10; %number of paths
Fc = 900e6; %carrier frequency
Fs = 4*Fc; %sampling frequency
Ts = 1/Fs; %sampling period
t = [0:Ts:1999*Ts]; %time array
wc = 2*pi*Fc; %radian frequency
%v = 25; %vehicle speed in m/s
for i = 1:numpaths
wd = 2*pi*v*Fc*cos(unifrnd(0,2*pi))/3e8;
ray = ray + a.*cos((wc+wd)*t+unifrnd(0,2*pi,1,length(t)));
end
Page No: 10
J.N.T.U. College of Engineering Exp. No: ….………
Anantapur Date :………………
env_ray = sqrt(rayi.^2+rayq.^2); %envelope of received signal
subplot(2,2,1)
plot(t*1e9,ray)%plots the rf signal
title('rf signal')
xlabel('time ns')
ylabel('volt')
xlim([0 20])
subplot(2,2,2)
plot(t*1e9,rayi)%plots the inphase component
xlabel('time ns')
ylabel('volt')
xlim([0 20])
title('inphase component')
subplot(2,2,3)
plot(t*1e9,rayq)%plots the quadrature component
title('quadrature component')
xlabel('time ns')
ylabel('volt')
xlim([0 20])
subplot(2,2,4)
plot(t*1e9,env_ray)%plots the envelope
title('envelope')
xlabel('time ns')
ylabel('volt')
xlim([0 20])
end;
figure
plot(pow,poutth,':',pow,poutsim,'--');
xlabel('thrshold power dBm')
Page No: 11
J.N.T.U. College of Engineering Exp. No: ….………
Anantapur Date :………………
ylabel('outage probability')
legend('poutth','poutsim')
Output results:-
MU speed in m/s....5, 10, 15, 20, 25,..>20
mean_power =
9.8335
MK =
2000
Page No: 12
J.N.T.U. College of Engineering Exp. No: ….………
Anantapur Date :………………
% jakes model %
clc;
clear all;
N0=8;
N=2*(2*N0+1);
t=250*10^-3;
t1=0:t/(2500):t;
fm=input('enter the dopplear spread frequency fm=');
wm=2*pi*fm;
gamma=1;
fc=900*10^6;
pw1=0;
for s=0:(t/(2500)):t;
xca=0;
xsa=0;
i=1:N0;
wn=wm.*cos(2*pi*i/N);
bt=(pi*i/N0);
for i=1:N0;
x=cos(wn(i)*s);
xca=xca+x.*2*cos(bt(i));
xsa=xsa+x.*2*sin(bt(i));
end
x1=0.707*cos(2*pi*fm*s);
x1ca=x1*2*cos(gamma);
x1sa=x1*2*sin(gamma);
xc=xca+x1ca;
xs=xsa+x1sa;
Page No: 13
J.N.T.U. College of Engineering Exp. No: ….………
Anantapur Date :………………
y=xs.*sin(2*pi*fc*s)+xc.*cos(2*pi*fc*s);
%disp(y)
z=y.^2;
pw=10*log10(z);
pw1=[pw1 pw];
end
%disp(pw1);
plot(pw1(2:length(pw1)));
title(' rayleigh fading channel by using jakes model');
xlabel('samples');
ylabel('power (db)');
% axis([0 120 -50 20]);
grid;
Output results:-
10
-10
-20
power (db)
-30
-40
-50
-60
-70
-80
0 500 1000 1500 2000 2500 3000
samples
Result:-
Thus we have simulated the Rayleigh Fading channel incorporating speed
of the mobile and power delay profile.
Page No: 14
J.N.T.U. College of Engineering Exp. No: ….………
Anantapur Date :………………
Theory:
This yields two phases, 0 and π. In the specific form, binary data is often
conveyed with the following signals:
Page No: 15
J.N.T.U. College of Engineering Exp. No: ….………
Anantapur Date :………………
or
Matlab Program:
clear all;
Eb_No = [1,2,3,4,5,6,7];
No = 1;
Eb = Eb_No * No ;
N=4;
symbol_number = 10000 ;
m = rand(1,symbol_number) ;
[i] = find(m>0.5) ;
Page No: 16
J.N.T.U. College of Engineering Exp. No: ….………
Anantapur Date :………………
[j] = find(m<=0.5) ;
m(i) = 1 ;
m(j) = 0 ;
for k = 1:length(Eb)
E = 10^(Eb(k)/10) ;
E = sqrt(2*E/N) ;
s1 = ones(1,N)*E ;
s2 = ones(1,N)*(-E) ;
for i = 1:symbol_number
if m(i) == 0
message((i-1)*(N) + 1 : (i-1)*(N) + N) = s2 ;
else
message((i-1)*(N) + 1 : (i-1)*(N) + N) = s1 ;
end
end
received_signal = awgn(message,Eb(k)) ;
for j = 1:N
c1(j) = s1(5-j) ;
c2(j) = s2(5-j) ;
end
Z1 = conv(received_signal, c1) ;
Z2 = conv(received_signal, c2) ;
for i = 1:symbol_number
end
error = xor(m_hat,m) ;
Page No: 17
J.N.T.U. College of Engineering Exp. No: ….………
Anantapur Date :………………
error_number = length(find(error>0))
Pb(k) = error_number/symbol_number ;
end
figure
semilogy(Eb_No,Pb);
Qx = (1/2)*erfc((10.^(Eb/10))/sqrt(2)) ;
figure
figure
plot(Eb_No,Pb,'r',Eb_No,Qx);
ylabel(' Pb ');
Page No: 18
J.N.T.U. College of Engineering Exp. No: ….………
Anantapur Date :………………
Output Results:
Page No: 19
J.N.T.U. College of Engineering Exp. No: ….………
Anantapur Date :………………
Result:
Thus Simulation of BPSK system over AWGN channel & finding its
performance with BER
Page No: 20
J.N.T.U. College of Engineering Exp. No: ….………
Anantapur Date :………………
Linear Equalizers:
The most common type of equalizers used to reduce ISI are adaptive
equalizers that update their parameters on periodic basis during the
transmission of data so they are capable of tracking slowly time varying
channel response.
K=[0.05 -0.063 0.088 -0.126 -0.25 0.9047 0.25 0.0126 0.038 0.088]
Page No: 21
J.N.T.U. College of Engineering Exp. No: ….………
Anantapur Date :………………
where , n<0
For Instance, The gradient vector denoted as for the MSE criterion
found by taking the derivatives of MSE w.r.t each of 2K+1 coefficients is
Page No: 22
J.N.T.U. College of Engineering Exp. No: ….………
Anantapur Date :………………
Error signal
Where
Page No: 23
J.N.T.U. College of Engineering Exp. No: ….………
Anantapur Date :………………
equalizer used to form the error signal .The error is scaled by step size
parameter and scaled error signal multiplies the received signal values
Matlab Program:
%%% echo on
clear all;
close all;
N = 20000;
Nt = [1000000 1000000 1000000 1000000 1000000 5000000 10000000];
delta = 0.0045;
K = 5;
actual_isi = [0.05 -0.063 0.088 -0.126 -0.25 0.9047 0.25 0 0.126 0.038
0.088];
snr_db = 2:2:14;
snr = 10.^(snr_db/10);
l_snr = size(snr,2);
var = 1/2./snr;
sigma = sqrt(var);
pe = zeros(1,l_snr);
for idx = 1:l_snr
% [A] the training sequence
training_s = ones(1,N);
for i = 1:N
if(rand<0.5)
training_s(i) = -1 ;
end
Page No: 24
J.N.T.U. College of Engineering Exp. No: ….………
Anantapur Date :………………
end
% The channel output
y = filter(actual_isi,1,training_s);
noise = zeros(1,N);
for i = 1:2:N
noise(i) = random('Normal',0,sigma(idx));
noise(i+1) = noise(i);
end
y = y +noise;
% The equalization part follows
estimated_c = [0 0 0 0 0 1 0 0 0 0 0]; % initial estimate of isi
for k = 1:N-2*K
y_k = y(k:k+2*K);
z_k = estimated_c*y_k';
e_k = training_s(k) - z_k;
estimated_c = estimated_c + delta*e_k*y_k;
end
% (B) the transmitted information sequence
info = ones(1,Nt(idx));
for i = 1:Nt(idx)
if(rand<0.5)
info(i) = -1;
end
end
% The channeled output
y = filter(actual_isi,1,info);
noise = sigma(idx)*randn(1,Nt(idx));
y = y + noise;
% The equalization part
count = 0;
err_count = 0;
z_k_vec = ones(1,Nt(idx) - 2*K);
for k = 1:Nt(idx)-2*K;
y_k = y(k:k+2*K);
z_k = estimated_c*y_k';
if z_k<0
z_k_vec(k) = -1 ;
end
err_count = err_count + 0.5*abs(info(k)-z_k_vec(k));
end
pe(idx) = err_count/length(z_k_vec);
clear y; clear noise
end
% Plot the results
semilogy(snr_db,pe)
grid
ylabel(' pe ')
xlabel(' snr(db) ')
Page No: 25
J.N.T.U. College of Engineering Exp. No: ….………
Anantapur Date :………………
Output Results:
Result:
Implementing equalization at the receiver to remove ISI caused
due to low channel bandwidth is simulated and results are verified.
Page No: 26
J.N.T.U. College of Engineering Exp. No: ….………
Anantapur Date :………………
Page No: 27
J.N.T.U. College of Engineering Exp. No: ….………
Anantapur Date :………………
Rake receiver:-
If, in a mobile radio channel reflected waves arrive with small relative
time delays, self interference occurs. Direct Sequence (DS) Spread
Spectrum is often claimed to have particular properties that makes it less
vulnerable to multipath reception. In particular, the rake receiver architecture
allows an optimal combining of energy received over paths with different. It
avoids wave cancellation (fades) if delayed paths arrive with phase
differences and appropriately weighs signals coming in with different signal-
to-noise ratios.
The rake receiver consists of multiple correlators, in which the receive
signal is multiplied by time-shifted versions of a locally generated code
sequence. The intention is to separate signals such that each finger only
sees signals coming in over a single (resolvable) path. The spreading code
is chosen to have a very small autocorrelation value for any nonzero time
offset. This avoids crosstalk between fingers. In practice, the situation is less
ideal. It is not the full periodic autocorrelation that determines the crosstalk
between signals in different fingers, but rather two partial correlations, with
contributions from two consecutive bits or symbols. It has been attempted to
find sequences that have satisfactory partial correlation values, but the
crosstalk due to partial (non-periodic) correlations remains substantially
more difficult to reduce than the effects of periodic correlations.
Page No: 28
J.N.T.U. College of Engineering Exp. No: ….………
Anantapur Date :………………
The rake receiver is designed to optimally detect a DS-CDMA signal
transmitted over a dispersive multipath channel. It is an extension of the
concept of the matched filter.
In a multipath channel, delayed reflections interfere with the direct
signal. However, a DS-CDMA signal suffering from multipath dispersion can
be detected by a rake receiver. This receiver optimally combines signals
received over multiple paths.
Like a garden rake, the rake receiver gathers the energy received over
the various delayed propagation paths. According to the maximum ratio
combining principle, the SNR at the output is the sum of the SNRs in the
individual branches, provided that
we assume that only AWGN is present (no interference)
codes with a time offset are truly orthogonal
Matlab Program:
clc;
clear all;
e=1;
snrdb=0:1:20;
n=1000;
L=length(snrdb);N=7;code=[1 1 1 -1 -1 1 -1];G=7;chipsperslot=7;
bfad=randn(1,10);%[0.1 -0.2 0.3];
bfadt=conj(fliplr(bfad));%[0.3 -0.2 0.1];
t=0:ts:((n*tb/2)-ts);
sp=10;
for ii=1:L
pe1=0;
snr=10^((ii-1)/10);
sigmao=sqrt(sum(bfad.*bfadt)*G/snr);
%%%data generater
d=rand(1,n)>.5;
d1=2*d-1;
%%%%SPREADING THE DATA
% out=conv(d1,code);
out=[];
for i=1:n
out=[out d1(i)*code];
end
K=length(bfad);
Page No: 29
J.N.T.U. College of Engineering Exp. No: ….………
Anantapur Date :………………
mfdata=conv(out,bfad);
% %% AWGN CHANNEL
w=sigmao.*randn(1,length(mfdata));
rx=w+mfdata;
% %%AT RECEIVER SIDE
%%%matched filter
mfdata1=conv(rx,conj(fliplr(bfad)));
%delay=length(code)+length(bfad);
getdata=mfdata1(3:length(mfdata1)-2);
%getdata=mfdata1(delay:delay+chipsperslot);
%getdata=getdata(K:length(code):length(getdata));
rdata=getdata;
for i=1:n
rdata(i)= getdata(((K)+(i-1)*N));
end
rd=rdata>0;
for i=1:n
if(rd(i)==d(i))
else
pe1=pe1+1;
end
end
pe2(ii)=pe1;
%%probability error in simulated system
BER(ii)=pe2(ii)/(n);
%%probability error in theoretical function
geta=G*(sum(bfad.*bfadt)/sigmao^2);
qf4(ii)=0.5*(1-sqrt(geta/(1+geta)));
end
disp(pe2);
disp(qf4);
disp('bit error rate is');
disp(BER);
semilogy(snrdb,BER,'-o',snrdb,qf4,'-+');
hold all;
%axis([0 14 10e-7 10e-1]);
legend(' praticalBER','theoreticalBER');
title('BER performance of RAKE Receiver')
xlabel('snrdb--->');
ylabel('Pe--->');
grid;
Page No: 30
J.N.T.U. College of Engineering Exp. No: ….………
Anantapur Date :………………
Output Result:-
Result:-
Thus we have implemented the Rake Receiver and its performance has
been calculated through BER curve.
Page No: 31
J.N.T.U. College of Engineering Exp. No: ….………
Anantapur Date :………………
Aim:- To implement the LMS algorithm to estimate the original data when it
is corrupted by noise and channel.
Software Required:- Pc with MATLAB 7.0 or above.
Theory:-
Adaptive Noise Cancellation (ANC) and its Applications. Adaptive noise
Cancellation is an alternative technique of estimating signals corrupted by
additive noise or interference. Its advantage lies in that, with no apriori
estimates of signal or noise, levels of noise rejection are attainable that
would be difficult or impossible to achieve by other signal processing
methods of removing noise.
Its cost, inevitably, is that it needs two inputs - a primary input containing
the corrupted signal and a reference input containing noise correlated in
some unknown way with the primary noise. The reference input is
adaptively filtered and subtracted from the primary input to obtain the signal
estimate. Adaptive filtering before subtraction allows the treatment of
inputs that are deterministic or stochastic, stationary or time-variable.
Page No: 32
J.N.T.U. College of Engineering Exp. No: ….………
Anantapur Date :………………
Matlab Program:
echo on
N = 500 ;
K=5;
actual_isi = [0.05 -0.063 0.088 -0.126 -0.25 0.9047 0.25 0 0.126 0.038 0.088] ;
sigma = 0.01 ;
delta = 0.115 ;
Num_of_realizations = 1000 ;
mse_av = zeros(1,N-2*K) ;
for j = 1:Num_of_realizations
% the information sequence
for i = 1:N
if(rand<0.5)
info(i) = -1 ;
else
info(i) = 1 ;
end
echo off ;
Page No: 33
J.N.T.U. College of Engineering Exp. No: ….………
Anantapur Date :………………
end
if(j == 1) ;
echo on ;
end
% the channel output
y = filter(actual_isi,1,info);
for i = 1:2:N, [noise(i) noise(i+1)] = gngauss(sigma) ; end;
y = y+noise ;
% Now the equalization part follows
estimated_c = [ 0 0 0 0 0 1 0 0 0 0 0] ; % initial estimate of ISI
for k = 1:N-2*K,
y_k = y(k:k+2*K) ;
z_k = estimated_c*y_k.' ;
e_k = info(k) - z_k ;
estimated_c = estimated_c + delta*e_k*y_k ;
mse(k) = e_k^2 ;
echo off ;
end ;
if(j == 1) ; echo on ; end
mse_av = mse_av + mse ;
echo off ;
end ;
echo on ;
mse_av = mse_av/Num_of_realizations ; % mean-squared error versus
iteraions
% plotting commands follow.
figure
plot(y)
ylabel(' data corrupted by noise and channel ')
xlabel(' number of iterations ')
figure
plot(mse_av)
ylabel(' average mean square error ')
xlabel(' number of iterations ')
if nargin == 0,
Page No: 34
J.N.T.U. College of Engineering Exp. No: ….………
Anantapur Date :………………
m = 0 ; sgma = 1 ;
elseif nargin ==1,
sgma = m; m =0 ;
end ;
u = rand ; % a uniform random variable in (0,1)
z = sgma*(sqrt(2*log(1/(1-u)))) ; % a Rayleigh distributed random variable
u = rand ; % another uniform random variable in (0,1)
gsrv1 = m + z*cos(2*pi*u) ;
gsrv2 = m + z*sin(2*pi*u) ;
Output Result:-
Page No: 35
J.N.T.U. College of Engineering Exp. No: ….………
Anantapur Date :………………
Result:-
Page No: 36
J.N.T.U. College of Engineering Exp. No: ….………
Anantapur Date :………………
parameters:
p = filter order
forgetting factor
value to initialize p(0)
n = length of the desired signal
Initialization:
Page No: 37
J.N.T.U. College of Engineering Exp. No: ….………
Anantapur Date :………………
w = [ w(0) = 0 ,w(1) = 0 ,.......,w(p) = 0]
computations:
Matlab Program:
% Recursive Least Squares
% Importing Data
% Vectors must have same length and sampling frequency
% signal = source input
% noise = noise to add to source input
% ref = reference signal (e.g. delayed noise)
% lambda = forgetting factor,
% M = filter order
% delta = initial value for P; use a value in the 10^-3 range
% Output arguments:
% xi = output
% w = final filter coefficients
% Initialization
clear all;
close all;
clc;
lambda = 1;
M =5;
delta = .0005;
w=zeros(M,1); k=zeros(M,1);
t=1:.025:5;
signal=5*sin(2*3.*t);
ref=5*sin(2*50*3.*t+3/20);
noise=random('normal',0,t);
primary = signal + noise;
subplot(5,1,1);
plot(t,signal);
ylabel('signal');
subplot(5,1,2);
Page No: 38
J.N.T.U. College of Engineering Exp. No: ….………
Anantapur Date :………………
plot(t,noise);
ylabel('noise');
subplot(5,1,3);
plot(t,primary);
ylabel('primary');
% eye(M) gives an MxM identity matrix
% dividing by delta replaces the 1's in the identity matrix with delta^-1
P=eye(M)/delta;
% Loop, RLS
for n=M:N
uvec=ref(n:-1:n-M+1);
k=lambda^(-1)*P*uvec'/(1+lambda^(-1)*uvec*P*uvec');
% xi is output
xi(n)=primary(n)-w'*uvec';
% Recursive equation to minimize cost function (difference between the
% desired and input signals)
w=w+k*conj(xi(n));
P=lambda^(-1)*P-lambda^(-1)*k*uvec*P;
end
subplot(5,1,5);
plot(t(1:length(MSE)), MSE)
xlabel('Time (seconds)')
ylabel('Error')
title('Mean Squared Error')
Page No: 39
J.N.T.U. College of Engineering Exp. No: ….………
Anantapur Date :………………
OUTPUT RESULTS:
Result:
Page No: 40