Finding zeroes of data for multiple trials

2 次查看(过去 30 天)
I have found that the answer to another question on MATLAB Answers (found here: Previous Question) works for finding the zeroes of one of my data trials (see code below).
x = QF02num(:,1);
y = QF02num (:,2);
%%Code is from Star Strider in Previous Question (see link above)
zci = @(v) find(v(:).*circshift(v(:), [-1 0]) <= 0); % Returns Approximate Zero-Crossing Indices Of Argument Vector
dy = zci(y); % Indices of Approximate Zero-Crossings
for k1 = 1:size(dy,1)-1
b = [[1;1] [x(dy(k1)); x(dy(k1)+1)]]\[y(dy(k1)); y(dy(k1)+1)]; % Linear Fit Near Zero-Crossings
x0(k1) = -b(1)/b(2); % Interpolate :Exact, Zero Crossing
mb(:,k1) = b; % Store Parameter Estimates (Optional)
end
However, my data consists of multiple trials. I have a matrix called QF02num(91X81) that has 81 trials of data for which I am wanting to find the zeroes. The length of these trials (or the number of rows) and the number of times the data will cross the x axis both vary from trial to trial.
I have tried adding a for loop to iteratively go through each column or trial but I'm not sure how to store the zeroes (x0) for all the trials into one matrix. How do I make it so x0 stores the values of each iteration or column (i)?
for i=size(QF02num,2);
x = QF02num(:,1);
y = QF02num (:,i);
%%Code is from Star Strider in Previous Question (see link above)
zci = @(v) find(v(:).*circshift(v(:), [-1 0]) <= 0); % Returns Approximate Zero-Crossing Indices Of Argument Vector
dy = zci(y); % Indices of Approximate Zero-Crossings
for k1 = 1:size(dy,1)-1
b = [[1;1] [x(dy(k1)); x(dy(k1)+1)]]\[y(dy(k1)); y(dy(k1)+1)]; % Linear Fit Near Zero-Crossings
x0(k1) = -b(1)/b(2); % Interpolate :Exact, Zero Crossing
mb(:,k1) = b; % Store Parameter Estimates (Optional)
end
end
I have included a plot of one of the trials for visualization:

回答(1 个)

Image Analyst
Image Analyst 2020-12-21
Assuming mb is your signal that you plotted, you can count the number of regions where the signal is above zero with this:
[, count] = bwlabel(mb > 0);

类别

Help CenterFile Exchange 中查找有关 Multirate Signal Processing 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by