필터 지우기
필터 지우기

Error when trying to use output value of a function in another fucntion

조회 수: 1 (최근 30일)
Gova ReDDy
Gova ReDDy 2013년 12월 23일
댓글: Gova ReDDy 2013년 12월 23일
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.

채택된 답변

Matt J
Matt J 2013년 12월 23일
편집: Matt J 2013년 12월 23일
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.
  댓글 수: 3
Matt J
Matt J 2013년 12월 23일
편집: Matt J 2013년 12월 23일
You should pass w to simple_LMS2() as an additional input argument. Currently, however, simple_LMS2 only accepts 4 input arguments, not 5
x,d,mu_step,M
Gova ReDDy
Gova ReDDy 2013년 12월 23일
thanks Matt J it is working now.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matched Filter and Ambiguity Function에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by