In MATLAB, the outputs of the fft
and/or ifft
functions often require additional processing before being considered for analysis.
I have heard many differing opinions on what is correct:
Scaling
Mathworks states that
fft
andifft
functions are based on the following equations: \begin{align} X[k] &= \frac{1}{1} \cdot \sum_{n=1}^{N} x[n] \cdot e^{\frac{-j \cdot 2 \pi \cdot (k-1) \cdot (n-1)}{N}}, \quad\textrm{where}\quad 1\leq k\leq N\\ x[n] &= \frac{1}{N} \cdot \sum_{k=1}^{N} X[k] \cdot e^{\frac{+j \cdot 2 \pi \cdot (k-1) \cdot (n-1)}{N}},\quad \textrm{where}\quad 1 \leq n\leq N \end{align}Scaling by signal length
My peers typically scale the data by $\small \frac{1}{N}$ immediately after the processing the
fft
.
(We do not consider the rawfft
data before scaling.)%% Perform fft
X_f = fft(x, n_sample, 1) / n_sample; % fft must be normalized by the number of samples in the data. % This convention was set by the software developer (Mathworks).Is this correct?
- If so, why does the MATLAB
ifft
function expect that we have not scaled by $1/N$ already? - Is there a MATLAB
ifft
function or function option which does not automatically scale by $1/N$?
Alternatively, is there a better convention which we should be using in placing the $1/N$? For example, placing the $1/N$ in the
fft
rather than theifft
, or placing an $1/\sqrt{N}$ in both equations, instead of an $1/N$?- If so, why does the MATLAB
Scaling by sampling period
I have heard that the
fft
andifft
functions assume that the sampling period $T_{\rm sampling} = 1/f_{\rm sampling} = 1$, and that for the functions to be true, the following would need to apply:
\begin{align} X[k] &= \frac{1}{T_{\rm sampling}} \cdot \sum_{n=1}^{N} x[n] \cdot e^{\frac{-j \cdot 2 \pi \cdot (k-1) \cdot (n-1)}{N}},\quad \textrm{where}\quad 1 \leq k \leq N\\ x[n] &= \frac{T_{\rm sampling}}{N} \cdot \sum_{k=1}^{N} X[k] \cdot e^{\frac{+j \cdot 2 \pi \cdot (k-1) \cdot (n-1)}{N}},\quad\textrm{where}\quad 1 \leq n \leq N \end{align}
See links:
- Link 1 (see comment to Matt Szelistowski by Dr Seis)
- Link 2 (see answer by Rick Rosson vs that of Dr Seis)
- Link 3 (see comment by Matt (Message: 7/16) and comment by Poorya (14/16)
- Link 4 (see pg. 10, slide [1,1])
- Link 5 (see pg. 8+9) [it seems he is using inverse convention for fft and ifft].
Is this true?
I'm particularly piqued because I cannot find any DFT or DTFT equations on Wikipedia which include the sampling period.