データの異常検出

8 views (last 30 days)
Mamoru Mabuchi
Mamoru Mabuchi on 23 Jul 2020
Answered: Kenta on 23 Jul 2020
下記のようなサイン波に近い時系列の計測データがあるとします。
そして、あるタイミングから、振幅、周波数、位相が異なる信号が計測されるとします。
計測データから、状態が変化するタイミングを検出したいです。
どのようにするのが、最適でしょうか?
x1=0.05:0.05:5;
x2=5.05:0.05:10;
y1 = sin(5*x1);
y2 = 0.9*sin(4*x2-0.5*pi);
y1_data = y1 + 0.1*(rand(1,100)-0.5);
y2_data = y2 + 0.1*(rand(1,100)-0.5);
x = [x1,x2];
y = [y1,y2];
y_data = [y1_data,y2_data]; % 計測データ
plot(x,y,'-',x,y_data,'.')

Answers (1)

Kenta
Kenta on 23 Jul 2020
こんにちは、単に振幅が変わるのであれば、下のようにfindpeak関数で、ピークを検出し、そのピークの高さが前の変化があるかどうかを検証すれば、検出をすることができます。ただ、実際の問題はもっと複雑だと思うので、このような方法をもとに、ご自身の問題の条件を加味しながらブラッシュアップしていくとよいと思います。
波の異常検知の方法自体はたくさんあるので、それらの方法とご自身の問題設定を比べながら適切な方法をしぼっていけばいかがでしょうか。
x1=0.05:0.05:5;
x2=5.05:0.05:10;
y1 = sin(5*x1);
y2 = 0.9*sin(4*x2-0.5*pi);
y1_data = y1 + 0.1*(rand(1,100)-0.5);
y2_data = y2 + 0.1*(rand(1,100)-0.5);
x = [x1,x2];
y = [y1,y2];
y_data = [y1_data,y2_data]; % 計測データ
figure;subplot(1,2,1)
plot(x,y,'-',x,y_data,'.')
% change detection
window = 3; % window size for smoothing
% take moving mean for smoothing
Amean = movmean(y,window);
subplot(1,2,2)
plot(x,Amean)
[pks,locs] = findpeaks(Amean,x);
findpeaks(Amean,x)
text(locs+.02,pks,num2str((1:numel(pks))'));hold on
aveamp=pks(1);
for i=2:numel(pks)
if abs(pks(i)-aveamp)/aveamp*100>5
break
end
end
subplot(1,2,2)
scatter(locs(i),pks(i),30,'filled')

Products

Community Treasure Hunt

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

Start Hunting!