1
$\begingroup$

This question already has an answer here:

I am generating sine wave in MATLAB with following code

fs=2000e6;%sampling frequency
t=0:1/fs:(1e-6)-1/fs; %1us seconds duration
fc=501e6;%frequency of the cosine wave
x=cos(2*pi*fc*t);
plot(x)

The wave it generates is somehing like this enter image description here

My question is: Why do we see amplitude modulation in the wave. Shouldn't amplitudes be 1 at all peaks of the wave? like this wave enter image description here

$\endgroup$

marked as duplicate by MBaz, lennon310, Fat32, Peter K. Sep 9 at 15:23

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    $\begingroup$ What you're seeing is a plotting artifact (you have more data points that pixels, so Matlab has do discard most data points before plotting). Also, you only have four samples per period, so you can't expect the plot to be super detailed. $\endgroup$ – MBaz Sep 3 at 13:22
  • 2
    $\begingroup$ I'm voting to close this question as off-topic because this is not a signal processing question. $\endgroup$ – MBaz Sep 3 at 13:22
  • $\begingroup$ Don't close this question! It is very much a signal processing question and with the confusion it caused related to that, then a very good dsp-puzzle at that! $\endgroup$ – Dan Boschen Sep 5 at 0:55
0
$\begingroup$

To explain what you are seeing (the envelope you see specifically is not a plotting artifact, but a fundamental DSP concept worth explaining) consider if you instead sampled a 500e6 Hz cosine wave at your sampling rate of 2000e6 Hz, which is exactly 4x the sampling rate. This would result in samples 1, 0, -1, 0, 1.... and since Matlab as you plotted would connect the adjacent samples, it would look like the bottom picture. (And if you used plot(x,'o') you would see just three lines).

Now consider your case where you have offset the frequency by 1 Hz, with this the sample location will "roll" along the sine wave, one cycle in the 1 us duration you are using.

This is exactly what you are seeing. The magnitudes 1 and -1 given in the first case are now moving slowly as the sample locations change slowly along the plot due to the slightly higher frequency, and if you use plot(x, 'o') for that case you will more clearly see the sample locations I am speaking of rather than the lines connecting the adjacent samples that are positive and negative (you will see what appears at 4 shapes varying sinusoidally and in quadrature. The envelope is just the artifact of the relatively low sampling rate (you have slightly less than 4 samples per cycle)- not how Matlab plots it.

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.