Identify Zerocrossing Indices near to the peak of the other signal matlab

4 ビュー (過去 30 日間)
Ganesh Naik
Ganesh Naik 2022 年 5 月 27 日
コメント済み: Star Strider 2022 年 5 月 28 日
Hi all, I have two signals (data attached) , for first signal I plot the peaks of the signal and for the second one I find zero crossings of the signal. My aim is to find the zero crossing indices (start and stop) closer to the peak of the first signal. In this example (please refer to the figure), peak for the first signal is around 4.567 and the zerocrossings (closest ones) are closer to 4.564 and 4.571 respectively. I would like to get these indices (start and stop) for the signal with all the peak points. For your reference, I have added data, code for peak and zerocrossing and also figure.
https://www.dropbox.com/s/i8s52no5ivdo6gm/data.mat?dl=0
Any help in this regard is highly appreciated.
load Data.mat;
t=1:length(Data(:,1));
[pk,lk] = findpeaks(Data(:,1),t,'MinPeakProminence',200);
ax1=subplot(211);
plot(t,Data(:,1),lk,pk,'o')
y = Data(:,2);
zci = @(v) find(v(:).*circshift(v(:), [-1 0]) <= 0);
zx = zci(y); % Approximate Zero-Crossing Indices
figure(1);
ax2=subplot(212)
plot(t, y, '-r')
hold on
plot(t(zx), y(zx), 'bp'); hold on;
% plot(t,Pepi);
hold off
grid
legend('Signal', 'Approximate Zero-Crossings')
linkaxes([ax1 ax2],'x')

採用された回答

Star Strider
Star Strider 2022 年 5 月 27 日
The file is too large to download here, and the online Run feature still has problems with .mat files.
That aside, finding the zero-crossings (using simulated data) is straightforward
t = linspace(0, 10, 500);
s = sum((1:10)'.*(sin((1:10)'*pi*t)));
zxi = find(diff(sign(s))); % Approximate Zero-Crossing Indices
for k = 1:numel(zxi)
idxrng = max(1,zxi(k)-2) : min(numel(s),zxi(k)+2);
t_exact(k) = interp1(s(idxrng), t(idxrng), 0);
end
t_exact
t_exact = 1×100
0 0.1367 0.2346 0.3311 0.4270 0.5226 0.6180 0.7136 0.8092 0.9047 0.9999 1.0953 1.1909 1.2865 1.3819 1.4773 1.5730 1.6691 1.7656 1.8637 1.9999 2.1370 2.2348 2.3312 2.4269 2.5224 2.6181 2.7137 2.8092 2.9045
figure
plot(t, s)
hold on
plot(t(zxi), s(zxi), 'xg')
plot(t_exact, zeros(size(t_exact)), '+r')
hold off
grid
legend('Signal','Approximate Zero-Crossing Indices','Interpolated Exact Zero-Crossings', 'Location','best')
figure
plot(t, s)
hold on
plot(t(zxi), s(zxi), 'sg', 'MarkerSize',10)
plot(t_exact, zeros(size(t_exact)), 'xr', 'MarkerSize',10)
hold off
grid
legend('Signal','Approximate Zero-Crossing Indices','Interpolated Exact Zero-Crossings', 'Location','best')
xlim([3 5])
I changed the zero-crossing index code from my previous posts. The one I use here is more robust and does not encounter the ‘wrap-around’ problems of my original version.
.
  4 件のコメント
Ganesh Naik
Ganesh Naik 2022 年 5 月 28 日
編集済み: Ganesh Naik 2022 年 5 月 28 日
Dear Star Strider you are the legend. Now I have managed to get the start and stop of corresponding second signal for every peak location of the first signal. I have tested this for a large data with 12 peak locations. Now i will work on it to shade/patch start stop locations.
Index = fliplr(te) % Get the start stop indexes
Start_Stop = t_exact(Index)
Thanks again for your help, much appreciated.
Star Strider
Star Strider 2022 年 5 月 28 日
As always, my pleasure!

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

その他の回答 (1 件)

KSSV
KSSV 2022 年 5 月 27 日
Multiple options:
  1. Use knnsearch
  2. Use interp1
  3. Use InterX: https://in.mathworks.com/matlabcentral/fileexchange/22441-curve-intersections
I would suggest to use third option.
  1 件のコメント
Ganesh Naik
Ganesh Naik 2022 年 5 月 27 日
Hi KSSV thanks for your answer. I have two separate signals. Signal 1 generates peak points and signal 2 is a noisy signal and from it I get several zero crossing points. My aim is to pick up two closest zero crossing points from signal 2 for every peak of signal 1. Unfortunately signal 1 and signal 2 dont intersects and hence I cant use the third option that you suggested.

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

カテゴリ

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

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by