sliding window algorithm for time-series data
現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示
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 件のコメント
Sameer Sayyad
2021 年 5 月 20 日
@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
Mathieu NOE
2021 年 5 月 20 日
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
Mathieu NOE
2021 年 5 月 20 日
That looks nice , have you another question ?
Sameer Sayyad
2021 年 5 月 20 日
% 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

Sameer Sayyad
2021 年 5 月 20 日
Is it correct?
time_index(ci) = round((start_index+stop_index)/(2*buffer));
Mathieu NOE
2021 年 5 月 20 日
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
Sameer Sayyad
2021 年 5 月 20 日
Okay. Thank you so much sir.
Alyaa Ghazi
2024 年 4 月 20 日
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!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の 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)
