Segment data into overlapping windows

7 visualizzazioni (ultimi 30 giorni)
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!

Risposta accettata

William Rose
William Rose il 19 Dic 2023
@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 Commenti
Panos Kerezoudis
Panos Kerezoudis il 19 Dic 2023
awesome thank you so much for all your help! Will let you know if I run into any issues.
Panos
William Rose
William Rose il 20 Dic 2023
@Panos Kerezoudis, you're welcome, good luck.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Time Series Events in Help Center e File Exchange

Prodotti


Release

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by