My cos function appears as a straight line instead of as a wave

13 ビュー (過去 30 日間)
Serena Simpson
Serena Simpson 2020 年 9 月 18 日
コメント済み: Serena Simpson 2020 年 9 月 19 日
%Defining given varibles
t = 0 :.1 :3;
f1 = 130;
f2 = 120;
y1 = cosd(2*pi*f1*t);
y2 = cosd(2*pi*f2*t);
%% Section 2: Processing
%equation given
y = 2 .* cos(2.*pi.*(f1+f2./2).*t) .* cos(2.*pi.*(f1-f2./2).*t); %This is my function for the sound waves, however, it appears as a stright line
  2 件のコメント
Walter Roberson
Walter Roberson 2020 年 9 月 19 日
Do you want f1 + (f2/2) or do you want (f1+f2)/2 ? If you are looking for beat frequencies then you want (f1+f2)/2 and (f1-f2)/2
Serena Simpson
Serena Simpson 2020 年 9 月 19 日
Making the increments smaller worked! Thanks for looking at my code!

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

採用された回答

David Hill
David Hill 2020 年 9 月 19 日
f1 = 130;
f2 = 120;
t=0:.001:3;%need smaller incrementing
y = 2*cos(2*pi*(f1+f2/2)*t).*cos(2*pi*(f1-f2/2)*t);
plot(t,y);
  2 件のコメント
Walter Roberson
Walter Roberson 2020 年 9 月 19 日
Yes, smaller increments are important too. With 1/10 or 2/10 increment and frequencies that end in 10s, the result of the multiplication was always an integer multiple of 2*pi, and so you were not sampling at different points on the wave.
Serena Simpson
Serena Simpson 2020 年 9 月 19 日
Thank you so much! It worked. My grade is saved <3

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeAudio I/O and Waveform Generation についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by