Why is the number of periods of a cosine wave in the plot changing with the number of samples ?
4 次查看(过去 30 天)
显示 更早的评论
Hello,
I am trying to plot a cosine wave of frequency 7.9 GHz on Matlab, from time interval - 8 to 8 so I use "linspace" to define my time vector.
However I noticed, If I change the number of points (or samples) in my "linspace" vector, the number of periods of the cosine I see in the plot changes. I don't understand why this number of periods would change when it's the same time interval, any idea on why this happens ?
Please see below my code for both cases (samples number = 400 and 500) and the plots that I get!
Thank you in advance for your help,
f=7.9*10^9; % frequency of my cosine 7.9 GHz
w=2*pi*f;
t=linspace(-8,8,400); % time interval with 400 is the number of samples that I change
y=cos(w*t);
plot(t,y)
grid on
t2=linspace(-8,8,500); % I change from 400 to 500 samples
y2=cos(w*t2);
plot(t2,y2)
grid on
0 个评论
采纳的回答
Les Beckham
2023-6-16
This is called aliasing. I recommend reading the linked Wikipedia article. The sample rate (in this case the number of time samples in your t vector, per second), must be at least twice the frequency of the signal in order to even approximately represent the signal. A better rule of thumb is at least 10 samples per period of the signal.
So, for a signal at approximately 8 GHz you need to sample it at around 80 GHz to get a relatively clean representation of the signal. This means that, for an 16 second time span you would need this many samples:
num_samples = 16*80e9
Of course that is going to take about a terabyte of memory and, if you had that much memory, your plot would look like a blue rectangle and you couldn't see the wave shape at all.
Each period of an 8 GHz sine wave is only
period = 1 / 8e9
In other words, 0.125 nanoseconds.
Shorten the time span of your plot. For example:
f=7.9*10^9; % frequency of my cosine 7.9 GHz
w=2*pi*f;
t=linspace(-8e-10,8e-10,400); % time interval with 400 is the number of samples that I change
y=cos(w*t);
plot(t,y)
grid on
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!