6
$\begingroup$

Suppose we have a total number N= 2048 points in a data and we wish to have zero centered Gaussian. There are two possibilities that we use the x-axis as

x1=[-1023:1:1024]; % x axis spans from -1023 to 1024 with 1 unit steps

x2=[-1024:1:1023]; % x axis spans from -1024 to 1023 with 1 unit steps

and if we make two zero centered Gaussians using these x values:

Gauss1=normpdf(x1,0, 10); % The syntax is normpdf(x, mean, standard deviation)


Gauss2=normpdf(x2,0,10);

and obtain their FTs as follows in MATLAB.

FFTGauss1=fft(Gauss1);
FFTGauss2=fft(Gauss2);

The real parts are identical and their magnitudes exactly match. For some reasons, the imaginary parts vary drastically. Why do we see large imaginary parts in one case and almost non-existent imaginary parts in the other? Thanks.

enter image description here

$\endgroup$
1

3 Answers 3

7
$\begingroup$

Answer : When $x_2 = [-1024:1:1023]$, then $x_2[n]$ satisfies the condition $x_2[n] = x_2[(N-n)\mod N]$. That is why when $x_2 = [-1024:1:1023]$, then the FFT is real and hence the imaginary part is $0$. If you see the scale of the $y$-axis for imaginary part of $x_2$ plot, it is of the order of $10^{-17}$ which is almost $0$ in MATLAB.

Detailed Explanation:

When $x \in \{-1024, -1023, -1022,..., 0, 1, 2, ..., 1023\}$, then you get the following mapping : $$\begin{array}{lcl}x[0] &=& {\rm gaussian}(-1024)\\ x[1] &=& {\rm gaussian}(-1023)\\ x[2] &=& {\rm gaussian}(-1022) \\ & \vdots\\ x[1024] &=& {\rm gaussian}(0)\\ x[1025] &=& {\rm gaussian}(1) \\ & \vdots \\ x[2047] &=& {\rm gaussian}(1023)\end{array}$$ Observe that $x[1] = x[2047] = x[(2048 - 1)\mod\ 2048]$, $x[2] = x[2046] = x[(2048 - 2)\mod \ 2048]$ and so on. This makes $x[n]$ real and symmetric mod $N$, which will in turn make $X[k]$ real and that is why you see that the imaginary part as $0$. MATLAB shows $0$ as values of the order of $10^{-17}$.

Do the same mapping for $x = [-1023:1:1024]$, and you will see that $x[n] \ne x[(N-n)\mod \ N]$ and hence imaginary part is not $0$.

$\endgroup$
5
$\begingroup$

You are simply seeing the effect of the time delay due to being offset by a half a sample (a delay in time is a linear phase in frequency). If you have an odd number of samples then you can implement what would be a non-causal zero-delay signal since you can have the same number of samples for positive time as negative time. If a signal is symmetric in one domain then it’s transform will be completely real in the other domain. Similarly, if a signal is anti-symmetric in one domain, it will be completely imaginary in the other domain. This is the reason causal time domain signals MUST be complex in frequency since a causal signal can be decomposed into the sum of a symmetric signal with an asymmetric signal.

If you offset a symmetric time domain signal by one sample then the phase in frequency will go from 0 to $-2\pi$ as your samples go from 0 to N-1 or DC to the sampling rate. For half a sample as I believe is the OP’s case the added phase would transition from 0 to $-\pi$.

To implement a complex Gaussian signal in time you would want to generate both the real and complex samples as independent random variables and the FT of this will also be complex Gaussian independent of sample delay effects.

$\endgroup$
3
$\begingroup$

Matlab has no notion of "negative time" for the FFT: it interprets the first sample of the time domain sequence to be at $t=0$

As far as Matlab is concerned your vectors are delayed Gaussians, delayed by either $D = 1023$ or $D = 1024$ samples. A delay in the time domain corresponds to multiplication in the frequency domain by $e^{-i \cdot 2 \pi \cdot D \cdot k/N}$ For D = 1024 that just happens to be a sequence of $[+1 -1 +1 -1 ...]$, i.e it stays real. For D = 1023, the imaginary part is not zero.

The correct way to do this, would be to circularly shift the Gaussians so that the center is at the first sample.

$\endgroup$
3
  • $\begingroup$ Thanks. Do you have a suggestion, how to apply circular shift on the zero centered Gaussian. I mean MATLAB has circshift (A, K). How should one choose K for N data-points? $\endgroup$
    – ACR
    Commented May 4, 2020 at 18:18
  • $\begingroup$ Look at ifftshift() mathworks.com/help/matlab/ref/ifftshift.html $\endgroup$
    – teeeeee
    Commented May 4, 2020 at 18:35
  • $\begingroup$ The circular shift array is working if I choose in the above case Gauss2=circshift(Gauss2, round(N/2)); What is the difference between circular shift vs. fftshift? They both achieve the center at the first sample. I think the problem arises whether N is even or odd. $\endgroup$
    – ACR
    Commented May 4, 2020 at 19:29

Your Answer

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

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