# How to find the median in a zero crossing?

조회 수: 1 (최근 30일)
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 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이전 댓글 4개 표시이전 댓글 4개 숨기기
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 2017년 9월 20일
As always, my pleasure!

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

### 카테고리

Help CenterFile Exchange에서 Descriptive Statistics에 대해 자세히 알아보기

### Community Treasure Hunt

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

Start Hunting!

Translated by