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

3 ビュー (過去 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 Center および File ExchangeLogical についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by