Find zero crossings in each row of a matrix (321 x 123 double)

3 vues (au cours des 30 derniers jours)
NotA_Programmer
NotA_Programmer le 9 Mai 2022
Commenté : Star Strider le 9 Mai 2022
How can I find the no. of times the signal crosses zero. Signal is in form of a matrix (321 x 123 double), where each row represents the data one signal.

Réponse acceptée

Star Strider
Star Strider le 9 Mai 2022
t = linspace(0, 5, 123); % Create Data
A = sin(randi(9,5,1)*2*pi*t/5 + 2*pi*randi(9,5,1)) % Sine Curves With Varying Phases
A = 5×123
-0.0000 0.1028 0.2046 0.3041 0.4005 0.4925 0.5794 0.6602 0.7339 0.7998 0.8573 0.9057 0.9445 0.9733 0.9917 0.9997 0.9970 0.9838 0.9601 0.9263 0.8827 0.8297 0.7679 0.6979 0.6206 0.5367 0.4471 0.3528 0.2547 0.1539 -0.0000 0.3041 0.5794 0.7998 0.9445 0.9997 0.9601 0.8297 0.6206 0.3528 0.0515 -0.2547 -0.5367 -0.7679 -0.9263 -0.9970 -0.9733 -0.8573 -0.6602 -0.4005 -0.1028 0.2046 0.4925 0.7339 0.9057 0.9917 0.9838 0.8827 0.6979 0.4471 -0.0000 0.3528 0.6602 0.8827 0.9917 0.9733 0.8297 0.5794 0.2547 -0.1028 -0.4471 -0.7339 -0.9263 -0.9997 -0.9445 -0.7679 -0.4925 -0.1539 0.2046 0.5367 0.7998 0.9601 0.9970 0.9057 0.6979 0.4005 0.0515 -0.3041 -0.6206 -0.8573 -0.0000 0.3041 0.5794 0.7998 0.9445 0.9997 0.9601 0.8297 0.6206 0.3528 0.0515 -0.2547 -0.5367 -0.7679 -0.9263 -0.9970 -0.9733 -0.8573 -0.6602 -0.4005 -0.1028 0.2046 0.4925 0.7339 0.9057 0.9917 0.9838 0.8827 0.6979 0.4471 -0.0000 0.3041 0.5794 0.7998 0.9445 0.9997 0.9601 0.8297 0.6206 0.3528 0.0515 -0.2547 -0.5367 -0.7679 -0.9263 -0.9970 -0.9733 -0.8573 -0.6602 -0.4005 -0.1028 0.2046 0.4925 0.7339 0.9057 0.9917 0.9838 0.8827 0.6979 0.4471
for k = 1:size(A,1)
zc{k} = find(diff(sign(A(k,:)),[],2)); % Zero-Crossings For Row 'k'
end
figure
plot(t,A(1,:))
hold on
plot(t(zc{1}), zeros(size(zc{1})),'+r')
hold off
grid
figure
plot(t,A(5,:))
hold on
plot(t(zc{5}), zeros(size(zc{5})),'+r')
hold off
grid
Use interp1 in a loop for each zero crossing in each row to find the exact ‘x’ values for each zero-crossing.
.
  2 commentaires
NotA_Programmer
NotA_Programmer le 9 Mai 2022
Yeah, this worked.
Thanks a lot!!
Star Strider
Star Strider le 9 Mai 2022
As always, my pleasure!

Connectez-vous pour commenter.

Plus de réponses (1)

Torsten
Torsten le 9 Mai 2022
  1 commentaire
NotA_Programmer
NotA_Programmer le 9 Mai 2022
Torsten, thanks for your response, but I want a seperate matrix that contains locations or indices where signal crosses 0.
The sinal is of (321 x 123 double) matrix and I want a matrix of (321 x location_where_signal_crosses_zero) but while using the below code I am getting zm of different dimension
t = [0:0.048780:6];
y = Data; %Data (321 x 123 double)
zci = @(v) find(v(:).*circshift(v(:), [-1 0]) <= 0);
zx = zci(y);

Connectez-vous pour commenter.

Catégories

En savoir plus sur Shifting and Sorting Matrices dans Help Center et File Exchange

Produits


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by