Effacer les filtres
Effacer les filtres

Segment data into overlapping windows

7 vues (au cours des 30 derniers jours)
Panos Kerezoudis
Panos Kerezoudis le 19 Déc 2023
Commenté : William Rose le 20 Déc 2023
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!

Réponse acceptée

William Rose
William Rose le 19 Déc 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 commentaires
Panos Kerezoudis
Panos Kerezoudis le 19 Déc 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 le 20 Déc 2023
@Panos Kerezoudis, you're welcome, good luck.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Time Series Events dans Help Center et File Exchange

Produits


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by