How to select the maximum points of the absolute values of a sin function

2 ビュー (過去 30 日間)
Mauricio Galván García Luna
Mauricio Galván García Luna 2017 年 8 月 17 日
編集済み: Adam 2017 年 8 月 17 日
I would like to get all the maximum values of x in another matrix any idea? Sorry I am new
fs = 500;
t = 0:1/fs:10-1/fs;
x = abs(sin(2*pi*3*t));
  1 件のコメント
Adam
Adam 2017 年 8 月 17 日
編集済み: Adam 2017 年 8 月 17 日
Due to discretisation and the imperfect reproduction of the sine wave you will only pick up certain peaks as being the maximum.
find( x == 1 )
will give the indices of these locations, but when I run it this gives me only every 3rd peak. If you want the actual peak locations of the continuous curve surely that is just trivial maths?
peakLocs = 1/12 : 1/6 : ( 10 - 1/fs );

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

採用された回答

Torsten
Torsten 2017 年 8 月 17 日
https://de.mathworks.com/help/signal/ref/findpeaks.html
Best wishes
Torsten.
  2 件のコメント
Mauricio Galván García Luna
Mauricio Galván García Luna 2017 年 8 月 17 日
thank you so much!!
But once I get the maximum points is there a way to put them back in the time that they belong.
Torsten
Torsten 2017 年 8 月 17 日
編集済み: Torsten 2017 年 8 月 17 日
[xp,locs] = findpeaks(x);
for i=1:numel(xp)
tp(i)=t(locs(i));
end
Best wishes
Torsten.

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

その他の回答 (1 件)

Selva Karna
Selva Karna 2017 年 8 月 17 日
fs = 500;
t = 0:1/fs:10-1/fs;
x = abs(sin(2*pi*3*t));
p=find(x==1)
  1 件のコメント
Stephen23
Stephen23 2017 年 8 月 17 日
編集済み: Stephen23 2017 年 8 月 17 日
This answer is very fragile, and does not handle floating-point errors at all. This is not a general solution for this task (try changing fs to 499 and see what happens).
Read these to know why testing for equality of floating-point values is a bad way to write code:
and a hundred other discussion of this topic.

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

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by