2017-05-01 6 views
1

Sharkfin信号が下降するポイントと上がったポイントで滑らかにしたい。以下の図に示すように、Sharkfin波形は、時間2秒、4秒での急落と立ち上がりを有する:Matlabの関数で1つのシャープコーナーを滑らかにする

As shown in the figure below, the Sharkfin waveform has sharp fall and rise at time 1 sec and 2 seconds

そうそのセクションに滑らかになるようにその領域ラウンド方法の任意のアイデアをそれは次のようになりますこと:

Smooth corner

+0

ですから、シャープを検出するアルゴリズムを探しています信号のコーナーを切り取り、それらを丸めます。あなたは1つを見つけましたか? – Anthony

+0

['convex'](https://en.wikipedia.org/wiki/Convex_function)の使い方はおそらく間違っていることに注意してください。コーナーを滑らかにしても、より凸にならないでしょう。 – m7913d

+0

アルゴリズム以上のステップがあれば十分です。急な上昇と下降の周りの移動平均フィルタが機能するかもしれないという考えがあります。しかし、私はここからいくつかの助けを求めていた。または、カーブの小さな部分にのみフィルタを実装するのに役立ちます。 –

答えて

1

あり、ここで二つの別々のものです - あなたは鋭い遷移を検出しますどのように、どのようにあなたがそれをフィルタリングします。

これを順番にお試しください。

急な遷移は大きな曲率によって特徴付けられます。入力曲線のdiffを使用すると、これを簡単に検出できます。 2番目のパラメータ= 2を使用すると、diffが2回使用され、2次導関数のようなものが得られますが、1だけオフセットされます。したがって、diff(sharkfin,2)が大きいポイントを見つけるときは、コーナーポイントを得るために1をオフセットする必要があります。

次に、平滑化そのもの。多くのテクニックがあります - ボックス関数を使った簡単な畳み込みを示します。これを2回実行すると、入力の平滑化されたバージョンが得られます。元の「不連続から遠い」オリジナルと、「不連続に近い」フィルタリングされたバージョンを選択することにより、あなたが求めていたものを正確に得ることができます。必要に応じて、ポイントを "ブレンド"することができます - コーナーポイントにどれくらい近づいているかによって、フィルタリングされたフィルタリングされていないバージョンの重み付きバージョンを使用します。私は明示的にそれを示さなかったが、私はすでに書いたコードを拡張する方法を見やすいようになります。

% generate a "shark fin" function: 
fin = exp(-linspace(0,4,60)); 
shark = [fin (1-fin+fin(end))]; 
shark = repmat(shark, [1 3]); 
D2 = diff(shark, 2); 
roundMe = find(abs(D2)>0.1*max(D2))+1; % offset by 1 because second derivative 

figure; 
subplot(3,1,1) 
plot(shark); title 'shark plot' 
hold on; 
plot(roundMe, shark(roundMe),'r*') 
legend('input','corners found') 

% take N points on either side of the sharp corners: 
N = 3; 

% boxplot filtered version of the curve 
boxFilt = ones(1, 2*N+1)/(2*N+1); 
smoothShark1 = convn(shark, boxFilt, 'same'); % box plot 

% second filter - smoother 
smoothShark2 = convn(smoothShark1, boxFilt, 'same'); 


% plot the filtered results: 
subplot(3,1,2) 
plot(shark) 
hold on 
plot(smoothShark1); 
hold on 
plot(smoothShark2); 
xlim([114 126]) 
ylim([0.8,1.1]) 
legend('original','box','box x2') 
title 'smoothed everywhere' 

% Now apply filtering only to points near the discontinuity 
smoothMe = zeros(size(shark)); 
smoothMe(roundMe)=1; 
smoothMe = convn(smoothMe, boxFilt, 'same'); 
smoothMe(smoothMe>0)=1; % this finds N points on either side of the corner 

subplot(3,1,3) 
plot(shark) 
finalPlot=shark; 
hold on 
smoothIndx = find(smoothMe); 
finalPlot(smoothIndx)=smoothShark2(smoothIndx); 
plot(finalPlot,'g') 
plot(smoothIndx, finalPlot(smoothIndx), 'r*') 
xlim([114 126]) 
ylim([0.8,1.1]) 
legend('original','smoothed','changed') 
title 'smoothed only near discontinuity' 

は出力:

enter image description here

+0

この回答に感謝します。それに応じて修正して使用しました。本当にうまく動作します:) –

関連する問題