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

조회 수: 1 (최근 30일)
NotA_Programmer
NotA_Programmer 2022년 5월 9일
댓글: Star Strider 2022년 5월 9일
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.

채택된 답변

Star Strider
Star Strider 2022년 5월 9일
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.
.

추가 답변 (1개)

Torsten
Torsten 2022년 5월 9일
  댓글 수: 1
NotA_Programmer
NotA_Programmer 2022년 5월 9일
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);

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

카테고리

Help CenterFile Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by