4

The "N" is DFT is understood to be the number of data points in a given sequence or in other words the length of the sequence. We recently have had discussions here Indexing in DFT (from an old paper) and someone's old question How do I measure the time duration of a finite-length discrete sequence?. One of the popular symbolic versions of DFT is

$$ X(j)=\sum_{k=0}^{N-1} x(k) \exp \left(-i 2 \pi\left(\frac{j}{N}\right) k\right) $$

Suppose someone gives us the sequence consisting of N=11 points without telling us the total time or the sampling rate. If we apply DFT on it in MATLAB, the output is 11 points

Sequence

Notational problems start when we wish to determine the time interval $\Delta$t and the frequency step $\frac{1}{N\Delta t}$ when the $\Delta$t is revealed.

a) If we wish to determine the sampling frequency it is (N-1) points collected in 1 seconds. The last point belongs to the next cycle. The correct sampling rate is 10 Hz not 11.

b) The frequency resolution is shown to be $\frac{1}{N\Delta t}$. In order to get the correct frequency step, we to have to put $\frac{1}{10(0.1)}$ NOT $\frac{1}{11(0.1)}$.

Therefore, the frequency resolution, if we accept that N=11, $$\frac{1}{(N-1)\Delta t}$$ but nobody shows this formula.

It seems that we are using N in two ways

  1. N as the length of the sequence
  2. N when we have to determine the frequency step where actually it is one less than N to get the correct result.

A respected colleague says that N should be interpreted as the no of intervals not the number of points. This is inconsistent with defining N as the number of points in the sequence. Unfortunately, I cannot find any reference which says that N is the number of intervals.

How can we make this consistent?

Thanks.

Royi
  • 19,608
  • 4
  • 197
  • 238
AChem
  • 569
  • 4
  • 19
  • Am I accurate to interpret this question as "Why is frequency resolution defined as $(N \Delta t)^{-1}$ when 0.1Hz in my example makes more sense"? – OverLordGoldDragon Nov 22 '20 at 13:44
  • I have a problem with the notation rather. Is N=11 or 10 in the Table shown above? – AChem Nov 22 '20 at 13:47
  • N=11, unambiguously; $N = $ number of samples by definition, and you have 11 samples. I guess instead you ask what $M$ is in $(M \Delta t)^{-1}$ -- $N$ or $(N - 1)$? – OverLordGoldDragon Nov 22 '20 at 13:48
  • $f_s=10 \text{Hz}$ is correct here because $\Delta t = .1$, rather than anything to do with $N$, but I can help clarify why the $(N \Delta t)^{-1}$ definition for frequency resolution is used and why there's a distinction with duration. – OverLordGoldDragon Nov 22 '20 at 13:54
  • If we both agree N =11, then the notation shown by most textbooks becomes problematic because nobody uses M. In your notation M has to be N-1 in order to get the correct result, or it better be $\frac{1}{k\Delta t}$ – AChem Nov 22 '20 at 13:54
  • You cannot determine $f_s$ from $N$ alone. You can use $N$ to determine $\Delta t$, to then determine $f_s = 1/\Delta t$. – OverLordGoldDragon Nov 22 '20 at 13:55
  • Right, we need the time interval $\Delta t$ as well. – AChem Nov 22 '20 at 13:56
  • 2
    Note that a trivial answer, if you only seek consistency, is that "duration" here is 1.1sec, since $\Delta t = \text{Total duration} / N$. But this again is a different question than frequency resolution - but to spoil it, you do have a point, and resolution can be taken with $(N-1)$. What I offer is to show why $N$ is used and in which sense it's more accurate, and what using $(N - 1)$ instead entails. – OverLordGoldDragon Nov 22 '20 at 14:01
  • Okay, this makes a good point if we accept that the duration is indeed 1.1 sec not 1 sec. Please write your viewpoint as well. Let us use the given data in the table as an example and accept that N=11. The reason I am saying accept because a very well respected colleague says that N=10 in this table. – AChem Nov 22 '20 at 14:07
  • Regarding "intervals" your colleague is correct - see here; if it isn't intervals but points, your "duration" is zero. -- But if your colleague says N=10... s/he has some defining to do on what an "interval" is. -- I'll write my answer. – OverLordGoldDragon Nov 22 '20 at 14:08

4 Answers4

3

The key is to understand what the DFT says, vs what we seek. Consider a cosine, where we change $f \text[Hz]$, $N$, and $t$ and observe the effect on DFT:

  • [1]: DFT "sees" 1 cycle in the "analysis frame" (i.e. what we feed it), so nonzero at $k=1$, as expected.
  • [1] to [2]: we double our time duration without changing $f$ or $N$; DFT sees this as two cycles spanning the analysis frame, so $k=2$.
  • [1] to [3]: we double the physical frequency without changing $N$ or $t$; DFT sees this as two cycles spanning the frame.
  • [1] to [4]: we double the number of samples, $N$, without changing $f$ or $t$; DFT sees this as still 1 cycle spanning the frame; bin location, $k$, remains unchanged, but (unnormalized) correlation strength doubles (not relevant here).
  • [4] to [5]: now we also double duration, yielding two cycles in analysis frame.

You should be seeing a pattern. Without reading further, try to establish a relationship between $k$, $N$, $t$, and $f$. Hint: units.


Here's the deal: DFT has no idea what Hz, or physical frequency, is. All it knows is samples and cycles spanning the analysis frame. In [1], the "DFT frequency" is

$$ f_{\text{DFT}} = \frac{k}{N} = \frac{1 \text{ cycle}}{10 \text{ samples}} = .1 \left[ \frac{\text{cycles}}{\text{samples}} \right] $$

[2] = [3] = 2 cycles / 10 samples, [4] = 1 cycle / 20 samples, [5] = 2 cycles / 20 samples. Now let's take what we know about physical frequency, $f_p$ and DFT frequency, and relate them. In [2], DFT says $k=2$, but we know $f_p = 1$. It could also be (not shown in any [1]-[5]) $f_p=2$ and $k=1$. How to convert?

The unifying relation is:

\begin{align} f_p \left[ \frac{\text{cycles}}{\text{second}} \right] & = \left( f_{\text{DFT}} \left[ \frac{\text{cycles}}{\text{samples}} \right] \right) \cdot \left( f_s \left[ \frac{\text{samples}}{\text{second}} \right] \right) \end{align}

So, for [2]:

$$ f_{\text{DFT}} \cdot f_s = \left( \frac{2 \text{ cycles}}{10 \text{ samples}} \right) \cdot \left( \frac{10 \text{ samples}}{2 \text{ seconds}} \right) = 1 \left[ \frac{\text{cycles}}{\text{second}} \right] = 1\ \text{Hz} = f_p $$


But how to determine $f_s$?

By a simple definition, it's the reciprocal of sampling period, $\Delta t$, making everything above consistent. However, one must ask, if "sampling frequency" is defined as "# of samples / total duration", and "total duration" of

$$ [0, .1, .2, .3, .4, .5, .6, .7, .8, .9]\ \text{sec} $$

is clearly $0.9\ \text{sec}$, then isn't $f_s$ actually $.9 / 10 = 0.9\ \text{Hz}$? No; the duration is actually 1 sec. Here's why: $0.9\ \text{sec}$ here is actually the duration of something else entirely. Namely, "what is the duration of the signal?" can ask two things:

  1. For how long have we been sampling?
  2. How much time's worth of information is contained in our signal?

The answer to former is $0.9\ \text{sec}$, but to latter is $1\ \text{sec}$. Former computed via $(N-1)\Delta t$, latter via $N \Delta $, and if we insist on 0.9 for #2, we're saying that one sample holds no time-representative information, which implies all signals have duration of zero.

I clarify this with examples here. In a nutshell, the end-goal is description of information, not of process used to obtain it.


So what is the frequency resolution (rather DFT bin spacing)${}^{1}$?

It's defined as spacing between DFT bins, $df$; the answer depends on units of choice. For Hertz, per all of the above,

$$ df_p = \frac{1}{N \Delta t} \tag{1} $$

meaning, for [2], $k=1$ corresponds to $f_p = 0.5\ \text{Hz}$, $k=2$ corresponds to $f_p = 1\ \text{Hz}$, and so on. Alternatively, if you insist on defining duration via $(N-1)$, then it'll be per $(N-1)$ in Hertz, but not in DFT frequencies; latter is unambiguous:

$$ k=1 \rightarrow \frac{1\ \text{cycle}}{N\ \text{samples}} = \frac{1}{N} \left[ \frac{\text{cycles}}{\text{sample}} \right] $$

You can again convert between DFT frequency resolution and physical; taking [2], $\text{Duration} / N = 2 \text{ sec} / 10 = .2 \text{ sec}$, so bin spacing is

$$ df_p = \frac{1}{N \Delta t} = .5\ \text{Hz} $$

The spacing can change, but it's by redefining $\Delta t$ rather than changing $N$ to $(N - 1)$ in $(1)$. Suppose we say $\text{Duration} = 1.8\ \text{sec}$; then, $\Delta t = 0.18\ \text{sec}$, and

$$ df_p = \frac{1}{N \Delta t} = 0.\bar{5}\ \text{Hz} $$

So in [2], $k=1$ corresponds to $0.56\ \text{Hz}$, and $k=2$ corresponds to $1.1\ \text{Hz}$, which agrees with completing 2 cycles in 1.8 secs = 1.1 Hz.


Your specific example: $N=11$, $\Delta t = 0.1\ \text{sec}$:

$$ df_p = \frac{1}{N \Delta t} = \frac{1}{11 \cdot 0.1\ \text{sec}} = 0.909\ \text{Hz} $$

So $k=1$ corresponds to $0.909\ \text{Hz}$, not to 1Hz, since you've included a sample from the next cycle in the analysis frame.


1: NOTE: $df$ is DFT bin spacing, not "frequency resolution". DFT has perfect frequency resolution and no time resolution. But if you define it as discrimination of continuous-time frequencies, then the resolution and bin spacing are inversely-related (lesser spacing -> more bins -> more granular resolution). This is its own topic so I'll avoid clarifying in detail, feel free to open new q.

OverLordGoldDragon
  • 8,912
  • 5
  • 23
  • 74
  • Thanks for adding details. Do you think $df_p$ from my Table, as $\frac{1}{N\Delta t}$ of 1/(11)(0.1) is mathematically wrong? As per the other answer, it is rigorously correct. – AChem Nov 22 '20 at 20:29
  • @M.Farooq It's indeed correct, as I show below "Your specific example" and interpret in context of DFT. – OverLordGoldDragon Nov 22 '20 at 20:31
  • Thanks. And then this is an odd point DFT, the frequency spacing would be 0, 1/(11)(0.1), 2/(11)(0.1), until we reach 5/(11)(0.1)=4.54 Hz and there is no Nyquist frequency here (5 Hz). – AChem Nov 22 '20 at 20:39
  • 1
    @M.Farooq Correct, odd-point DFTs have the dc bin, and same number of positive and negative frequencies, neither of which is half of Nyquist (5.5 Hz actually). Evens, take 12, have 1 dc bin, 6 positives, and 5 negatives, and 6th positive is 6Hz = 12/2. – OverLordGoldDragon Nov 22 '20 at 20:42
  • The Nyquist in my Table should 10 Hz/2= 5 Hz. Why do you say it is 11 Hz? Once the sampling rate has been fixed, the Nyquist should remain constant regardless of the number of points. – AChem Nov 22 '20 at 20:54
  • 1
    @M.Farooq My mistake, Nyquist is 5Hz and $f_s=10Hz$. I had forgot how you defined $t$; 5Hz is correct. (But 5.5 is still DFT's Nyquist bin). – OverLordGoldDragon Nov 22 '20 at 20:58
3

I think this question comes down to the the concept of sampling, and how discrete samples relate to the continuous-domain signal they were obtained from. This question starts with the assumption that, if one has, for example, 8 samples (|), 1 second apart (----), the samples represent 7 seconds (the space in between the 8 samples):

  |----|----|----|----|----|----|----|

So let's split these 8 samples into two groups of 4 samples:

  |----|----|----|    |----|----|----|

Now we have two sets of samples each representing 3 seconds. 3 + 3 = 7?!? No, of course not!

If we have a sample spacing of 1 second, then each sample represents 1 second. The 8 samples represent 8 seconds, which we can divide into two sets of 4 samples each representing 4 seconds. 4 + 4 = 8. Our math holds! Our model thus should be:

  |----|----|----|----|----|----|----|----

or

  --|----|----|----|----|----|----|----|--

or however you want to place the sample within its interval.

In image processing, a pixel is usually represented as a little square. Each pixel takes up a certain space. But an image is just a 2D signal, and the relationship between samples and the continuous-domain signal they come from is identical to the 1D signal case. There really is no difference between the two. I have always found it strange that image-processing people have a hard time thinking of a digital image as a set of point samples, which is often a useful model. But now I see that always thinking of a digital signal as a set of point samples also can cause confusion.

Cris Luengo
  • 2,484
  • 1
  • 11
  • 25
2

FREQUENCY RESOLUTION and DFT BIN FREQUENCY SPACING are two different (but related) concepts.

In the following graph I have plotted, two and a half periods of a, 7-point DFT of a 7-point sequence x[n].

As the graphics speaks for itself, that the SPACING between each DFT sample (aka DFT bins) is given by:

$$ \Delta_\omega = \frac{2\pi}{N} \tag{1}$$

Where $N = 7$ is the number of samples in DFT $X[k]$.

This value is the discrete-time frequency spacing ($\omega$ in radian per sample) between consecutive DFT samples; mistakenly referred to as the DFT frequency-resolution through internet.

The continuous-time spacing between those frequency samples, in Hertz, is computed using the same formula, using the fact that the samples $X[0]$ and $X[7]$ (the first sample of the second period plotted in cyan) are separated by $F_s$, we have:

$$ \Delta_f = \frac{F_s}{N} \tag{2}$$

Also writing equation 2 in terms of the period $T_s = 1/F_s$ you get:

$$ \Delta_f = \frac{1}{N \cdot T_s} = \frac{1}{ \Delta t} \tag{3}$$

And this is the formula that you have mistakenly referred to as the "frequency resolution". No, it's not. It's just the DFT-bin frequency spacing in Hertz. And that value $\Delta t$ is NOT about the duration of the sequence, but just a consequence of the algebra there; yes the duration of $N$ samples is also $(N-1)\cdot T_s$; hence they are similar quantities. That's why the duration of the sequence may be used to get a shortcut into DFT bin frequency spacing.

enter image description here

Fat32
  • 28,152
  • 3
  • 24
  • 50
  • Thanks. Would you also add what is "frequency resolution" if we contrast it with "DFT BIN FREQUENCY SPACING." – AChem Nov 22 '20 at 17:06
  • I was also thrown off by that, thought I was missing some terminology - but noone's correcting this answer. In a way it does make sense, in that more DFT bins correspond to greater discrimination of continuous-time frequencies. – OverLordGoldDragon Nov 22 '20 at 17:07
  • 2
    Frequency Resolution does not have a precise formula or description. Rather qualitatively it's defined as the ability to distinguish two closest frequencies (borrowed from physics), and it's dependent on the duration of the observation and the type of windowing applied on it. You cannot get a sharp formula to express it. But the DFT bin Frequency spacing is a very clear and sharply defined concept. As arule of thumb: Frequency-Resolution is always worse than the DFT bin frequency spacing. Hence the DFT bin freuqency spacing gives an optimistic estimate of the max reolution attainable. – Fat32 Nov 22 '20 at 17:10
  • @Fat32 If it's as you define it then bin spacing and resolution are inversely-related; DFT of 1.5Hz cosine is better resolved by the cosine spanning 2 secs instead of 1, where latter would give two "frequencies" and former the one true one. – OverLordGoldDragon Nov 22 '20 at 17:14
  • This is also consistent with how frequency resolution is defined in a time-frequency representation like STFT, where fewer rows are troubled with conflating adjacent frequency bands. Yet in the sense of DFT mapping frequencies "as-is", at exact bins it's defined, it has perfect frequency resolution and no time resolution (alternatively time-res = length of analysis frame), so I agree on need for explicit distinction. – OverLordGoldDragon Nov 22 '20 at 17:25
  • @OverLordGoldDragon Let me give you an example. Assume an analog signal $x(t)$ of bandwidth $B$ Hz, is sampled at $F_s$ Hz. Let's obtain $N$ samples; over the the duration of observation $D = (N-1) Ts$. Now compute N-point DFT of those samples. Your DFT bin freq-spacing is $F_s/N$, your spectral-resolution (frequency resolution) say $\delta_f$ is limited by the window function applied and is less than the DFT bin-spacing. Now you can also compute 5N-point DFT of the same sequence; now your DFT binspacing is reduced by 5, but your true frequency-resolution is still the same $\delta_f$. – Fat32 Nov 22 '20 at 17:29
  • @Fat32, The signal duration as Marcus also said is $N\Delta t$ not $(N-1)\Delta t$. – AChem Nov 22 '20 at 17:47
  • @Fat32 Frequency resolution per row is the same but not of entire time-frequency representation; latter is greatly amplified, likewise for DFT. But yes, going by "standard" definition, bin spacing's not relevant. This is again its own topic, and I've acknowledged the distinction you're suggesting in an edit, while addressing OP's core question on $N$ vs $N-1$ - but if you insist on keeping the downvote, I'll justify mine by your answer not doing latter. – OverLordGoldDragon Nov 22 '20 at 17:47
  • @M.Farooq Fat32 was more accurate replying to me than in his answer, by clarifying "duration of observation" rather than "the duration". – OverLordGoldDragon Nov 22 '20 at 17:49
  • Okay, let us finalize it. Duration of observation is $N\Delta t$ and the duration is indeed $(N-1)\Delta t$, do we agree on that? – AChem Nov 22 '20 at 17:51
  • @M.Farooq The Duration of Observation is $(N-1)T_s$. There's no Duration of Samples, as Marcus defines. And the formula $N \cdot T_s$ does not have a descriptive name for it. BUT some people prefer also calling it as the duration of observation, eventhough it's one $T_s$ longer than the actual duration. Incidentally, DFT bin frequency spacing is 1/$N T_s$. And apart from pedantic examples, you may prefer any one of them as the duration of observation, or duration of the sequence. – Fat32 Nov 22 '20 at 18:10
  • @OverLordGoldDragon down-voting is not a weapon of threatening, nor is something you can use for your own sake. If an answer is correct, you cannot introduce awkward argumentations to downvote it. My answer is %100 correct. For its definitions, for its formulas, and for its graphics. Why would anyone, if not obsessive, downvote it? And I'm quite sorry but you cannot judge my accuracy... – Fat32 Nov 22 '20 at 18:16
  • @Fat32, In my simple table in the original post, the DFT BIN frequency spacing is $\frac{1}{(11)(0.1)}$ Hz and this is rigorously correct. Right? – AChem Nov 22 '20 at 18:18
  • @Fat32 I'm stating loudly what you and others on this network are doing quietly, except mine wasn't a baseless retaliation. – OverLordGoldDragon Nov 22 '20 at 18:20
  • 1
    @M.Farooq YES! you take N=11 samples at Fs=10 Hz, and compute N=11 point DFT, then the DFT bin freq-spacing is : $ \frac{1}{11 \times 0.1} = \frac{1}{N \times T_s}$ Hz. Rigorously correct ! – Fat32 Nov 22 '20 at 18:24
  • @Fat32, Let us suppose we had N=11 points obtained in 1 second. And this is the only information given. Our sampling interval would then be $\frac{1 }{(N-1)(1 s)}$. This is the only way to stay consistent with all the discussion and notation. – AChem Nov 22 '20 at 18:35
  • 1
    @M.Farooq Yes if $N$ samples are gathered on the time interval $[t_a , t_b]$ (including both ends) then your sampling-period is $T_s = \frac{ t_b - t_a}{N-1} $ . This is it. Now you answer: why don't you accept the corect answers (mine) in your two (this and previous) questions ? – Fat32 Nov 22 '20 at 18:38
  • @M.Farooq Firstly, I made a bit of a mishap in math in last section - now corrected to include your example. More importantly, I'm unsure you follow my reasoning as it'd make the mishap obvious; the answer is not $\frac{1}{(N-1)(1s)}$ or $\frac{1}{(N-1)(.1s)}$, and if Fat32 suggests otherwise he's very wrong. – OverLordGoldDragon Nov 22 '20 at 19:47
  • @Fat32 I'm unsure you realize that we agree that $df = 1/(N\cdot T_s)$ where $T_s = (t_{max} - t_{min})/(N - 1)$. Your answer makes no or pale attempt to show a connection between DFT and physical frequencies or correspondence between bin spacing and physical frequency spacing, instead focusing on a side-point of sampling resolution and definition of duration (latter being faulty I'll add). – OverLordGoldDragon Nov 22 '20 at 20:20
  • @OverLordGoldDragon Ok you finally have a point! Since you posted into my answer, I thought you were referring to my answer as being wrong. Otherwise, as I state again, $N$ point DFT of $N$ samples of $x[n]$ taken at $T_s = 1/F_s$ will have DFT bin frequency-spacing of $\delta_f = \frac{1}{N \cdot T_s}$. And the time duration between those samples (time between samples including the first and last) is $D = (N-1) \cdot T_s$. – Fat32 Nov 22 '20 at 20:27
  • @Fat32 I disagree with absolutely none of what you just said. But I do disagree with stating $(N-1)\cdot T_s$ is necessarily "the" duration for reasons described in my answer. – OverLordGoldDragon Nov 22 '20 at 20:29
  • @Fat32 In case you read it wrong I said "I agree with absolutely everything you just said". But if the part afterwards was too much, so be it. – OverLordGoldDragon Nov 22 '20 at 20:32
  • @Fat32 Well that's rather rash @ reading, but I can agree to retracting downvotes. – OverLordGoldDragon Nov 22 '20 at 21:04
1

You should really let go of the notion of a discrete signal being a sequence of periods. It's not. It's a sequence of numbers – nothing more, nothing less.

Notational problems start when we wish to determine the time interval $\Delta t$

exactly. Since that's not a property of a discrete signal.

a) If we wish to determine the sampling frequency it is (N-1) points collected in 1 seconds

That sounds wrong. To gather the first point, you already had to have signal before. If the signal was "suddenly" the value your sample describes, your signal wouldn't be band-limited and hence, sampling it has no sense, and the samples have no meaning, since the continuous-time signal might change arbitrarily between them.

So, all in all, the same I wrote to How do I measure the time duration of a finite-length discrete sequence? and to OverLord's questions stands:

Stop trying to assign the property "duration" to a sequence of numbers. It's just a sequence of numbers. As soon as you add the notion of these numbers representing a time-continuous signal, you need to take into account that this needs to be band-limited, and hence can't have a finite duration. In the context of the DFT as a tool to "measure" something over frequency, the DFT spectrum estimate only agrees with the continuous-time Fourier transform for the observed bandwidth if the signal is DFT-length periodic at the sampling instants. And then there's no question: the frame is $N\Delta t$ long, and any other length won't work.

Marcus Müller
  • 30,525
  • 4
  • 34
  • 58
  • Thanks, I had read your previous answer as well. I think this will help if we stop assigning a duration to the sequence of numbers. Just to confirm, A) the (time) frame in my Table above is 11* 0.1 seconds = 1.1 seconds not 1 second, i.e., I must say that 11 points have been sampled in 1.1 seconds. B) The N in DFT formula refers to number of points not the number of intervals. – AChem Nov 22 '20 at 15:50
  • 1
    A) it really corresponds to neither, the signal is infinitely long. But 1.1 s is certainly less wrong. B) yes, points. – Marcus Müller Nov 22 '20 at 15:51
  • What is N then in the DFT formula, if it is not the number of data points or the length of the sequence? – AChem Nov 22 '20 at 15:52
  • 1
    It's the number of points. I wrote that three times now. – Marcus Müller Nov 22 '20 at 15:53
  • 1
    Sorry, I wrote the comment when you just wrote " It corresponds to neither". My good colleague does not agree with N as the number of points but he calls it the number of intervals, but I cannot find any reference which says that it is number of intervals. N is the number of points and this is what I had gathered by screening at least 5 books on this subject. – AChem Nov 22 '20 at 15:56
  • 2
    tell your good colleague that he might still be a great colleague but is wrong about that. Nothing I can do to change math to accomodate the fact that the DFT deals with sequences of numbers, not intervals. – Marcus Müller Nov 22 '20 at 16:14
  • I think the biggest point which brings consistency in notation (with typical experimental data) is to accept the fact that it takes $N\Delta t$ or 1.1 sec not 1.0 sec, where the data in the table ends. I did not realize that counting could be that tricky in DSP. – AChem Nov 22 '20 at 16:27
  • 1
    @M.Farooq To be clear the DFT certainly deals with points not intervals; my earlier comment was regarding defining duration. – OverLordGoldDragon Nov 22 '20 at 16:39