--------------------------------------------------------------------------------

hi guys
I'm a final year student, in engineering.
i've just signed up to this forum. Hope all is good. i'd appreciate any help.

I have a piece of matlab code which used to work like last year. but i am having some trouble with it now.

Before i f i entered values for theta0 and thetai. in the figures produced the main beam would move to theta0 value and a null placed for thetai value.

doing this now moves the beam but not to the values i want to.

for instance if i type in theta0=10; and thetai=50; the main beam moves in the negative direction by some other value. plz help me solve this problem. If you copy and paste this in matlab u'll see what i mean.

thanks for n e replies

%--------------------------------------------------------------------------------------------------------
% CODE FOR IMPLEMENTATION OF LMS ALGORITHM FOR DIRECTING
% BEAM TOWARDS THE DESIRED USER IN THE PRESENCE OF INTERFERERS
%---------------------------------------------------------------------------------------------------------

function arrayfact = lms_alg(K,d,lamda,f1,f2,theta0,thetai,SNR,SIR,Ni,no_samples)

K=8;
lamda=1;
d=lamda/2;
f1=0.1;
f2=0.23;

theta0=10;
thetai=50;


SNR=10;
SIR=5;
Ni=1;
no_samples=1000;

%--------------------------
%Variable Declaration
%--------------------------

conv_factor = 0.0011;kap = (2*pi)/lamda;

%--------------------
%Generating x(t)
%--------------------

alpha1 = kap*d*sin(theta0);
index1 = 0:K-1;
vtranspose = exp(j*(index1)*alpha1);

%----------------------------------------------------
%Generation of signal with Signal Power = 1
%----------------------------------------------------

index2 = 1:no_samples;
signal = sqrt(2)*cos(2*pi*f1*index2); % A = 1

%----------------------------------
%Addition of Gaussian noise
%----------------------------------

sig_noisepower = 1/(10^(SNR/10));
sig_noise = randn(1,no_samples);
sig_noise = sqrt(sig_noisepower)*sig_noise;

%-------------------------------------------------
%Generating Signal corrupted with Noise
%-------------------------------------------------

s = signal+sig_noise;


%-----------------------------------------------------------
%Generating Inteferer with Signal Power = A^2/2
%----------------------------------------------------------

for index3 = 1:Ni
alpha2 = kap*d*sin(thetai(index3));
ntranspose = exp(j*(index1)*alpha2);
interferer = cos(2*pi*f2*index2);

%-----------------------------------------------------------
%Generating Inteferer with Signal Power = A^2/2
%-----------------------------------------------------------

interferer = cos(2*pi*f2*index2);
int_noisepower = 1/(10^(SIR(index3)/10));
int_noise = sqrt(2*int_noisepower);

%-------------------------------------------------------------------------------
%Generating Interferer Signal multiplied with respective amplitude
%-------------------------------------------------------------------------------

u = int_noise*interferer; % Signal = Acos(wt)
end

%-------------------------------------
%Generating the actual signal
%-------------------------------------

signal_vector = [];
interferer_vector = [];
for temp = 1:no_samples
signal_vector = [signal_vector s(temp).*vtranspose'];
interferer_vector = [interferer_vector u(temp).*ntranspose'];
end
x = signal_vector+interferer_vector;

%------------------------------
%LMS Algorithm
%------------------------------
curr_wt = zeros(K,no_samples+1);
lms_error = zeros(1,no_samples);
updated_signal = zeros(1,no_samples);
for index4 = 1:no_samples
updated_signal = x(:,index4)'*curr_wt(:,index4);
lms_error(index4) = ((s(1,index4))- (x(:,index4)'*curr_wt(:,index4)));
curr_wt(:,index4+1)=curr_wt(:,index4)+(conv_factor.*lms_error(index4)*x(:,index4));
end
%-------------------------------------------------
%Plots (calling the function “arrayplot)
%--------------------------------------------------

figure;
plot([1:no_samples],abs(lms_error));
xlabel('Time');ylabel('LMS Error');
title('LMS Error Variation over time');
grid on
count = no_samples+1;
arrayplot(K,d,lamda,curr_wt,count,no_samples);

%------------------------------------------------------------------------
% Function to plot & generate the Array Factor with weights
%------------------------------------------------------------------------

function [arrfact] = arrayplot(K,d,lamda,curr_wt,count,no_samples)

%Variable Declaration
% K = No. of Array elements
% d = Inter-element spacing

kap = 2*pi/lamda;
l = 1;
for index = 1:length(count)
N = 2*no_samples;
wt = curr_wt(:,count(index));
arrfact = zeros(1,N*2+1);
for theta = -pii/Ni
n = 0:K-1;
v = exp(j.*n*kap*d*sin(theta));
arrfact(l) = wt'*v';
l = l+1;
end

arrfact = arrfact/max(arrfact);
theta = -pii/Ni;
theta = theta(N/2:3*N/2); % Plot from -90->90
arrfact = arrfact(N/2:3*N/2);
%Plots
figure;
polar(theta,abs(arrfact));
grid on;
title('Polar Plot of Array Factor');
figure;
plot(theta*180/pi,20*log10(abs(arrfact)));
grid on;
title('Rectangular Plot of Array Factor');
xlabel('theta(deg)');
ylabel('|Array Factor|');
axis([-90 90 -30 0]);
end

Dude your codes are all wrong, have you cut and paste from somewhere else???

example:

you are using pii (in MATLAB its pi)
your function is losing "Ni" in many places

many places your Index exceeds matrix dimensions:

like: theta = theta(N/2:3*N/2); % Plot from -90->90

you should work on it, before asking for help.

B4

Hi, I am a final yr student and working on lms algorithm.This programm has to be implemented with continuous additive training sequence. if u know how to decide desired signal and use in lms,pls help me.i would be grateful to u.Thanks
clear all
close all
x=2*ones(1000,1);
d=ones(1000,1);
c=zeros(1000,1);
for n=1:1000
y(n)=c(n)'*x(n)
e(n)=d(n)-y(n)
c(n+1)=c(n)+.0005*x(n)*e(n)
end;
figure
plot(e)
title('ERROR CURVE');
xlabel('SAMPLES')
ylabel('ERROR VALUE')

figure
plot(c)
title('COEFFICIENT CURVE');
xlabel('SAMPLES')
ylabel('COEFFICIENT VALUE')

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.