26
$\begingroup$

If I have a signal that is time limited, say a sinusoid that only lasts for $T$ seconds, and I take the FFT of that signal, I see the frequency response. In the example this would be a spike at the sinusoid's main frequency.

Now, say I take that same time signal and delay it by some time constant and then take the FFT, how do things change? Is the FFT able to represent that time delay?

I recognize that a time delay represents a $\exp(-j\omega t)$ change in the frequency domain, but I'm having a hard time determining what that actually means.

Practically speaking, is the frequency domain an appropriate place to determine the time delay between various signals?

$\endgroup$
3
  • 1
    $\begingroup$ It depends on what you mean by FFT. Say your original signal had $N$ time samples. Suppose the delay is $100$ samples. So now you have $N+100$ samples with the first $100$ being $0$. Are you computing the FFT of the first $N$ samples (same as before)? of the $N+100$ samples? of the last $N$ of the $N+100$ samples? The answer will depend on what you mean by FFT... $\endgroup$ Oct 26, 2011 at 13:37
  • 1
    $\begingroup$ @Dilip I'm looking for a more general answer. Perhaps an explanation of what would change in those scenarios would be helpful? $\endgroup$
    – gallamine
    Oct 26, 2011 at 17:12
  • 1
    $\begingroup$ If you pass the last $N$ of the $N+100$ samples to your $N$-point FFT subroutine, you will get the same FFT as you got before. No difference whatsoever. If you pass the first $N$ of the $N+100$ samples (with the first $100$ samples being $0$) to your $N$-point FFT subroutine, you will get things that are difficult to interpret. Read the Answer by @JasonR carefully which tells you that if the first $100$ samples are filled from your data via a circular or cyclic shift, then you will see the delay reflected in the phase of the samples. $\endgroup$ Oct 26, 2011 at 17:22

4 Answers 4

27
$\begingroup$

The discrete Fourier transform (DFT), commonly implemented by the fast Fourier transform (FFT), maps a finite-length sequence of discrete time-domain samples into an equal-length sequence of frequency-domain samples. The samples in the frequency domain are in general complex numbers; they represent coefficients that can be used in a weighted sum of complex exponential functions in the time domain to reconstruct the original time-domain signal.

These complex numbers represent an amplitude and phase that is associated with each exponential function. Thus, each number in the FFT output sequence can be interpreted as:

$$ X[k] = \sum_{n=0}^{N-1} x[n] e^{\frac{-j 2 \pi n k}{N}} = A_k e^{j \phi_k} $$

You can interpret this as follows: if you want to reconstruct x[n], the signal that you started with, you can take a bunch of complex exponential functions $e^{\frac{j 2 \pi n k}{N}}, k = 0, 1, \ldots, N-1$, weight each one by $X[k] = A_k e^{j \phi_k}$, and sum them. The result is exactly equal (within numerical precision) to $x[n]$. This is just a word-based definition of the inverse DFT.

So, speaking to your question, the various flavors of the Fourier transform have the property that a delay in the time domain maps to a phase shift in the frequency domain. For the DFT, this property is:

$$ x[n] \leftrightarrow X[k] $$ $$ x[n-D] \leftrightarrow e^{\frac{-j2 \pi k D}{N}}X[k] $$

That is, if you delay your input signal by $D$ samples, then each complex value in the FFT of the signal is multiplied by the constant $e^{\frac{-j2 \pi k D}{N}}$. It's common for people to not realize that the outputs of the DFT/FFT are complex values, because they are often visualized as magnitudes only (or sometimes as magnitude and phase).

Edit: I want to point out that there are some subtleties to this rule for the DFT due to its finiteness in time coverage. Specifically, the shift in your signal must be circular for the relation to hold; that is, when you delay $x[n]$ by $D$ samples, you need to wrap the last $D$ samples that were at the end of $x[n]$ to the front of the delayed signal. This wouldn't really match what you would see in a real situation where the signal just doesn't start until after the beginning of the DFT aperture (and is preceded by zeros, for example). You can always get around this by zero-padding the original signal $x[n]$ so that when you delay by $D$ samples, you just wrap around zeros to the front anyway. This relationship only applies to the DFT since it is finite in time; it's does not apply to the classic Fourier transform or discrete-time Fourier transform.

$\endgroup$
3
$\begingroup$

Gallamine,

This simply means that there will be a phase offset in your FFT vector. When you FFT your (real) signal, your answer will be complex, so you will have real, and imaginary part. If you took their phase, (inverse_tangent(imag/real)), this will display all the phases of the frequencies. The way their phases differ from if you had no delay is related directly to the delay you have in time.

(In matlab you can also get the phase by simply "angle(fft_result)").

By the way if you do a correlation of your signal with delay and without delay and pick the peak, you can get the delay in that way. In the freq-domain it is subtracting all the phases of your signal with no delay, from all the signal with delay, and taking the average.

$\endgroup$
3
  • 4
    $\begingroup$ There are too many things left unsaid and unspecified in this answer. Mohammad is essentially assuming a circular shift of the data without saying so. See @JasonR's (edited) answer for a careful description of this point, and my comment on the main question saying that there are many ways of using the FFT and they all give different results $\endgroup$ Oct 26, 2011 at 17:27
  • 1
    $\begingroup$ @DilipSarwate is right, this is assuming a circular shift of data. As he pointed out there are subtleties in the FFT based on the input vector. $\endgroup$
    – Spacey
    Oct 26, 2011 at 17:50
  • 1
    $\begingroup$ @gallamine, may I ask what your data vectors looks like, exmaple: - Signal1: [someZeros, signal, someZeros] - Signal2: [someDifferentNumberOfZeros, signal, someDifferentNumberOfZeros] $\endgroup$
    – Spacey
    Oct 26, 2011 at 17:53
2
$\begingroup$

Consider the signal $\sin(\omega t)$, it has frequency content $\omega$. Delayed by 1 sec. the signal will be same so same frequency content but our time t=0 has already started 1 sec before so waveform will only shift by 1 sec right i.e phase not frequency component.

As one can see from equation $G(w) = e^{-j\omega t}$ will cause only a phase change in a circular fashion so that whatever delay is there wrt T of the original signal.

$\endgroup$
1
  • 1
    $\begingroup$ Hi aman. Welcome to Signals.SE. Could you take a little time and format your answer a bit? We have MathJax enabled, which we generally prefer for equations. I did a quick partial edit that has a few examples if you haven't used it before. Thanks for your contribution, and again, welcome to the site! $\endgroup$
    – datageist
    Aug 22, 2018 at 22:26
1
$\begingroup$
  1. When a time-shift is applied to a signal, it only changes the angles in the DFT coefficients.

  2. In turn, the time-shift used can determined by observing how the spectral line angles have been changed according to their index $k$.


Experiment

(I'm using the general term DFT, the transform implemented by FFT algorithm.)

The following plots show a signal, its DFT magnitude and angle, and the same for a shifted version.

enter image description here

enter image description here

This answers your first question: Time-shifting a signal results in a change of phase in the spectral lines.

For the second question, how to determine the time-shift from the DFT, let's look at how the time-shift changes the DFT.

A phase shift is a multiplication by a complex exponential

As you mentioned, a change of phase is a multiplication by a complex exponential. This is consistent with the the relationship:

$$\cos(\omega t + \varphi) = \Re \{ e^{j (\omega t + \varphi) } \} = \Re \{ e^{j \omega t}e^{j\varphi} \}$$

where adding $\varphi$ and multiplying by $e^{j\varphi}$ are equivalent.

Time-shift DFT pair

This pair of formulas relates the effect of time-shifting in the time-domain and in the frequency-domain:

$$y[n]=x[((n-n_{d}))_{N}]\overset{\textrm{DFT}}{\longleftrightarrow}Y[k]=e^{-j\frac{2\pi k}{N}n_{d}}X[k]$$

for a signal of length $N$ and a shift of $n_d$ samples.

Angle increase is different for each spectral line

To get the DFT of a shifted signal the DFT of the unshifted signal $X[k]$ is multiplied by $e^{-j\frac{2\pi k}{N}n_{d}}$.

Let's note $\frac{2\pi k}{N}n_{d}$ is a value proportional both to:

  • The ratio $n_d/N$. This determines a constant angle value.
  • The index of the spectral line $k$. Since the phase angle corresponding to a given time is proportional to the frequency, this angle increases for each spectral line.

This multiplication by a variable factor applies the same amount of time-shift to all spectral lines, and thus the whole signal is consistently time-shifted.

Now if the angles for the original signal are subtracted from the angles for the shifted signal, the result is an arithmetical progression with a common difference $p_d$:

enter image description here

Getting the time-shift $n_d$ from the common difference:

$$n_d = -\frac {N} {2 \pi}p_d$$

Application

This piece of Python code plots the images above and computes the time delay:

import numpy as np
import scipy.fft as sf
import matplotlib.pyplot as plt

# Generate a signal delayed or not
def signal_gen(length, delay=0, aliasing=False):
    indices = np.arange(-delay, -delay+length)
    if aliasing: indices = indices % length
    values = np.linspace(1, 0, length) ** 2 + 0.2
    xn = np.where((indices<0) | (indices>=length), 0, values[indices])
    return xn

# Plot signal
def plot(xn, Xk, title='Signal', unwrap=False):
    # Plot signal
    fig, axes = plt.subplots(ncols=3, squeeze=True, figsize=(8, 2.5), layout='constrained')
    ax = axes[0]
    ax.set_title(title)
    ax.stem(xn)

    # Plot DFT magnitude
    ax = axes[1]
    ax.set_title('DFT magnitude')
    ax.stem(abs(Xk))

    # Plot DFT angle
    ax = axes[2]
    ax.set_title('DFT angle')
    angles = np.angle(Xk)
    if unwrap: angles = np.unwrap(angles)
    ax.stem(angles)

N = 9 # number of samples to create
nd = 4 # time-delay in samples

# Original and time-shifted signals
xn = signal_gen(N, 0)
xn_s = signal_gen(N, nd, aliasing=True)

# Plot
Xk, Xk_s = [sf.fft(signal) for signal in [xn, xn_s]]
plot(xn, Xk, title='Unshifted signal')
plot(xn_s, Xk_s, title='Time-shifted signal')

# Phase differences between DFT of shifted and unshifted signals
phase_wrapped = np.angle(Xk_s) - np.angle(Xk)
phase = np.unwrap(phase_wrapped)

# Print wrapped and unwrapped phase differences and increments
print(np.array2string(phase_wrapped, formatter={'float_kind': lambda x: "%.2f" % x}))
print(np.array2string(phase, formatter={'float_kind': lambda x: "%.2f" % x}))
print(np.array2string(np.diff(phase), formatter={'float_kind': lambda x: "%.2f" % x}))

# Compute time-delay
pd = phase[1]-phase[0]
nd2 = -N * pd / (2*np.pi)
print(f'nd = {nd2:.2f}')

It outputs

  • The change in angles between DFT

    [0.00 3.49 0.70 -2.09 1.40 -1.40 2.09 -0.70 -3.49]

  • The same angles unwrapped to show the increase

    [0.00 -2.79 -5.59 -8.38 -11.17 -13.96 -16.76 -19.55 -22.34]

  • The first differences

    [-2.79 -2.79 -2.79 -2.79 -2.79 -2.79 -2.79 -2.79]

The time-delay as a number of samples is determined from the phase increment $p_d=-2.79$:

nd = 4.00


You may want to read about the shift theorem.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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