Why does the DFT have only $N$ components in it? I can see that after N components the frequency component is periodic and repeats with the same values but that does not seem to explain why we can have only $N$ components. Is this related to the sampling theorem? How does this all tie together?
-
1The continuous Fourier Transform has this symmetry between the forward and inverse transforms. Because $+j$ and $−j$ both have equal claim to squaring to be $−1$, both have equal claim to being the imaginary unit. So the forward and inverse Fourier transforms are essentially the same. So uniform sampling in one domain will cause periodic extension in the reciprocal domain. So this means that the DFT has sampled (or "discrete") and periodic sequences in both domains. $N$ contiguous samples in either domain fully define the two periodic functions in the both domains. – robert bristow-johnson Sep 16 '20 at 00:52
-
I will offer my view, which is linear algebraic and brings intuition different from that of the answers below. A signal $\mathbf{s}$ of $N$ complex entries is a vector in the $N$-dimensional complex vector space $\mathbb{C}^N$. Once can express any such vector as a linear combination ($\mathbf{s} = c_0\mathbf{u}0 + \cdots + c{N-1}\mathbf{u}_{N-1}$) of the vectors in a basis of $\mathbb{C}^N$. Each basis of $\mathbb{C}^N$ has exactly $N$ vectors in it. The DFT of $\mathbf{s}$ is the list of coefficients of $\mathbf{s}$ with respect to one very convenient and intuitive basis of $\mathbb{C}^N$. – Joe Mack Sep 17 '20 at 18:34
3 Answers
The DFT is discrete in both time and frequency domains with the same number of samples in each domain, this means the input to the transform and the output of the transform are both discrete and both have $N$ samples. This is defined in the formula for the DFT where we have $N$ samples in time indexed as $n = 0$ to $N-1$ and $N$ samples in frequency indexed as $k = 0$ to $N-1$. The sampling frequency is located at $k = N$.
$$ X[k] = \sum_{n=0}^{N-1}x[n]e^{-j k \frac{2\pi}{N} n}$$
This is by definition, as for example the DTFT is continuous in frequency given by
$$ X(e^{j\omega}) = \sum_{n=-\infty}^{\infty}x[n]e^{-j\omega n}$$
As we see in the DFT formula, each sample $k$ in $X[k]$ is a correlation (sum of products) of the time domain waveform $x[n]$ with the frequency tone given by $e^{-j k \frac{2\pi}{N} n}$ -- observe that the form $e^{j\phi}$ is a phasor with magnitude $1$ and angle $\phi$, so we see that for each value of $k$ that we pick, $e^{-j k \frac{2\pi}{N} n}$ is just a phasor spinning at a different rate defined by $k$. Due to this, the correlation will be maximimum when $k$ is equal to or close to the frequency of $x[n]$.
The reason for $N$ samples is also quite intuitive since as the OP saw the transform mathematically has the same result as if the time domain waveform was periodic: This is similar to the Fourier Series Expansion (FSE) which decomposes any single valued analytic function into an infinite series of discrete frequencies, with each frequency an integer multiple of the fundamental, with the fundamental given by $f=1/T$ Hz where $T$ is the duration in seconds of the time domain signal: That makes sense as the FSE would also have the same result if that time domain waveform continued to infinity as a periodic waveform; if we repeat an arbitrary waveform over $T$ seconds, it will have a fundamental frequency at $1/T$ Hz. It also must be discrete, since each of the individual components given by the higher harmonics will also repeat only over duration $T$, and we recreate the waveform by summing each of these component (so any component that didn't repeat over $T$ would violate our ability to do that).
Thus knowing we have $N$ samples in time, the fundamental frequency would then be at $1/N$. We also know that the sampling rate is at bin $k = N$ in frequency, thus the fundamental frequency is at $k=1$, and there must then be $N$ total frequency samples (some may be equal to 0), each one the integer multiple of the fundamental, just like the FSE!
- 50,942
- 2
- 57
- 135
-
looks like we had overlapping edits, Dan. did mine trample over yours? – robert bristow-johnson Sep 15 '20 at 03:56
-
often the DTFT is expressed exactly as the bilateral Z-transform with the substitution of $z=e^{-j \omega}$. but i can't see what i clobbered. – robert bristow-johnson Sep 15 '20 at 03:58
-
1@Robert I was simply changing the order of the variables in the exponent of the DFT to be $-j k \frac{2\pi}{N} n$- making it a more intuitive match to $\omega_o = \frac{2\pi}{N}$ in the last graphic. But thanks for all your good clean-up. If you noticed, I finally learned to put the slash in front of sin, cos etc – Dan Boschen Sep 15 '20 at 03:59
-
-
I tweaked it just a tad, then untweaked it when I reread your rationale. Generally, I prefer it this way: $ e^{-j \frac{2\pi}{N}k n} = R^{kn} = R_k^n $ where $R$ is a root of unity. – Cedron Dawg Sep 15 '20 at 09:01
-
1Yes often given in DFT related literature as $W_N^{nk}$; the "twiddle factors" introduced by Gentleman and Sande in 1966 in explaining the DFT. So the DFT is simply $\sum_{n=0}^{N-1}x[n]W_N^{nk}$ which is so much easier to read and work with. – Dan Boschen Sep 15 '20 at 12:39
-
(Such as was done in this post: https://dsp.stackexchange.com/questions/66716/why-do-we-have-to-rearrange-a-vector-and-shift-the-zero-point-to-the-first-index/66999#66999 ) – Dan Boschen Sep 15 '20 at 12:47
-
Yep, and it can be seen as a power series, so it can be categorized that way. As is the Z-tranform. But you can't categorize a DFT as a Z-transform unless you include the appropriate window function. (For the benefit of my nephew). $$ $$ You can also see it here: https://www.dsprelated.com/showarticle/768.php I do like to emphasize that $W_N^{nk}$ has a Nth Root of Unity as a base and each instance is also a Nth Root of Unity. If the Roots of Unity don't convince you that complex numbers are something special, then nothing will. Also that the DFT is very much a Roots of Unity "thing". – Cedron Dawg Sep 15 '20 at 13:08
-
2A little additional commentary for the OP, other noobs, my nephew, and even some of the regulars: In a chicken vs the egg sense, the DFT precedes the DTFT. The DTFT is obtained by allowing the domain to be continuous, and extending it to infinity. That's how things work in math. So statements like "sampling of the DTFT causes the inverse transform to become periodic" (https://en.wikipedia.org/wiki/Discrete-time_Fourier_transform) are behavioral observations not foundational statements. As for the chicken or the egg. Eggs existed way before chickens, duh. – Cedron Dawg Sep 15 '20 at 14:12
Why does the DFT have only N components in it ?
As you pointed out, the DFT could have an infinity of components in it, that repeat every N entries. To some extent, this is what aliasing is all about -- you're putting those "missing" bits back in.
There's two reasons (or perhaps one and a half) to limit the DFT to N components, though: One is economy -- you don't need more than N components. The other is completeness -- if you want to have a transform with an inverse, then having extra points in the forward direction makes for an indeterminate transformation in the reverse direction.
In a way that you can regard the DFT is as multiplying a vector by a square matrix. So you can say $$X = \mathbf{A}_{DFT}\ x$$ where $X$ is a vector of samples in the frequency domain and $x$ is a vector of samples in the time domain. $\mathbf{A}_{DFT}$ is defined as $$\mathbf{A}_{DFT} = \begin{bmatrix} 1 && 1 && \cdots && 1 && \cdots && 1\\ 1 && e^{-2i \pi 2/N} && \cdots && e^{-2i \pi m/N} && \cdots && e^{-2i \pi (N-1)/N} \\ && && && \vdots && && \\ 1 && e^{-2i \pi n/N} && \cdots && e^{-2i \pi\ n\,m/N} && \cdots && e^{-2i \pi (N-1)n/N} \\ && && && \vdots && && \\ 1 && e^{-2i \pi (N-1)/N} && \cdots && e^{-2i \pi\ (N-1)\,m/N} && \cdots && e^{-2i \pi (N-1)^2/N} \end{bmatrix}$$
(Work this out for yourself -- first, because it's profound, and second, because I probably made some stupid typo in there somewhere).
It turns out that $\mathbf{A}_{DFT}$ is a square Hermitian orthoganal matrix, and just a scaling factor away from being orthonormal.
The nasty thing about this is that it puts the whole thing into hard-to-grok matrix notation. The nice thing about it is that the inverse DFT just falls right into your lap: $$x = \mathbf{A}_{IDFT} X$$ and so by inspection you can say that $$\mathbf{A}_{IDFT} = \mathbf{A}_{DFT}^{-1}$$
And that is why we stop at N points in our DFT: because each of the N points in the 'output' of a DFT is uniquely defined, and that N-point DFT carries all the information in the original vector $x$, without duplication. That, in turn, means that there's an inverse transformation -- that we can even find using linear algebra, if we're in a mood.
- 12,704
- 1
- 11
- 25
-
It looks like you only revealed one of your two reasons-- what is the second reason? – Dan Boschen Sep 15 '20 at 12:29
-
T'oh! Poor editing -- I figured out at the end that I was really only making one point, and only needed to make it one way. Stand by for edits... – TimWescott Sep 15 '20 at 16:12
-
Oh I liked the mystery of it all, and thought you should always do that — for instance when there are four reasons you say there are five and list the four – Dan Boschen Sep 15 '20 at 16:15
-
5Trying, but I can't resist: "There are three types of Mathematicians, those who can count and those who can't." ;-) – Cedron Dawg Sep 15 '20 at 17:07
The Discrete Fourier Transform (DFT) is a transform from a signal to a spectrum, both being discrete sequences. The values in the signal are called samples and the values in the spectrum are called bins. The signal may typically be real valued or complex, but the spectrum usually needs to be complex. There are signals that have strictly real spectrums.
The definition establishes the calculation a single bin value from a range of sample values called a frame:
$$ X[k] = ? \cdot \sum_{n=L}^{H} x[n] e^{-i \frac{2\pi}{N} kn} $$
The DFT definition makes no assumptions about the values of the signal outside the frame.
Common notation is:
$\quad X[\,]$ is the spectrum
$\quad k$ is the bin index
$\quad x[\,]$ is the signal
$\quad n$ is the signal index
$\quad N$ is the sample count also known as the DFT frame size
Further notation is:
$\quad ?$ is the normalization factor (usually not shown, no conventional symbol)
$\quad L$ is the lowest sample index
$\quad H$ is the highest sample index
The definition of the DFT can have variations based on the conventions used. The first is the normalization factor. The three predominant ones are:
$\quad ? = 1 $ This is the most conventional, and what you will find with most code libraries.
$\quad ? = 1/N $ This is the more meaningful one in terms of usage, and IMO be "The Correct One".
$\quad ? = 1/\sqrt{N} $ This is the Linear Algebra preferred one, as it makes the Matrix representation (TimWescott's answer) unitary.
The input range as two common ranges:
$\quad L,H = 0,N-1 $ Is the common on in code libraries and usage.
$\quad L,H = -M,M $ This is an odd sized domain which is zero centered. This configuration is the more "natural" one where $N = 2M+1$. The symbol $M$ isn't a convention.
Because of the nature of the exponential expression in the defintion, $X[k]$ will be $N$ periodic. Therefore a spectrum of N bins will contain all the obtainable information and extra calculations are redundant. (The answer being sought, I presume).
The value of $k$ represents the frequency of the corresponding basis vector in the signal space in units of cycles per frame. Because of the discrete nature of the signal, and how the underlying trigonometric functions work, values of $k$ larger than $N/2$, or smaller than $-N/2$ (known as the Nyquist bin for even $N$ values) are indistinguishable from values within this range and are known as alias frequencies.
It is common to evaluate the DFT for bins 0 through $N-1$, usually done when the input range is also 0 through $N-1$. The second most common, is to evaluate the range from $-M$ to $M$ in the case of the corresponding input range. There is nothing that says you have to compute any or all the bins. The periodicity makes conversion between different choices easy without requiring recalculation.
$$ X[k] = X[k+N]$$
The inverse DFT is mathematically equivalent to the forward one without the negative sign in the exponent. The normalization factor should be chosen so that the product of the two normalization factors is $1/N$. This is not a requirement and many code libraries will provide an unnormalized IDFT.
Whether the negative sign is in the forward transform or the inverse is relevant for complex tones, as it is desired the a signal which is a pure complex tone of frequency $k$ cycles per frame should be represented by bin $k$ in the spectrum. Since a real pure tone is an average of two complex pure tones with equal magnitude, but opposite sign, frequencies, it will be represented in bin $k$ and bin $-k=N-k$ regardless of the sign.
Like the forward DFT, the inverse DFT is periodic in its output. Thus, if you take the inverse of the spectrum of a signal, the signal you generate is a new signal which matches the original signal exactly in the frame and is N periodic outside of it.
The "ideal use" of a DFT is to frame a periodic signal on a whole number of cycles. In this case, the inverse of the spectrum and the signal match inside and outside the frame. Since a periodic signal can always be represented as the weighted sum of a set of harmonic tones, and harmonic tones have frequencies that are whole integer multiples of the fundamental, the values of the weights can be determined directly from bin values.
The N periodicity of the output is trivial to prove straight from the definition:
$$ X[k+N] = ? \cdot \sum_{n=L}^{H} x[n] e^{-i \frac{2\pi}{N} (k+N)n} = ? \cdot \sum_{n=L}^{H} x[n] e^{-i \frac{2\pi}{N} kn } e^{-i 2\pi n} = X[k] $$
Where $e^{-i 2\pi n}$ always equals 1 when $n$ is an integer.
This can be shown directly from Euler's formula:
$$ \begin{aligned} e^{i\theta} &= \cos( \theta ) + i \sin( \theta ) \\ e^{-i 2\pi n} &= \cos(-2\pi n) + i \sin(-2\pi n) \\ &= 1 + i0 = 1 \end{aligned} $$
Note, this answer does not have any dependency to the corresponding continuous case, or even presumes its existence.
A representation of a $N=16$ DFT:
The animated gif is even cooler, but way too large to post.
- 7,560
- 2
- 9
- 24
-
1The term bin has a quite common usage accross internet for referring to elements of the forward DFT sequence $X[k]$, yet its origin is not possibly DSP textbooks. I believe the source is the users from Computer Science, Data Science, or Statistics, who like demonstrating various data, statistics, or histograms, into graphs using bins for the index of a particular kind, which doesn't have better name for. Eventually the term gained some acceptance among Electrical Engineers (DSP guys) too. So we consider $k$ of $X[k]$ as the DFT index, the frequency-index, and $n$ as the time-index. – Fat32 Sep 15 '20 at 20:39
-
1Futhermore, I'm not sure about what you mean by the term ideal utilisation,but the most typical professional enginering use of DFT is for analysing frequency spectrums of continuous-time signals. (The second most common utilization for DFT/FFT being efficient implementation of convolution). In that case, probability of observing a whole period of samples from a signal of unknown period is very low; the ideal lolipop frequency view practically does not happen. But various frequency estimation methods are developed to infer the frequencies of those peaks within the observed spectrum. – Fat32 Sep 15 '20 at 21:01
-
@Fat32 Duly noted, but not sufficient to trigger an editing change. Critique: "DFT index" employs the alternate meaning of DFT to refer to the spectrum rather than the operation, so it is misleading. The transform doesn't have an index, per se. "frequency-index" doesn't specify the (ahem) units of the frequency so it is ambiguous. Using "bin index" and "bin value" is much more concise and precise. "time-index" supposes that the samples are in the committee approved time dimension, whereas "sample index" allows for any (ahem) unit of something. – Cedron Dawg Sep 15 '20 at 23:08
-
@Fat32 Are not periodic signals the "most ideal" subset of continuous-time signals for the DFT? Especially if you have the choice to frame them on a whole number of cycles. So this is the special case when the DFT works most like its erroneously stated ability to "pluck frequencies out of the signal". – Cedron Dawg Sep 15 '20 at 23:09
-
1If you used the term ideal, in place of unrealistically perfect, then yes you are right, otherwise if it was used in place of correct or proper, then my comment applies; i.e., we never expect to capture (ADC) a whole period of a periodic signal; because you don't need it. If it's you are lucky, but if it's not you are still lucky...;-) – Fat32 Sep 15 '20 at 23:56
-
-
1These kind of exclusive discussions with you solidified my opinion on the reasons of producing a collective specific terminology to identify every annoying feature of pedantic demagogue people... :-)). $k$ is the frequency-index and $n$ is the time index. bin is a trashy name, suitable for the use of statisticians or alike ;-)) Unlike mathematicians or statisticians, we the engineers are bound by phsyical reality... – Fat32 Sep 16 '20 at 00:07
-
1I think the phrases best to hope for and most exemplary are a bit contradicting... I pick the former: best to hope for ... – Fat32 Sep 16 '20 at 00:09
-
2pedantic? demagogue? (happy that someone else gets it.) – robert bristow-johnson Sep 16 '20 at 00:31
-
1Okay, I'll pick "most exemplary" because it is the condition which most exhibits the capabilities of the DFT. No, wait, wait, wait, I'll pick "best to hope for" because it ain't going to get any better out there in this cold cruel world. Oh no, Mark Leeds, shield your eyes, you can't join the club. I'm getting the chat prompt, let's be done now. It is kind of ironic you guys don't recognize your insistence of defining and following standards as pedantic when it means: "overly concerned with minute details or formalisms, especially in teaching." – Cedron Dawg Sep 16 '20 at 00:37
-
1@robertbristow-johnson I understand your happiness, though he may not be the only one ;-)))) [referring to my self of course] – Fat32 Sep 16 '20 at 00:39
-
-
//@Fat32 Duly noted, but not sufficient to trigger an editing change.// $$ $$ "Do I hang him? I think not and reverse a Custer decision." (Little Big Man, but i can't find a clip on Youtube.) – robert bristow-johnson Sep 16 '20 at 00:46
-
I'm rather surprised you use "bins" to describe DFT coefficients; in what sense is it a useful description? Whatever it is, does it outweigh how it misleads? The coefficients describe nothing at all about any non-integer frequencies; treating them as bins, some sort of a step function, implies otherwise. (Maybe it's the "official" version, but so is "assumes input periodicity") – OverLordGoldDragon Sep 17 '20 at 15:58
-
@OverLordGoldDragon I don't. I use "bin value" to describe a DFT spectrum coefficient. The DFT is a tranform (verb like). Using DFT as shorthand for the spectrum is what is misleading. I use "bin index", to indicate the location in the spectrum. Using "bin" means the whole kit-n-caboodle. This is similar to a variable in a programming language, it has a value and an address. The bin values define any non-integer frequency pure tones exactly. https://www.dsprelated.com/showarticle/773.php Something that was considered impossible until I came along. :-) – Cedron Dawg Sep 17 '20 at 16:11
-
I also like to arrange the bins on the unit circle to reflect the modular nature of the indexing. This introduces "bin angle" as well with units of radians per sample. – Cedron Dawg Sep 17 '20 at 16:23
-
Lots of math there, but whatever the end-result, it's wrong to call these "DFT frequencies", as DFT deals only with integer frequencies by definition. It may be DFT-like, or DTFT-like, but not DFT. On "bin values" - your very first paragraph states "values in the spectrum are called bins". If I understood your article, you intend "bin" as a DFT spectrum index, not value, which I suppose is better. -- Also, where can I see the gif of your latest update? – OverLordGoldDragon Sep 17 '20 at 16:47
-
@OverLordGoldDragon If we are getting that meticulous, "bin" can be used for any of its attributes according to context. To declare something "wrong" requires a little more than just your say so. I have the animated gif on my computer. I'll leave it as a programming exercise for anyone in general. That way you can add your own flair to it. – Cedron Dawg Sep 17 '20 at 16:54
-
The DFT unambiguously encodes and decodes the input signals in terms of orthogonal basis functions spanning integer frequencies; introducing non-integer frequencies fundamentally change the transform. If you can represent the non-integer frequencies in terms of DFT equivalents, that's another story, but your wording implies that non-integer frequencies have a place in the forward or inverse DFT. – OverLordGoldDragon Sep 17 '20 at 17:02
-
@OverLordGoldDragon If you want to put it in Linear Algebra terms, then you can consider it a "coordinate transform" from a "standard basis vector" in one representation to a "basis vector" in another. You should tone down your declarative language a bit, it is getting wearying and I am tired of quibbling about terminology. We've gotten the chat prompt, so I am done here. Have fun with the programming should you decide to try it. Feel free to post a representative frame as an answer here so I can see it. Your apparent goal an irreducible description is not worth it. – Cedron Dawg Sep 17 '20 at 17:12
-
To clarify, declarative language is appropriate for concepts (objective things), not terminology (subjecting things). – Cedron Dawg Sep 17 '20 at 17:24
-
1After re-skimming the third time now I admittedly still don't know whether you did what I asserted you did; by "non-integer" do you refer to
korf? My beef is with former, I've no problem with latter at all. If it is latter, my mistake. – OverLordGoldDragon Sep 17 '20 at 17:55 -
@OverLordGoldDragon You should read and study (not f'ing skim) the prior article. dsprelated.com/showarticle/771.php Pay particular attention to equation (16) which is the simplifying assumption that differentiates my bin value formulas from the corresponding DTFT values. This simplification is what allows the bin value formulas to be inverted for a frequency formula, something that can't be done with a sum of Dirichlet kernels. In my diagram above, the bin indices are in the circles. The outer circular scale is for f. The inner scale is radians ($\alpha$, $\beta_k$, $\phi$). – Cedron Dawg Sep 17 '20 at 20:04
-
And thus broke the ice under the F. You're right, I shouldn't lecture this confidently without reading everything first, but some risk for sake of saving time might be worth it; the exact topic doesn't currently interest me. Anyway, I'm cooking a thing on DFT coefficients, that partly argues in favor of "periodicity denialism" - will probably post today. – OverLordGoldDragon Sep 17 '20 at 20:13
-
@OverLordGoldDragon And how much do you value the time of those who either have to correct you or annoyance at letting a misstatement stand in your cost calculation? How much of my first answer in your other post was dedicated to correcting your rush jobs? Recommended read: "Zen and the Art of Motorcycle Maintenance" by Robert Pirsig. Not skimmable by any means. The periodicity argument isn't that important. It is a property of the DTFT and sampling, not inherent in the DFT. I really don't like to overrun the chat prompt. So, please. (Simply upvote the comment to acknowledge.) – Cedron Dawg Sep 17 '20 at 21:16
-
Now that's exaggerating; I merely spoke in words what others do in silence, with varying success rates. Regarding other post, I started it the only place I knew to start at the time, and worked with all solutions to resolve it. If anything, I can argue my time 'wasted' at correcting some basics of information theory, like
x[-1]being used,Y[0] != sum(x'[n]), and yourx(n)miracle machine. Surely everyone could see all these things with proper time invested, but that's impractical - we converse at all to avoid this to begin with. – OverLordGoldDragon Sep 17 '20 at 21:30 -
@OverLordGoldDragon Language will never perfectly convey meanings. Every chat overrun places a burden on the moderator. Sometimes there are multiple levels of meaning in a communication. Sometimes things won't be explained to you. That book recommendation should be considered a friendly gift. So, please, enough. You can find my email address in my bio should you feel the need. – Cedron Dawg Sep 17 '20 at 22:03


