Identify Zerocrossing Indices near to the peak of the other signal matlab
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Ganesh Naik
el 27 de Mayo de 2022
Comentada: Star Strider
el 28 de Mayo de 2022
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')
0 comentarios
Respuesta aceptada
Star Strider
el 27 de Mayo de 2022
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
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 comentarios
Más respuestas (1)
KSSV
el 27 de Mayo de 2022
Multiple options:
- Use knnsearch
- Use interp1
- Use InterX: https://in.mathworks.com/matlabcentral/fileexchange/22441-curve-intersections
I would suggest to use third option.
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!