필터 지우기
필터 지우기

how to generate loop for given program

조회 수: 3 (최근 30일)
Ali Asghar
Ali Asghar 2019년 8월 16일
댓글: darova 2019년 8월 21일
my dataset buttLoop3 is 24000x4 and i want to find out zero crossing of it...
i want to do below work in loop instead of typing it 4 time
zcd = dsp.ZeroCrossingDetector % calling function to detect zero count...
zcdOut = zcd(buttLoop3); % it counts how many times signals cross zero
y1 = buttLoop3(:,1) ; % filtered signal
zci = @(v) find(v(:).*circshift(v(:), [-1 0]) <= 0); % Returns Approximate Zero-Crossing Indices Of Argument Vector
xi1 = zci(y1); % zero crossing indices command
for k = 1:numel(xi1)-1
ti1(k) = interp1(y1([xi1(k) xi1(k)+1]), t([xi1(k) xi1(k)+1]), 0); % Interpolate To Find ‘t’ At ‘y=0 ’
end
y2 = buttLoop3(:,2) ; % filtered signal
zci = @(v) find(v(:).*circshift(v(:), [-1 0]) <= 0); % Returns Approximate Zero-Crossing Indices Of Argument Vector
xi2 = zci(y2); % zero crossing indices command
for k = 1:numel(xi2)-1
ti2(k) = interp1(y2([xi2(k) xi2(k)+1]), t([xi2(k) xi2(k)+1]), 0); % Interpolate To Find ‘t’ At ‘y=0 ’
end
y3 = buttLoop3(:,3) ; % filtered signal
zci = @(v) find(v(:).*circshift(v(:), [-1 0]) <= 0); % Returns Approximate Zero-Crossing Indices Of Argument Vector
xi3 = zci(y3); % zero crossing indices command
for k = 1:numel(xi3)-1
ti3(k) = interp1(y3([xi3(k) xi3(k)+1]), t([xi3(k) xi3(k)+1]), 0); % Interpolate To Find ‘t’ At ‘y=0 ’
end
y4 = buttLoop3(:,4) ; % filtered signal
zci = @(v) find(v(:).*circshift(v(:), [-1 0]) <= 0); % Returns Approximate Zero-Crossing Indices Of Argument Vector
xi4 = zci(y4); % zero crossing indices command
for k = 1:numel(xi4)-1
ti4(k) = interp1(y4([xi4(k) xi4(k)+1]), t([xi4(k) xi4(k)+1]), 0); % Interpolate To Find ‘t’ At ‘y=0 ’
end

답변 (1개)

darova
darova 2019년 8월 16일
Then use for loop
% a(1) = 2;
% a(2) = 3;
% a(3) = 4;
% a(4) = 5;
for i = 1:4
a(i) = i+1;
end
Simple
  댓글 수: 2
Ali Asghar
Ali Asghar 2019년 8월 21일
dear
kindly suggest complete code.
like
or i = 1:4
a(i) = i+1;
y(i) = filter_datawindow(:,i) ; % filtered signal
zci = @(v) find(v(:).*circshift(v(:), [-1 0]) <= 0); % Returns Approximate Zero-Crossing Indices Of Argument Vector
x(i) = zci(y(i)); % zero crossing indices command
for k = 1:numel(x(i))-1
ti1(k) = interp1(y(i)([x(i)(k) x(i)(k)+1]), t([x(i)(k) x(i)(k)+1]), 0); % Interpolate To Find ‘t’ At ‘y=0 ’
end
end
this give error
darova
darova 2019년 8월 21일
It's because you trying to assign
x(i) = [1 2 3];
You don't need indexes in this case
y = filter_datawindow(:,i) ; % filtered signal

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

카테고리

Help CenterFile Exchange에서 Filter Design and Analysis에 대해 자세히 알아보기

태그

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by