I've been trying to find some places to help me better understand DFT and how to compute it but to no avail. So I need help understanding DFT and it's computation of complex numbers.
Basically, I'm just looking for examples on how to compute DFT with an explanation on how it was computed because in the end, I'm looking to create an algorithm to compute it.
Fourier transform (bottom) is zero except at discrete points. The inverse transform is a sum of sinusoids called Fourier series. Center-right column: Original function is discretized (multiplied by a Dirac comb) (top). Its Fourier transform (bottom) is a periodic summation (DTFT) of the original transform.
First, the DFT can calculate a signal's frequency spectrum. This is a direct examination of information encoded in the frequency, phase, and amplitude of the component sinusoids. For example, human speech and hearing use signals with this type of encoding.
x2[n]=1+cos(π4n)+sin(π2n) x 2 [ n ] = 1 + cos ( π 4 n ) + sin
A second argument to fft specifies a number of points n for the transform, representing DFT length: n = 512; y = fft(x,n); m = abs(y); p = unwrap(angle(y)); f = (0:length(y)-1)*100/length(y); subplot(2,1,1) plot(f,m) title('Magnitude') ax = gca; ax.
I assume 1D DFT/IDFT ...
All DFT's use this formula:
X(k)
is transformed sample value (complex domain)x(n)
is input data sample value (real or complex domain)N
is number of samples/values in your datasetThis whole thing is usually multiplied by normalization constant c
. As you can see for single value you need N
computations so for all samples it is O(N^2)
which is slow.
Here mine Real<->Complex domain DFT/IDFT in C++ you can find also hints on how to compute 2D transform with 1D transforms and how to compute N-point
DCT,IDCT by N-point
DFT,IDFT there.
Fast algorithms
There are fast algorithms out there based on splitting this equation to odd and even parts of the sum separately (which gives 2x N/2
sums) which is also O(N)
per single value, but the 2 halves are the same equations +/-
some constant tweak. So one half can be computed from the first one directly. This leads to O(N/2)
per single value. if you apply this recursively then you get O(log(N))
per single value. So the whole thing became O(N.log(N))
which is awesome but also adds this restrictions:
All DFFT's need the input dataset is of size equal to power of two !!!
So it can be recursively split. Zero padding to nearest bigger power of 2 is used for invalid dataset sizes (in audio tech sometimes even phase shift). Look here:
Complex numbers
c = a + i*b
c
is complex numbera
is its real part (Re)b
is its imaginary part (Im)i*i=-1
is imaginary unitso the computation is like this
addition:
c0+c1=(a0+i.b0)+(a1+i.b1)=(a0+a1)+i.(b0+b1)
multiplication:
c0*c1=(a0+i.b0)*(a1+i.b1)
=a0.a1+i.a0.b1+i.b0.a1+i.i.b0.b1
=(a0.a1-b0.b1)+i.(a0.b1+b0.a1)
polar form
a = r.cos(θ)
b = r.sin(θ)
r = sqrt(a.a + b.b)
θ = atan2(b,a)
a+i.b = r|θ
sqrt
sqrt(r|θ) = (+/-)sqrt(r)|(θ/2)
sqrt(r.(cos(θ)+i.sin(θ))) = (+/-)sqrt(r).(cos(θ/2)+i.sin(θ/2))
real -> complex conversion:
complex = real+i.0
[notes]
/=log2(N)
depends also on the recursion stopping condition)N=1 or 2
...N
is big)e^(i.x)=cos(x)+i.sin(x)
[edit1] Also I strongly recommend to see this amazing video (I just found):
It describes the (D)FT in geometric representation. I would change some minor stuff in it but still its amazingly simple to understand.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With