Finding zeroes of data for multiple trials
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
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:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/467635/image.png)
0 Commenti
Risposte (1)
Image Analyst
il 21 Dic 2020
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);
0 Commenti
Vedere anche
Categorie
Scopri di più su Multirate Signal Processing in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!