Error when trying to use output value of a function in another fucntion
조회 수: 1 (최근 30일)
이전 댓글 표시
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
채택된 답변
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.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Filter Analysis에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!