Why is the number of periods of a cosine wave in the plot changing with the number of samples ?

5 visualizzazioni (ultimi 30 giorni)
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

Risposta accettata

Les Beckham
Les Beckham il 16 Giu 2023
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
num_samples = 1.2800e+12
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
period = 1.2500e-10
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
  4 Commenti

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by