Sine plot at a period T over a 20 second interval
8 次查看(过去 30 天)
显示 更早的评论
Write a MATLAB script (m) file that builds an array e(k) which consists of the waveform sin(πt) sampled at a period T over a 20 second interval. Initially choose a sample period that is small compared to the period of the waveform.
My code is as follows.
clear all
clc
T=20;
freq = 1/20;
t=0:0.01:20;
y=sin(t*pi);
figure(1)
plot(t,y)
xticks(0:2:20);
grid on
grid minor
0 个评论
回答(1 个)
Walter Roberson
2021-3-10
T=20;
ok. But you never use T.
freq = 1/20;
Is the 20 a coincidence? But it doesn't matter, as you never use freq. Note by the way that a "freq"uency of 1/20 would mean that one period requires 20 seconds.
t=0:0.01:20;
That is a frequency of 1/0.01 which is 100 Hz.
y=sin(t*pi);
Only if your t is in radians per second instead of samples per second.
If you want 1 Hz thenyou need to complete 1 period in 1 second. 1 period is 2*pi radians. Therefore over 1 second you need to complete 2*pi radians. Your current code completes 1 radian per second instead of 2*pi radians in 1 seconds.
13 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spectral Estimation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!