displaying a sinusoidal wave

9 ビュー (過去 30 日間)
JJ polaris
JJ polaris 2012 年 9 月 9 日
This is for one assignment. The question is the following. Generate a time vector (tt) to cover a range of t that will exhibit approximately two cycles of the 4000 Hz sinusoids defined in the next part, part (b). Use a definition for tt similar to part 2.2(d). If we use T to denote the period of the sinusoids, define the starting time of the vector tt to be equal to −T, and the ending time as +T. Then the two cycles will include t = 0. Finally, make sure that you have at least 25 samples per period of the sinusoidal wave. In other words, when you use the colon operator to define the time vector, make the increment small enough to generate 25 samples per period.
This is my code.
if true
% code
tt = -1 : 1/4000 : 1;
y = sin( 2*pi*tt );
plot(4000*tt, y);
%<--- plot a sinusoid
title('TEST PLOT of a SINUSOID')
xlabel('frequency')
end
My problem is that I don't fully understand what a sample is so I can answer the last part. I know 1/4000 would be the sample frequency, unless I'm wrong. Can anybody explain what exactly is a sample in matlab?
I'm new to this forum.

採用された回答

JJ polaris
JJ polaris 2012 年 9 月 9 日
編集済み: Image Analyst 2012 年 9 月 9 日
thanks, so I should define T = 1/400 and use that. Can you explain what exactly is a sample as I asked previously? I have read about it online but I still don't quite understand it. I tried using linspace() and plot it but I get a straight line.
if true
% code
T = 1/400;
tt = linspace(-T, T, 50);
y = cos(2*pi*tt);
plot(tt, y, 'b:');
title('SINUSOID')
ylabel('amplitude')
xlabel('frequency')
end
  1 件のコメント
Image Analyst
Image Analyst 2012 年 9 月 9 日
See comment above in my answer.

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

その他の回答 (2 件)

Image Analyst
Image Analyst 2012 年 9 月 9 日
編集済み: Image Analyst 2012 年 9 月 9 日
No. You're wrong. There are 4000 cycles (periods) in a second, so the period of one cycle (T) is 1/4000 of a second, not the sampling frequency. And you're supposed to have 25 samples spanning that time period. Why not use linspace:
t = linspace(-T, T, 50); % 50 samples covering two periods from -T to T.
  1 件のコメント
Image Analyst
Image Analyst 2012 年 9 月 9 日
編集済み: Image Analyst 2012 年 9 月 9 日
Close (referring to your "Answer" below). Almost right but not quite. You should know that the equation for a cosine is cos(2 * pi * t / period). So try this:
y = cos(2*pi*tt/T);

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


JJ polaris
JJ polaris 2012 年 9 月 9 日
ok, thank you. I changed my equation which seems to be working now using sine.
y = sin(2*pi*f*tt);
where f = 1/T
Thank you for your help, I appreciate it

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by