Error when trying to use output value of a function in another fucntion
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Gova ReDDy
am 23 Dez. 2013
Kommentiert: Gova ReDDy
am 23 Dez. 2013
Hello, I am trying to use the output value(w) of a function(simple_LMS1) in another fucntion(simple_LMS2) but it giving error like
Undefined function or variable "w".
Error in simple_LMS2 (line 10)
y(n) = w'*x1; % filter output
Error in Motion_simple_LMS (line 12)
[w,y,e,W]=simple_LMS2(x1,x1,0.1,M);
The code I am uisng is
P=load('Analog_signal.mat');
a2=P.a1;
M=5;
for i=1:500:length(a2)-2000
if(i<499)
x1=a2(i:i+499,:);
[w,y,e,W]=simple_LMS1(x1,x1,0.1,M);
else
x1=a2(i:i+499,:);
[w,y,e,W]=simple_LMS2(x1,x1,0.1,M);
pause(0.2);
end;
end
The simple_LMS1 function is
function [w,y,e,W] = simple_LMS1(x,d,mu_step,M)
N = length(x); % number of data samples
y = zeros(N,1); % initialize filter output vector
w = zeros(M,1); % initialize filter coefficient vector
e = zeros(N,1); % initialize error vector
W = zeros(M,N); % filter coefficient matrix for coeff. history
for n = 1:N
if n <= M % assume zero-samples for delayed data that isn't available
k = n:-1:1;
x1 = [x(k); zeros(M-numel(k),1)];
else
x1 = x(n:-1:n-M+1); % M samples of x in reverse order
end
y(n) = w'*x1; % filter output
e(n) = d(n) - y(n); % error
w = w + mu_step*e(n)'*x1; % update filter coefficients
W(:,n) = w; % store current filter coefficients in matrix
end
Function simple_LMS2 is
function [w,y,e,W] = simple_LMS2(x,d,mu_step,M)
N = length(x); % number of data samples
for n = 1:N
if n <= M % assume zero-samples for delayed data that isn't available
k = n:-1:1;
x1 = [x(k); zeros(M-numel(k),1)];
else
x1 = x(n:-1:n-M+1); % M samples of x in reverse order
end
y(n) = w'*x1; % filter output
e(n) = d(n) - y(n); % error
w = w + mu_step*e(n)'*x1; % update filter coefficients
W(:,n) = w; % store current filter coefficients in matrix
end
can someone tell me how to solve this error so that I can use 1st function output in the 2nd fucntion.
0 Kommentare
Akzeptierte Antwort
Matt J
am 23 Dez. 2013
Bearbeitet: Matt J
am 23 Dez. 2013
In the line
y(n) = w'*x1; % filter output
the variable w is undefined. It was never previously introduced into the workspace of simple_LMS2, either as an input argument or otherwise.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Filter Analysis finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!