sliding window algorithm for time-series data
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
I have sample data and sampling frequency . Sample data points are 27900 and sampling frequency is 600 hz . I want to apply slidding window concept for my data. I want divide all data into set of 5 sec each with overlap of 4 sec. (i.e. 0-5, 1-6, 2-7, etc.). Please help me to apply slidding window concept.
채택된 답변
Mathieu NOE
2021년 5월 20일
HELLO
see demo below - second section implement a overlap method
all the best
clc
clearvars
% dummy data
data = rand(320,3); % data must be column oriented (number of rows = number of samples)
buffer = 25; % nb of samples for averaging
%% zero overlap averaging (unweighted)
[m,n] = size(data);
for ci=1:fix(m/buffer)
start_index = 1+(ci-1)*buffer;
stop_index = min(start_index+ buffer-1,m);
time_index(ci) = round((start_index+stop_index)/2); % time index expressed as sample unit (dt = 1 in this simulation)
avg_data(ci,:) =mean(data(start_index:stop_index,:)); %
end
figure(1),
plot(time_index,avg_data,'+-');
% return
%% averaging with overlap
clearvars
% dummy data
data = rand(320,3);
buffer = 25; % nb of samples in one buffer (buffer size)
overlap = 10; % overlap expressed in samples
%%%% main loop %%%%
[m,n] = size(data);
shift = buffer-overlap; % nb of samples between 2 contiguous buffers
for ci=1:fix((m-buffer)/shift +1)
start_index = 1+(ci-1)*shift;
stop_index = min(start_index+ buffer-1,m);
time_index(ci) = round((start_index+stop_index)/2); % time index expressed as sample unit (dt = 1 in this simulation)
avg_data(ci,:) = mean(data(start_index:stop_index,:)); %
end
figure(2),
plot(time_index,avg_data,'+-');
댓글 수: 8
@Mathieu NOE Thanks sir. Can you please explain me (time_index(ci)) code line. Because I have frequency and number of samples from which I can create time step coloun. So can I use that Time step coloum in this code.
Thank you
hello Sameer
you are speaking about the time vector which is associated with your raw data (sampled at 600 Hz)
when I do buffer averaging , the output data have a different time spacing (increment) which depends on the buffer and overlap :
in my code, each buffer of data is associated with the time index around the middle of the buffer (for example , if my buffer has 11 samples , then I associate this buffer with the 6th sample (center position of the buffer) , then I do the buffer averaging and this value is associated with the 6th sample time index
hope this answer your question
That looks nice , have you another question ?
% clear window
clc;
clear all;
% % import xls or csv file
axial_Depth_1 = xlsread('E:\SIT\Datasets\TOOL WEAR DATASET OF NUAA_IDEAHOUSE\+-¦½-²+¦\Data collection of variable cutting parameters\Variable axial cutting depth\1');
%fz: feed per tooth= 0.03 ; n: spindle speed= 1200; ap: axial cutting depth=1; ae: radial cutting depth=3.0
%extract data in respective sensors sensors
Axial_cutting_force= axial_Depth_1 (:,1:1);
[m,n] = size(Axial_cutting_force);
buffer = 600;
for ci=1:fix(m/buffer)
start_index = 1+(ci-1)*buffer;
stop_index = min(start_index+ buffer-1,m);
time_index(ci) = round((start_index+stop_index)/(2*buffer)); % time index expressed as sample unit
% 1. mean (Average)
Mean_Axial_cutting_force(ci,:) = mean(Axial_cutting_force(start_index:stop_index,:)); %
% 2. rms (Root mean square), Value that generally tends to get bigger as the degree of fault increases
RMS_Axial_cutting_force(ci,:) = rms(Axial_cutting_force(start_index:stop_index,:));
% 3. std(x)(Standard Deviation)
std_Axial_cutting_force(ci,:) = std(Axial_cutting_force(start_index:stop_index,:));
%4. Peak (Maximum value of signal absolute value)
Peak_Axial_cutting_force(ci,:) = max(Axial_cutting_force(start_index:stop_index,:));
%5. Skewness (The asymmetry of the probability density function of the signal)
Skewness_Axial_cutting_force(ci,:) = skewness(Axial_cutting_force(start_index:stop_index,:));
%6. Kurtosis (The sharpness of the probability distribution of the signal)
kurtosis_Axial_cutting_force(ci,:) = kurtosis(Axial_cutting_force(start_index:stop_index,:));
%7. Crest factor (The ratio of peak values to the RMS of a signal)
CF_Axial_cutting_force(ci,:) = Peak_Axial_cutting_force(ci,:)/RMS_Axial_cutting_force(ci,:);
%8. Clearance factor (Peak value divided by the square of root mean)
CL_Axial_cutting_force(ci,:)= (Peak_Axial_cutting_force(ci,:)/(RMS_Axial_cutting_force(ci,:))^2);
%9.Shape factor (RMS divided by mean)
SF_Axial_cutting_force(ci,:) = (RMS_Axial_cutting_force(ci,:)/ Peak_Axial_cutting_force(ci,:));
%10. Impulse factor (The ratio of peak values to the mean of a signal)
IF_Axial_cutting_force(ci,:)= (Peak_Axial_cutting_force(ci,:)/ Mean_Axial_cutting_force(ci,:));
%11. Peak to peak (The difference between maximum and minimum values of the signal)
Max_Axial_cutting_force (ci,:)= max(Axial_cutting_force(start_index:stop_index,:));
Min_Axial_cutting_force (ci,:)= min(Axial_cutting_force(start_index:stop_index,:));
P2P_Axial_cutting_force(ci,:)= (Max_Axial_cutting_force (ci,:)- Min_Axial_cutting_force (ci,:));
end
figure(1),
subplot (3,4,1)
plot(time_index,Mean_Axial_cutting_force,'+-', 'color','r');
title('Mean Axial Cutting Force'); grid on
xlabel('Time (Sec)')
ylabel('Mean Axial force in N')
subplot (3,4,2)
plot(time_index,RMS_Axial_cutting_force,'+-','color','b');
title('RMS Axial cutting force'); grid on
xlabel('Time(Sec)')
ylabel('RMS Axial cutting force in N')
subplot (3,4,3)
plot(time_index,std_Axial_cutting_force,'+-','color','g');
title('Std. Dev. Axial cutting force'); grid on
xlabel('Time(Sec)')
ylabel('std axial cutting force in N')
subplot (3,4,4)
plot(time_index,Peak_Axial_cutting_force,'+-','color','m');
title('Peak Axial cutting force'); grid on
xlabel('Time(Sec)')
ylabel('Peak Axial cutting force in N')
subplot (3,4,5)
plot(time_index,Skewness_Axial_cutting_force,'+-','color','r');
title('Skewness Axial cutting force'); grid on
xlabel('Time(Sec)')
ylabel('Skewness Axial cutting force in N')
subplot (3,4,6)
plot(time_index,kurtosis_Axial_cutting_force,'+-','color','b');
title('kurtosis Axial cutting force'); grid on
xlabel('Time(Sec)')
ylabel('kurtosis Axial cutting force in N')
subplot (3,4,7)
plot(time_index,CF_Axial_cutting_force,'+-','color','g');
title('Crest factor of Axial cutting force'); grid on
xlabel('Time(Sec)')
ylabel('CF of Axial cutting force in N')
subplot (3,4,8)
plot(time_index,CL_Axial_cutting_force,'+-','color','m');
title('Clearance factor of Axial cutting force'); grid on
xlabel('Time(Sec)')
ylabel('CL of Axial cutting force in N')
subplot (3,4,9)
plot(time_index,SF_Axial_cutting_force,'+-','color','r');
title('Shape factor of Axial cutting force'); grid on
xlabel('Time(Sec)')
ylabel('SF of Axial cutting force in N')
subplot (3,4,10)
plot(time_index,IF_Axial_cutting_force,'+-','color','b');
title('Impulse factor of Axial cutting force'); grid on
xlabel('Time(Sec)')
ylabel('IF of Axial cutting force in N')
subplot (3,4,11)
plot(time_index,P2P_Axial_cutting_force,'+-','color','g');
title('Peak to Peak value of Axial cutting force'); grid on
xlabel('Time(Sec)')
ylabel('P2P of Axial cutting force in N')
% return

Is it correct?
time_index(ci) = round((start_index+stop_index)/(2*buffer));
yes
maybe I should emphasize that this is an index , means it about samples , not time is seconds
if you want to have it in seconds divide time_index by your sampling rate
Okay. Thank you so much sir.
This was very helpfull to me also. Thanks alot.
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Scopes and Data Logging에 대해 자세히 알아보기
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
