2

My motivation to this post has arisen from the accepted answer to Amplitude modulation vs sampling rate?

Sampling the signal with the frequency close to $f_s/2$ can lead to some kind of "beatings" of the sampled signal. It is clearly seen if I try to sample simple cosine signal: enter image description here

Here FFT shows both positive and negative frequencies of the signal as it should be.

But if I try complex signal (here it is $e^{j2\pi f t}$) and left plot is real part of my complex signal: enter image description here

In this case FFT shows only one (positive) frequency component, but beatings of the sampled signal still exist. My question is why?

The Python code to reproduce these plots:

fig, ax = plt.subplots(2,2, figsize=(15,5))

fs = 20 f = 8.8 t = np.arange(0, 2, 1/(fs*fs)) t_sampled = np.arange(0, 2, 1/fs)

signal_complex = np.exp(1j(2np.pift_sampled)) signal_real = np.cos(2np.pif*t_sampled) # cosine

ax[0,0].plot(t, np.cos(2np.pif*t)) ax[0,0].plot(t_sampled, signal_real, color='r', marker='o') ax[0,0].set_title('Time domain (cosine signal)')

ax[1,0].plot(t, np.exp(1j(2np.pift)).real) ax[1,0].plot(t_sampled, signal_complex, color='r', marker='o') ax[1,0].set_title('Time domain (exponential signal)')

FFT_complex = np.fft.fft(signal_complex) FFT_real = np.fft.fft(signal_real) freqs_fft = np.fft.fftfreq(len(t_sampled), t_sampled[1])

ax[0,1].stem(freqs_fft, abs(FFT_real)) ax[0,1].set_title('FFT (cosine signal)')

ax[1,1].stem(freqs_fft, abs(FFT_complex)) ax[1,1].set_title('FFT (exponential signal)')

plt.tight_layout()

Curious
  • 355
  • 1
  • 11
  • Plotting just the real part of a complex signal doesn't tell the whole story. Try plotting the amplitude of your complex signal, or the real and imaginary part together on the same graph. – TimWescott Sep 07 '22 at 18:15
  • @TimWescott, I tried to plot real and imaginary parts and got the same result - beatings exactly at frequency $fs/2-f$, I also tried to plot the amplitude (module) and got just a straight line – Curious Sep 07 '22 at 20:02
  • It's not unambiguously "there's no beats". Refer to this and this. Short version, if we know it'd bandlimited, then there's no beats. – OverLordGoldDragon Sep 07 '22 at 21:30
  • @OverLordGoldDragon, I saw your question (first link) and after it asked my own here, I think bandlimited signal'll also look like a signal with beatings as we're close to $f_s/2$ – Curious Sep 07 '22 at 21:45
  • More detail, if we know it's bandlimited and the signal of interest is analog, then the signal is a pure sine - that is, the samples perfectly and uniquely reconstruct to a pure sine. Disagreement can only occur if we're not bandlimited or if the discrete sequence is ground truth. Otherwise we're saying a pure sine has beats, which violates the definition. – OverLordGoldDragon Sep 07 '22 at 23:35
  • Actually I think the criteria is simply this: if we know the signal is a pure sinusoid, then there is no actual beating. If the signal is two tones then the beating will be realized. (Any pure sinusoid or two tones are "bandlimited")-- it also does not matter where the signals are compared to the sampling rate-- for that case we would then also consider the effects of aliasing, where a pure sine wave higher than half the sampling rate would simply alias to another pure sine wave less than half the sampling rate so has nothing to do with creating actual "beats". – Dan Boschen Sep 08 '22 at 03:38
  • @OverLordGoldDragon, but if I do know nothing about considered signal? how can I distinguish between unknown signal with "real" beats and unknown signal with "beatings" occured due to sampling process? – Curious Sep 09 '22 at 17:37
  • @DanBoschen, and if we do know nothing about the signal? I think I can't distinguish the signal with real beatings (two tones) and beatings due to the sampling process. – Curious Sep 09 '22 at 17:43
  • @Curious Correct. In your example you specifically demonstrated what we would see with a single tone. So in that case we know "truth" was the single tone you created. My point more detailed in my answer that it is a many to one mapping from continuous time to discrete time in terms of the possible analog waveforms that would create the discrete samples that result. – Dan Boschen Sep 09 '22 at 18:42

2 Answers2

3

In this case FFT shows only one (positive) frequency component, but beatings of the sampled signal still exist. My question is why?

Why would it? Real vs. complex has nothing to do with the phenomenon we are looking at. The only difference between a real and complex sinusoid is that the former has two spectral lines and the latter only one.

You seem to be confusing two different effects here.

The so-called "beating" does NOT exist. It's simply a visual artifact of the way you draw the waveform. Most plotting routines simply connect samples with straight lines which is simply wrong. If you were to draw this using proper band-limited interpolation at each pixel (and with enough pixels) you get the correct waveform. This has no bearing on the frequency domain at all.

The spreading of the spectrum you see is spectral leakage. There are plenty of post on this forum about this. Spectral leakage occurs for sine waves whose frequency doesn't line up with the frequency grid of the FFT. As long as your frequency is an integer multiple of the bin resolution (sample rate divided by FFT length), you will only get a single spectral line, regardless whether there "visual beating" or not in your time domain graph.

In your case, the frequency resolution is 0.5Hz so if you choose 8.5Hz or 8Hz (instead of 8.8Hz) all the spectral artifacts will disappear.

EDIT: Derivation of the apparent beat at $(f_s/2-f)$

Let's say we have a sequence $x[n] = \cos(\omega n)$. If $\omega$ is close to Nyquist we can write this $\omega = \pi-\delta$ where $\delta$ is the frequency difference to Nyquist.

Hence we get $$x[n] = \cos(\pi n - \delta n) = \cos(\pi n )\cos(\delta n) + \sin(\pi n )\sin(\delta n)$$

$\sin(\pi n ) = 0$ and $\cos(\pi n ) = [+1,-1,+1,-1,...] = (-1)^n$ so the whole thing becomes

$$x[n] = (-1)^n\cos(\delta n) = (-1)^n\cos(2\pi(f_s/2-f) n) $$

Note that we haven't done any actual manipulation here, we've just written the samples of the sine wave in a different form.

You visually interpret this as something that's oscillating fast multiplied with a slow sine wave. That sort of looks like a beat, but it's not. It's still a perfectly good sine wave. There is no actual amplitude modulation whatsoever.

Hilmar
  • 44,604
  • 1
  • 32
  • 63
  • ok, but how can be explained the fact that sampled signal has the envelope frequency of exactly $f_s/2-f$? – Curious Sep 07 '22 at 19:36
  • The envelope of the signal if calculated properly (using for example a Hilbert Transform) is perfectly flat. This is really just a visual artifact based on the way it's plotted. It's easy enough to calculate that it indeed looks like a beat at $f_s/2-f$ but it's still a perfect sine wave. The spectrum is a single (or dual) line (as long as you don't have spectral leakage) and if you run it through a DAC and put it on an oscilloscope you see a perfectly steady state sine wave with no beats whatsoever. Did you run your script at 9Hz? – Hilmar Sep 07 '22 at 20:26
  • the leakage issue is absolutely clear for me, as you just asked I tried 9Hz signal, which is multiple of one of the FFT frequencies and I got "pure" spectrum with no leakages as expected, but my question is not about it; even for 9 Hz the sampled signal still have "beatings" exactly at frequency $f_s/2-f$ – Curious Sep 07 '22 at 20:37
  • I don't know what else to tell you. It does NOT have any beats. These would show up as side-bands in the spectrum and there are clearly none. If you draw the samples with proper interpolation, it looks like sine wave. Try a cosine at $f_s/4$ with a phase of 0 and a phase of $\pi/4$ One looks like a triangle wave , the other one like a square-ish wave. But that's non-sense, they are both perfectly good sine waves. It only looks this way because you implicitly (or explicitly) assume that the waveform between samples is a straight line, which it really isn't. – Hilmar Sep 07 '22 at 21:19
  • 1
    See updated answer. I took a swing at explaining why it looks like $f_s/2-f$ – Hilmar Sep 07 '22 at 21:53
  • thank you!) could you please explain a bit, why if $\omega$ is close to Nyquist we can write $\omega=\pi-\delta$? – Curious Sep 09 '22 at 17:46
  • 1
    Sorry, I didn't explain this well. Of course you can write $\omega = \pi-\delta$ for any frequency. However, if $\omega$ is close to Nyquist (which corresponds to $\pi$) than $\delta$ becomes very small and $\cos(\delta n)$ looks like a beat. – Hilmar Sep 10 '22 at 18:32
  • I thought Nyquist frequency corresponds to just $f_s/2$, is it some kind of conversion to radians? – Curious Sep 10 '22 at 20:09
  • if $\omega$ is close to Nyquist, I think it would be $\omega=2\pi\frac{f_s}{2}=\pi f_s$, why do you omit $f_s$ here? – Curious Sep 11 '22 at 19:52
  • 1
    $\pi$ is the normalized frequency of Nyquist. Let's sample $\cos(2\pi \frac{f_s}{2} t)$ at $f_s = 1/T_s$. We get $x[n] = \cos(2\pi \frac{f_s}{2} nT_s ) = \cos(2\pi \frac{f_s}{2} n/f_s) = \cos(\pi n)$ – Hilmar Sep 12 '22 at 02:29
  • for $\pi$ it is clear, but in case of "arbitrary" frequency $f$ I think it would be: $x[n]=cos(2\pi fnT_s)=cos(2\pi fn/f_s)$ – Curious Sep 13 '22 at 12:33
  • 1
    Yes. That's why often use $\omega = 2\pi f/f_s$ as the "normalized frequency". This is normalizes everything to the sample rate. For discrete signals, calling a frequency "high" or "low" is always with respect to the sample rate, regardless of whether it's $1Hz$ or $1GHz$ – Hilmar Sep 14 '22 at 11:50
1

Through the commentary I now understand the crux of the OP's question which I will summarize as follows:

As detailed in the referenced post (https://dsp.stackexchange.com/a/70884/21048) I was able to explain how the underlying analog signal prior to sampling could have either been a single real tone OR a double-side-band-suppressed-carrier (DSB-SC) modulation with the suppressed carrier at $f_s/2$ (and there are infinitely many other solutions that would result in the same discrete samples that resulted). The OP has astutely observed that the same result (the beats in the time domain) can occur even if the input isn't real, which seems to counter the explanation provided.

The reason is the time domain plot shown is just the real component. In doing that the spectrum of the real component alone is identical to the first spectrum shown above which is the spectrum of the real signal NOT the complex signal. To observe the complex time domain signal we must observe two real signals (either magnitude and phase or real and imaginary). From a plot of magnitude and phase of the complex case, it will be clear that the magnitude is constant at all time samples while the same plot of magnitude and phase for the real case will show the beating as observed. If we choose to instead plot real and imaginary, then yes each of those will show beating but it is in such a way to maintain a constant magnitude (as one goes up the other goes down). Beating refers to an Amplitude Modulation, and with the complex waveform as $I+jQ$ we must consider both $I$ and $Q$ together to measure the amplitude, not individually. So plotting amplitude as $\sqrt{I^2+Q^2}$ will show that there is no beating (no AM), unless we take the real or take the imaginary only of the resulting waveform.

Consider the simple case for the spectrum of $e^{j \omega_o t}$ as plotted below without the added complexity of sampling, folding and spectral leakage:

complex spectrum

$$e^{j \omega_o t} = \cos(\omega_o t) + j \sin (\omega_o t)$$

So if we were to only plot the real part of the above complex spectrum in the time domain, we would get $\cos(\omega_o t)$. However to be complete the spectrum of this would then appear as below:

real spectrum

So bottom line, the second time domain plot on the left showing beating together with a complex spectrum on the right is incomplete. The time domain plot is not the time domain for the spectrum given, but the time domain for the real portion of the spectrum given (which would then be identical to the spectrum in the upper plot).

Dan Boschen
  • 50,942
  • 2
  • 57
  • 135
  • but in both cases the envelope frequency of the sampled signal is $f_s/2-f$; following your answer I think it would help to remove "beatings" – Curious Sep 07 '22 at 19:33
  • what do you mean by "two tones spaced apart in frequency by twice the beat tone frequency"? – Curious Sep 07 '22 at 20:49
  • I'm familiar with AM-signals and understand what did you mean: $f_s/2$ - carrier, $f_s/2-f$ - lower sideband, $f_s/2+(f_s/2-f)$ - upper sideband, with this in mind I get the same plot (though I still didn't get, why $f_s/2$ is carrier in this case), but in your plot for complex tone the output spectrum has no component for $f_s/2+(f_s/2-f)$ (upper sideband), but $f_s/2-f$ beatings exist, that's why I've posted this question. – Curious Sep 10 '22 at 20:46
  • now I'm absolutely confused about the sampling process... could you please clarify, which are those two tones BELOW $f_s/2$? – Curious Sep 11 '22 at 18:55
  • and in your answer here you consider the carrier as $f_s/2$, hmm... – Curious Sep 11 '22 at 20:52
  • @Curious So did I (finally) really understand your question and answer it? See my update. – Dan Boschen Sep 12 '22 at 12:24
  • thank you for such a nice explanation!) You exactly got the point of my question) Indeed, fot the first time I tried to plot the module of considered complex signal, but still if I plot it I just get the constant value equaled to 1, how can I plot such a periodic complex signal to finally observe pure signal without beatings? – Curious Sep 13 '22 at 10:41
  • @Curious Yes sorry I couldn't see that initially, nothing wrong with your question- it is very clear. The periodicity for the complex tone is the number of rotations per second, so I like to visualize it on a complex plane as a rotating phasor. This makes it very clear what frequency is in this context as well as what "positive" and "negative" frequencies are. Think of a bicycle wheel and the revolutions per second if the frequency but it can be moving forward or backward (positive or negative). So we see the magnitude of that phasor is constant just as you observed, and to see the rotation... – Dan Boschen Sep 13 '22 at 12:54
  • or repetition you need to observe the phase. A change of phase with a change of time ($d\phi / dt$) IS frequency. I preach that we are misguided in our early education with signal processing to start with sinusoids-- it leads to much confusion and much more difficulty in thinking through architectures and algorithms intuitively. In the courses I teach I start with the complex phasor (we are introduced to complex numbers in high school, so this shouldn't be a challenge; yet I see it is a lot of work to undo the misconceptions). I deleted my earlier comments from my prior misguided answer. – Dan Boschen Sep 13 '22 at 12:56
  • for complex phasor it is clear - we have a vector in a complex plane, the magnitude of this vector is constant and the phase is the angle between the current vector position and I-axis (for example), does it mean that I can't visualize such complex signal as periodic (sine or cosine) in time domain? – Curious Sep 13 '22 at 13:30
  • @Curious to represent a complex number we need two real numbers (such as I+jQ where I and Q are real, jQ is imaginary, or magnitude and phase). Similarly to measure a complex waveform in the lab, we need two scope probes. To represent your complex waveform vs time on a graph you will need two plots: either real and imaginary, or magnitude and phase. It is the two plots together that represent the waveform - if you only look at one you have essentially taken the real of it, or the imaginary of it, or the magnitude of it, or the phase of it. Any one of those alone is incomplete. – Dan Boschen Sep 13 '22 at 14:16
  • A sine (or cosine) is not a “single frequency tone” but contains two such tones (as we see if the DFT): a positive frequency and a negative frequency. The positive frequency tone is $e^{j \omega t}$, as one phasor rotating counter-clockwise and a negative frequency tone is $e^{-j \omega t}$ which is a clockwise rotating phasor. Add the two and you get a (real) cosine: $2\cos(\omega t)= e^{j \omega t} + e^{-j\omega t}$. – Dan Boschen Sep 13 '22 at 15:10
  • all of this is absolutely clear, but my main purpose here is to compare real tone (simple sine or cosine) and complex tone to confirm (visualize) that if I use a complex signal, I'll not see any beatings in time domain (hope, it sounds correct), for now I do so by plotting signal amplitude vs time; I tried to "plot" complex tone as its magnitude and phase, but for magnitude I always have a constant value and for phase saw-like curve and have no idea how "to connect" them... – Curious Sep 14 '22 at 17:54
  • 1
    @Curious The “beatings” as described are an AM artifact so result in the amplitude only. If you compare the magnitudes of the real vs the imaginary you will then properly confirm that the real has beats and the imaginary doesn’t (constant as it should be) – Dan Boschen Sep 14 '22 at 18:08
  • 1
    it obviously makes sense!) thinking in terms of sinusoids (in particular for this example) can really as you said before "misguide" the intuition and understanding the sampling process. – Curious Sep 15 '22 at 17:50