find change points, point of inflection and concave up and concave down

12 ビュー (過去 30 日間)
Osita Onyejekwe
Osita Onyejekwe 2016 年 10 月 31 日
コメント済み: dpb 2016 年 10 月 31 日
This is my code and I want to find the change points of my sign curve, that is all and I want to put points on the graph where it is concave up and concave down. (2 different shapes for concave up and down would be preferred. I just have a simple sine curve with 3 periods and here is the code below. I have found the first and second derivatives. I'm not sure where to go from here. I know have to set it equal to zero and solve for x, any algorithmic help would be appreciated
x = 1:500;
X = x;
T = 1;
Fs = 499;
N = T*Fs;
t = 0: 1/Fs : T;
Fn = 3; % this control the number of cycles/periods
deltax = 0.0020;
y_sine_25HZ = sin(Fn*2*pi*t);
y = y_sine_25HZ ;
drvY = diff(y)/deltax; % one unit shorter than y
drvY = [drvY , drvY(end)]; % making up for the missing point
secondDrvY = diff(drvY)/deltax;

採用された回答

dpb
dpb 2016 年 10 月 31 日
If you have the Signal Processing Toolbox, the simplest solution is to use findpeaks --
>> [~,locup]=findpeaks(y) % (+)ive peaks
locup =
43 209 375
>> [~,locdn]=findpeaks(-y) % (-)ive peaks (positive negative y)
locdn =
126 292 458
>>
Lacking it, to find the nearest point is--
>> dy=[0 sign(diff(y))];
>> find((diff(dy))==2)
ans =
126 292 458
>> find((diff(dy))==-2)
ans =
43 209 375
>>
are same locations as findpeaks located.
To show 'em,
>> plot(t,y)
>> ylim([-1.05 1.05])
>> hold on
>> scatter(t(locup)',y(locup)',30,'r','*')
>> scatter(t(locdn)',y(locdn)',30,'g','d','filled')
>>
You can also knowing these locations use them and a range on either side with
>> interp1(y(locup-1:locup+1),t(locup-1:locup+1),1,'cubic')
ans =
0.0828
find an approximation for t to be slightly better resolution than perhaps the actual point given the resolution in t.
  2 件のコメント
dpb
dpb 2016 年 10 月 31 日
編集済み: dpb 2016 年 10 月 31 日
...[Osita Onyejekwe Answer moved to comment--dpb]...
thanks, where do i get the locup function?
dpb
dpb 2016 年 10 月 31 日
It's not a function; it's the optional second return from the findpeaks function giving the location of the found peaks, not the values (the first, default return value).

サインインしてコメントする。

その他の回答 (2 件)

Osita Onyejekwe
Osita Onyejekwe 2016 年 10 月 31 日
one more question, for the second derivative why did you do
==2
and
==-2
  1 件のコメント
dpb
dpb 2016 年 10 月 31 日
I'll leave that one as "exercise for the student", I think... :)
Look up the sign function and think about what happens when apply it to differences of a function changing slope.

サインインしてコメントする。


Osita Onyejekwe
Osita Onyejekwe 2016 年 10 月 31 日
and for the plot
ylim([-1.05 1.05])
why -1.05 and 1.05 thank you that is all my questions!! :)
  1 件のコメント
dpb
dpb 2016 年 10 月 31 日
Just so the maxima/minima will show up on the plot w/o being obscured by the outer box of the axes...

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeSmoothing and Denoising についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by