フィルターのクリア

How to get a period of cosinus function ?

3 ビュー (過去 30 日間)
Ilan Moshe
Ilan Moshe 2020 年 5 月 25 日
コメント済み: Ilan Moshe 2020 年 5 月 27 日
Hi,
I have to find the period of the cosinus function using only the vector time and the vector data of the function.
Cosinus function
Vector data
time data
  2 件のコメント
Rik
Rik 2020 年 5 月 25 日
This looks like the sum of two cosines, not just one. Do you want the cosine with the largest magnitude? Are you allowed to use a Fourrier transform?
Ilan Moshe
Ilan Moshe 2020 年 5 月 25 日
Yes, it is actually a sum of cosines by using this code :
function [t,x]=getSumOfCosines(delta_t,Tlim,f)
t=0:delta_t:Tlim;
x=sum(cos(2*pi*t.*f));
end
The only restriction is to not use any loop and to use only x and t vectors.

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

採用された回答

Rik
Rik 2020 年 5 月 25 日
編集済み: Rik 2020 年 5 月 25 日
Because this is homework, I won't provide a copy-paste ready solution.
If you follow the example from the documentation for fft, you get the code below.
%recreate data
delta_t=0.1;Tlim=5;f=[1;2];
t=0:delta_t:Tlim;
x=sum(cos(2*pi*t.*f));
%figure(1),clf(1)
%plot(t,x)
Fs=1/mean(diff(t));%sampling frequency
L=numel(x);
Y = fft(x);
P2 = abs(Y/L);
P1 = P2(1:floor(L/2)+1);
f = Fs*(0:(L/2))/L;
figure(1),clf(1)
plot(f,P1,'-*')
title('Fourrier transform'),xlabel('frequency'),ylabel('magnitude')
Now you can clearly see there are two frequencies that have a high magnitude.
  3 件のコメント
Rik
Rik 2020 年 5 月 25 日
Frequency is the inverse of period.
Ilan Moshe
Ilan Moshe 2020 年 5 月 27 日
Thanks :)

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDiscrete Fourier and Cosine Transforms についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by