1

I'm fairly new to the DFT, and I'm trying to get a deeper understanding of what I'm looking at when I look at the polar magnitude of its output.

I have two sinusoids. I generated sinusoid b by just dropping its amplitude linearly to zero over time, and then I generated sinusoid a by just taking the mean amplitude from b. In code, I essentially did:

amp = np.linspace(1.4, 0, N)
sinusoid_b = amp * get_sinusoid(freq=750, len=N)
sinusoid_a = np.mean(amp) * get_sinusoid(freq=750, len=N)

Here they are plotted: enter image description here

Now, when I take the DFT of these two and plot the polar magnitude, the spectrums are very similar but not quite the same:

enter image description here

This makes sense to me, but at the same time it doesn't. On one hand, I should be able to synthesize two different signals from these two DFTs, so they should be a little different somehow. On the other, since the average amplitudes of the sinusoids over the DFT area is the same, I also would kind of expect the magnitude spectrum to be the same. What exactly am I looking at with the polar magnitude? Is it not the average amplitude of the sinusoids over the area the DFT was taken on?

Rob Allsopp
  • 199
  • 5

1 Answers1

1

"mult in time" $\Leftrightarrow$ "conv in freq", so B is simply dirac delta (unit impulse) circular-convolved with DFT of ramp, which is simply a shifted DFT of ramp. The two are visually similar due to spectral leakage; the sine is sampled at a non-integer number of cycles. Try sinus = sinus[:-20] on both:

The general case of amplitude modulation of a sine follows the same principle: FT of $A(t) \cos(\omega t)$ is just FT of $A(t)$ shifted by $\omega$ in frequency domain. It's possible that the linear ramp is some special case for which the two's magnitude spectra can overlap, but this isn't true in general.

I'll finish by noting that DFT coeffs aren't "meaningful" for a wide variety of signals, including AM/FM, and time-frequency analysis is preferred; see under "Modulation Model vs Fourier Transform".

import numpy as np
import matplotlib.pyplot as plt
from numpy.fft import rfft

sr=44100

def get_sinusoid(freq, N): t = np.linspace(0, N/sr, N, 1) # tried approximating your plots return np.cos(2np.pi freq * t)

N = 8192 amp = np.linspace(1.4, 0, N) sinusoid_b = (amp * get_sinusoid(freq=750, N=N))[:-20] sinusoid_a = np.mean(amp) * get_sinusoid(freq=750, N=N)[:-20]

xfa = rfft(sinusoid_a) xfb = rfft(sinusoid_b)

viz

plt.plot(sinusoid_a); plt.show() plt.plot(sinusoid_b); plt.show()

plt.plot(np.abs(xfa)) plt.plot(np.abs(xfb)) ax = plt.gca() ax.set_xscale('log') ax.set_xlim(1e1, 1e3)

OverLordGoldDragon
  • 8,912
  • 5
  • 23
  • 74
  • I'm generating audio sinusoids, so if you tweak your get_sinusoid method to something like np.sin(2*np.pi*freq*np.linspace(0, N/sr, N)) where sr=44100, and then also include x values for your plot ranging from 0 to 22050 you'll see what i'm seeing – Rob Allsopp Mar 25 '22 at 00:16
  • Regardless of the code though, I'm really looking for an answer to the theory question: How is the magnitude given by the DFT related to the original sinusoids when their amplitudes are changing over the length of the DFT? Are the DFT magnitudes giving the average amplitude over that time, or something else? – Rob Allsopp Mar 25 '22 at 00:26
  • @RobAllsopp Updated. – OverLordGoldDragon Mar 25 '22 at 00:39