How to find the median in a zero crossing?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Jayanta Deb
le 19 Sep 2017
Commenté : Star Strider
le 20 Sep 2017
Hello, I have calculated zero crossings for a certain signal named 'zip9'. and plotted with a star mark on it. As shown in the figure using the following code: lets consider, y = zip9; zci = @(v) find(v(:).*circshift(v(:), [1 0]) <= 0); % Returns Zero-Crossing Indices Of Argument Vector zx = zci(y); % Approximate Zero-Crossing Indices figure(1) plot(t, y, '-r') hold on plot(t(zx), y(zx), 'bp') hold off grid legend('Signal', 'Approximate Zero-Crossings')
Now, If you zoom the picture towards zero crossings point you will see a picture something like that:
Please note: The zoomed picture is from the first group of start occurrences. Now What I need is that I need to calculate the median of the zero crossing points among those 9 points(picture 2). This has to be done for the rest of the periods. So basically I need to calculate the medians from each of the group of stars from a full period, not half a period.
0 commentaires
Réponse acceptée
Star Strider
le 19 Sep 2017
Thank you for quoting my code!
I am not certain what you intend by ‘median’ zero-crossings. It is straightforward to calculate the more precise zero-crossings using simple linear interpolation. (You can use interp1 for this, but the calculations in my code are likely more efficient for this simple problem.)
The Code —
t = linspace(0, 20*pi, 5000);
y = sin(2*pi*t);
zci = @(v) find(v(:).*circshift(v(:), [1 0]) <= 0); % Returns Zero-Crossing Indices Of Argument Vector
zx = zci(y);
for k1 = 1:numel(zx)-1 % Interpolate To Calculate ‘Exact’ Zero-Crossings
tv = t(zx(k1):zx(k1)+1); % Independent Variable Vector
yv = y(zx(k1):zx(k1)+1); % Dependent Variable Vector
b = [[1;1], tv(:)]\yv(:); % Linear Interpolation
ti(k1) = -b(1)/b(2); % Actual Zero-Crossing Times (Values Of Independent Variable)
end
figure(1)
plot(t, y)
hold on
plot(t(zx), y(zx), 'pg')
plot(ti, zeros(size(ti)), '+r')
hold off
figure(2) % Zoomed Plot (Optional)
plot(t, y)
hold on
plot(t(zx), y(zx), 'pg')
plot(ti, zeros(size(ti)), '+r')
hold off
axis([60 63 ylim])
6 commentaires
Plus de réponses (0)
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!