Borrar filtros
Borrar filtros

help error: Reference to a cleared variable data.

5 visualizaciones (últimos 30 días)
phan nam
phan nam el 15 de Mayo de 2014
Comentada: Humberto Parra Vargas el 8 de Abr. de 2021
I appreciate your help.
error: Reference to a cleared variable data.
Error in tsanam (line 64) y=data(x);
------------------------------------------------------------------------------
function [tsadata, navgs,trev]=tsa(data,tachsignal,fsample,tachtype,ratio,ncycles,navgs)
clear all; clc;
%INPUT
% data= the scaled vibration time series
% tachsignal= the digitized tach signal
% fsample= data sample rate, must be the same for both the data and tach signals
% tachtype= sine or TTL, if sine is specified a frequency of ~11 kHz is assumed
% ratio= if the tach signal waa measured on a shaft other than the gear of interest, this
% value specifies (1X frequency for shaft of interest / tach frequency)
% ncycles= number of periods in the final TSA
%OPTIONAL INPUT PARAMETER:
% navgs= Number of synchronous averages, if no value is specified the maximum
% number of averages possible is used.
%OUTPUT
% tsadata= the time synchronously averaged waveform
% navgs=number of cycles used to obtain TSA
%
%switch tachtype
%%%case 'TTL'
% offset tach to detect zero crossings
monnang=load('50f.txt');
tachsignal=monnang(:,3);
ncycles=2;
ratio=0.097;
tachsignal = tachsignal - 2.5;
% find the portion of the tach vector that is zero or negative
% Exclude the first value to insure that (i-1)>=1
x=find(tachsignal(2:length(tachsignal))<=0)+1;
% find the zero crossings
xx=find(tachsignal(x-1)>0);
i=x(xx);
if ((ncycles/ratio)~=1)
% Determine indices for each ncycles of shaft of interest from tach cycles
% Note that the vector itrev when multipled by dt=1/fsample yeilds the
% zero crossing times starting with ??? <-can't read what was written here
m=floor(length(i)*ratio/ncycles);
itrev=zeros(m,1);
itrev(1)=((i(1)-1)+(0-tachsignal(i(1)-1))/(tachsignal(i(1))-tachsignal(i(1)-1)));
for p=2:m
sip=i(floor((p-1)*ncycles/ratio)+1);
itrevp=((sip-1)+(0-tachsignal(sip-1))/(tachsignal(sip)-tachsignal(sip-1)));
siq=i(ceil((p-1)*ncycles/ratio)+1);
itrevq=((siq-1)+(0-tachsignal(siq-1))/(tachsignal(siq)-tachsignal(siq-1)));
itrev(p)=itrevp+(itrevq-itrevp)*[(p-1)*ncycles/ratio-floor((p-1)*ncycles/ratio)];
end
else
%When ncycles/ratio=1
itrev =((i-1)'+(i - (i-1))'*(0-tachsignal(i-1))/(tachsignal(i)-tachsignal(i-1)));
end
%Determine radix 2 number such that number of points in resampled TSA waveform
%corresponds to a sample rate just greater than fsample
N=2^ceil(log2((mean(diff(itrev)))));
%Define the number of averages to perform
if nargin < 7
navgs = length(itrev)-1;
end
% resample vibe data using zero crossing times
%use the time vector to interpolate the vibe data
yy = zeros(1,N);
for k = 1:navgs
% select the subsection of the vector to operate on
x=floor(itrev(k)):ceil(itrev(k+1));
y=data(x);
% generate resample time values
itresample = (itrev(k):(itrev(k+1)-itrev(k))/(N-1):itrev(k+1));
% accumulate the vector values for each rev
yy = yy + spline(x,y,itresample);
end
% compute the average
tsadata = yy/navgs;

Respuestas (1)

Sara
Sara el 15 de Mayo de 2014
remove
clear all
otherwise the input parameters get cleared before doing any calculations.
  3 comentarios
Ngoc Nguyen
Ngoc Nguyen el 19 de Oct. de 2017
You're a genius! Thanks
Humberto Parra Vargas
Humberto Parra Vargas el 8 de Abr. de 2021
i love you, you're the most beautifull genius

Iniciar sesión para comentar.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by