Calculating time duration of a signal

조회 수: 9 (최근 30일)
Tom richards
Tom richards 2019년 7월 14일
편집: Tom richards 2019년 7월 18일
I would like to calculate the time duration of a signal. In the example below, I want to write in a 2 column matrix the signal and the duration for the purposes for plotting a histogram.
signal=[0 0 0 1 1 1 1 0 1 1];
Output I'd like to see:
signal duration(ns)
0 3
1 4
0 1
1 2
This is my code so far, I'm stuck at trying to calculate the actual duration. I dont know how to calculate time in between when 0 transitions to 1 and vice versa.
duration=[];
signal=[0 0 0 1 1 1 1 0 1 1];
for c=1:length(signal)
diff=signal(c+1)-signal(c);
if diff~=0
????
end
end
  댓글 수: 1
dpb
dpb 2019년 7월 14일
Look for FileExchange (FEX) submittal "runs"...

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

채택된 답변

infinity
infinity 2019년 7월 14일
Hello,
You also could refer this code to get the output
clear
signal=[0 0 0 1 1 1 1 0 1 1];
n = length(signal);
a = diff(signal);
b = find(a);
output = [signal(b) signal(end); diff([0 b n])]'
  댓글 수: 1
Tom richards
Tom richards 2019년 7월 14일
편집: Tom richards 2019년 7월 18일
Hi,
Your code definitely worked on a large data file as well.
Thanks very much!

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

추가 답변 (0개)

카테고리

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

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by