필터 지우기
필터 지우기

Segment data into overlapping windows

조회 수: 7 (최근 30일)
Panos Kerezoudis
Panos Kerezoudis 2023년 12월 19일
댓글: William Rose 2023년 12월 20일
Hi!
I have a vector of time series data (1x300), that I would like to segment into 20 segments that are 100 ms in duration and have 90% overlap. I tried the buffer function, but the indices in the first segments start with zeros, which is not desirable. I would like the first epoch to start from the first time point and go from there. Here is a screenshot from the figure in the paper where the authors applied the method (Foster, Neuron, 2015). thank you in advance!

채택된 답변

William Rose
William Rose 2023년 12월 19일
@Panos Kerezoudis, you did not specify the sampling rate. You said you have time series data (1x300).
I assume 300 is the number of points.
You said you want 20 segments that are 100 ms long with 90% overlap. This means the segments overlap by 90 ms. This means you can fit 21 segments onto 300 ms of data.
Let us assume the sampling rate is 1 kHz.
%% Generate simulated data
fs=1000; % sampling rate (Hz
N=300; % signal length (points)
t=(0:N-1)/fs; % time vector (s)
y=cos(2*pi*20*t); % 20 Hz sinusoidal signal, for demonstration purposes
%% Prepare to segment the data
tseg=0.100; % segment duration (s)
nseg=tseg*fs; % segment length (points)
noverlap=0.9*nseg; %overlap (point)
noffset=nseg-noverlap; % offset (points)
K=floor(1+(N-nseg)/noffset); % number of segments
fprintf('N=%d, nseg=%d, noffset=%d, number of segments=%d.\n',N,nseg,noffset,K)
N=300, nseg=100, noffset=10, number of segments=21.
yseg=zeros(K,nseg); % allocate arrays for time and y for each segment
tseg=zeros(K,nseg);
%% Segment the data
for i=1:K
tseg(i,:)=t(1+(i-1)*noffset:(i-1)*noffset+nseg);
yseg(i,:)=y(1+(i-1)*noffset:(i-1)*noffset+nseg);
end
%% Plot all segments, with vertical offsets
figure;
for i=1:K
plot(tseg(i,:),yseg(i,:)+(i-1)/5,'-r')
hold on
end
grid on; xlabel('Time (s)')
Looks decent.
Good luck with your research.
  댓글 수: 3
Panos Kerezoudis
Panos Kerezoudis 2023년 12월 19일
awesome thank you so much for all your help! Will let you know if I run into any issues.
Panos
William Rose
William Rose 2023년 12월 20일
@Panos Kerezoudis, you're welcome, good luck.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Time Series Events에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by