how to generate overlapping series

2 views (last 30 days)
Ali Asghar
Ali Asghar on 1 Feb 2020
Commented: Ali Asghar on 4 Feb 2020
Dear
data of 30000x1.
want to make first packet of 2000 values
but in 2nd packet last 500 values from packet 1 repeat, means 2nd packet value start from 1500 and end at 3500.
3rd packet start at 3000 and end at 5000
till end of 30000.
How can i do it?

Answers (1)

Ioannis Andreou
Ioannis Andreou on 1 Feb 2020
Try this
packages = nan(19, 2000);
for i = 1:19
packages(i,:) = data((i-1)*1500+1: i*1500+500);
end
However there will be a few data left, less than 2000 though, so you cant fill a new package with them
  1 Comment
Ali Asghar
Ali Asghar on 4 Feb 2020
Dear
I have two codes for overlapping windows, once yours and second code from other.
I run two codes on data and check result.
both code give right answer for 1st window only but give different answer for 2nd etc wondows which start from 1500 and end at 1500.
2 CODE
function segments_cell = overlap_window_segmentation(signal,windowSize,overlap,fs,rowNumber,filteredOrRaw)
%filteredOrRaw must be 1 for raw data and must be other numbers for filtered data.
colors=['r','g'];
%L=length(signal);
sz=size(signal);
if(sz(2)==1)
signal=signal';
end
sz=size(signal);
numberOfSegmentsEachRow=floor(sz(2)/(windowSize-overlap));
remaindar = mod(sz(2),(windowSize-overlap));
if remaindar < overlap
numberOfSegmentsEachRow=numberOfSegmentsEachRow-1;
end
save('numberOfSegmentsEachRow.mat','numberOfSegmentsEachRow');
total_number_of_segments=numberOfSegmentsEachRow*sz(1);
%segments = NET.createArray('System.Double[]',total_number_of_segments);
segments = zeros(total_number_of_segments,windowSize);
maxSignal= max(signal(rowNumber,:));
t=(1:length(signal(rowNumber,:)))/fs;
figure
plot(t,signal(rowNumber,:));hold on,
i=0;
j=1;
hight=[maxSignal 0.8*maxSignal];
for k=1:sz(1)
start=1;
L=length(signal(k,:));
while(start+windowSize-1 <= L && j <= total_number_of_segments)
%segments(j)=signal(k,start:start+windowSize-1);
segments(j,:)=signal(k,start:start+windowSize-1);
if(k==1)
plot([start start]/fs ,[hight(i+1) -0.5*maxSignal],colors(i+1));hold on,
plot([start+windowSize-1 start+windowSize-1]/fs ,[hight(i+1) -0.5*maxSignal],colors(i+1));hold on,
plot([start start+windowSize-1]/fs, [hight(i+1) hight(i+1)],colors(i+1));
end
start=start+windowSize-1-overlap;
i=~i;
j=j+1;
end
end
if(filteredOrRaw==1)
title('Overlap window segmentation for raw data');
else
title('Overlap window segmentation for filtered data');
end
xlabel('Time (s)');
ylabel('Amplituse');
%segments_cell=cell(segments);
segments_cell=segments;

Sign in to comment.

Categories

Find more on Programming in Help Center and File Exchange

Tags

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!