フィルターのクリア

How to find the median in a zero crossing?

2 ビュー (過去 30 日間)
Jayanta Deb
Jayanta Deb 2017 年 9 月 19 日
コメント済み: Star Strider 2017 年 9 月 20 日
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.

採用された回答

Star Strider
Star Strider 2017 年 9 月 19 日
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 件のコメント
Jayanta Deb
Jayanta Deb 2017 年 9 月 20 日
Thanks Star. The solution has partially helped me to solve my problem. It at least gave me a new dimension to think. Thanks again to help me out even the things were complicated... :)
Star Strider
Star Strider 2017 年 9 月 20 日
As always, my pleasure!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDescriptive Statistics についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by