MATLAB Answers

Getting error when i am running my code........plz help me.

1 view (last 30 days)
devendra parihar
devendra parihar on 7 Dec 2015
Edited: Stephen Cobeldick on 7 Dec 2015
%%Amplitude Based STA/LTA
function[pwaveTime,ratio,sta_buffer,lta_buffer]= aslta(Test_data)
m = length(Test_data);
sta_wnd = 0.1;
lta_wnd = 3;
trigger_threshold =3;
fs = 100; %sampling requency
x= fs*sta_wnd;
y= fs*lta_wnd;
i=1;
tr = 1;
trigLoc=zeros(m,1);
scal = 'mln';
for loop = 1:floor((m-y)/x)
windowed_data= wden(Test_data(i:i+y+x-1),'sqtwolog','s',scal,3,'db8');
% window number? loop number will decidea
disp(['Window Number' int2str(loop)])
lta_buffer(loop) = mean(abs(detrend(windowed_data(i:i+y-1))));
sta_buffer(loop) = mean(abs(detrend(windowed_data(i+y:i+y+x-1))));
ratio(loop) = sta_buffer(loop)/lta_buffer(loop);
if(ratio(loop)>=trigger_threshold)
trigLoc(tr)= loop;
lta_freeze = lta_buffer(loop);
tr = tr+1;
end
i = i+x;
pwaveData = trigLoc(1)*x; % Add previous window number multiplied by data points in each window
pwaveTime = (pwaveData+y)/fs; % Add time of each window
% clear loop;
% clear lta_buffer;
% clear sta_buffer;
% clear ratio;
end
end
error which i am getting is ..........
Index exceeds matrix dimensions.
Error in aslta (line 20) sta_buffer(loop) = mean(abs(detrend(windowed_data(i+y:i+y+x-1))));

  0 Comments

Sign in to comment.

Answers (1)

Stephen Cobeldick
Stephen Cobeldick on 7 Dec 2015
Edited: Stephen Cobeldick on 7 Dec 2015
You are going to have to learn how to use the debugging tools. This will help you to find errors on your own, without needing to ask strangers on the internet. The basic problem is that you are trying to access an element of an array that does not exist. It occurs on this line:
sta_buffer(loop) = mean(abs(detrend(windowed_data(i+y:i+y+x-1))));
and most likely is due to this indexing here:
windowed_data(i+y:i+y+x-1)
If you use the debugging command
dbstop if error
then it will stop at that point and you can have a look at those variables. Have a look at
numel(windowed_data)
and then the values of
i+y:i+y+x-1
and you will probably find that you are trying to access values of windowed_data that simply do not exist. Note that we do not have your data and so we cannot run your code.
The f9 key will also be useful here, as it runs any selected text.

  0 Comments

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!