real time fft for complex signal form
Hi bcosta,
first of all thank you very much for your long well explained reply. In addition to that i will state a few para and try to conclude a solution which might be thrilling.
i adding this concept because i have struggled to get this concept.
If your input signal is real and even (i.e. symmetric around zero, such that s(t) = s(-t)), then the spectrum will be real and even -- so you
don't even have to worry about those imaginary parts. (that is imaginary parts should be zero when U do fft i.e., freq domain sample values)
If your input signal is real and odd (i.e. anti-symmetric around zero, such that s(t) = -s(t)), then the spectrum will be purely imaginary and
off -- so you don't have to worry about those real parts. (that is real should be zero when U do fft i.e., freq domain sample values)
If your input signal is just plain real, without necessarily being odd or
even, then you can decompose it to an even part and an odd part .Then from the above two statements, the spectrum will be even in it's real part, and odd in it's imaginary part in other words, the it'll have conjugate symmetry around zero.
In short, Symmetry comes about due to the use of a complex exponential in the DFT .
If you have a N point real valued input waveform, your samples are the real valued inputs to the DFT or FFT, and the imaginary parts are set
to zero. After forward transforming it, you get N outputs that display some symmetry (e.g.: with N even, outputs 0 and N/2 will be real and unique, and outputs 1 to N/2-1 will be conjugate symmetric
with outputs N-1 to N/2+1).
That s why it is enough if we compute ceil(N+1)/2 without computing N-point DFT. (saving 50% dft computations , also memory storage)
As it displays conjugate symmetry of the spectrum that is in the range 0 to N/2.
1. when U take real & even signal (say cosine)& compute fft , freq domain values should not contain imaginary part. spectrum should also be real & even
2. When U take real & odd signal (say sine)& compute fft, freq domain values should not contain real part. spectrum should also be real & even
but in your code say real and odd signal, fft values produces real part as well even though it exhibit conjugate spectrum from N/2+1 to N-1.
So to avoid the real part in freq domain one has to follow DFT circular symmetry
i.e., for real odd signal for N (=even/odd value)
x[N-n] = - x[N] ;
also note: for even N especially for real-odd signal
X[p] DELf
X[0] DC ( zero freq) ===> 0
X[1] DEL f
X[2] 2 DEL f
X[3] 3 DEL f
X[4] 4 DELf (Nyquist frequency)===>0
X[5] –3 DEL f
X[6] –2 DEL f
X[7] –DEL f
For N = 8, X[1] and X[7] have the same magnitude(but complex conjugatein exist making real vlues to zero); X[2] and X[6] have the same magnitude; (but complex conjugatein exist making real vlues to zero); and X[3] and X[5] have the same magnitude. (but complex conjugatein exist making real vlues to zero); The difference is that X[1], X[2], and X[3] correspond to positive frequency components, while X[5], X[6], and X[7] correspond to negative frequency components. X[4] is at the Nyquist frequency. A representation where you see the positive and negative frequencies is the
two-sided transform. It is symmetric with respect to nyquist freq.
If incase N=7 (odd)
X[p] DEL f
X[0] DC ===> 0
X[1] DEL f
X[2] 2DEL f
X[3] 3DEL f
X[4] –3DELf
X[5] –2DELf
X[6] –DEL f
For N = 7, X[1] and X[6] have the same magnitude; (but complex conjugatein exist making real vlues to zero); X[2] and X[5] have the same magnitude; (but complex conjugatein exist making real vlues to zero); and X[3] and X[4] have the same magnitude. (but complex conjugatein exist making real vlues to zero); However, X[1], X[2], and X[3] correspond to positive frequencies, while X[4], X[5], and X[6] correspond to negative frequencies. Because N is odd, there is no component at the Nyquist frequency.
one would normally expect zero padding at the end.
(DFT CIRCULAR SYMMERTRICITY IS BROKEN)
but if do so, then real values do occur at the freq domain sample values of REAL -ODD SIGNAL.
INSTEAD PAD symmetrically. ( AT THE CENTRE)
X[0] DC ===> 0
X[1] DEL f
X[2] 2DEL f
X[3] 3DEL f
X[4] 4DEL f nyquist freq ==> 0
X[5] –3DELf
X[6] –2DELf
X[7] –DEL f
For example,
1. the array [1 2 3 8 3 2] is a real-even signal , where "1" is the zero-
frequency (DC) element, "8" is the Nyquist element, and "2 3" and "3
2" are the symmetric positive and negative frequency amplitudes,
respectively. To pad it symmetrically to length 8 ,you would do [1 2 3 4 0 4 3 2],
where the Nyquist frequency "8" has been split equally between
positive and negative frequencies.
if u want to compute N=16-point DFT. then the padded symmetrical array will look like
[1 2 3 4 0 0 0 0 0 0 0 0 0 4 3 2] so being padded symmetrically we can compute DFT for 0 to N/2. in matlab ceil(N+1)/2.
2. As per theory, 0th and nyquist component is made zero (for real-odd signal)
so real-odd signal with (N even) will {0, 10, 20,40,0,-40,20,-10}.
suppose if needs to do padding for N=16.
padded real-odd signal would be
{0, 10, 20,40,0,0,0,0,0,0,0,0,0,-40,20,-10}.
with (N+1)/2 data points are unique points. rest is redundant
symmetric.
So that we wont get real part WHEN WE DO FFT OF REAL-ODD SIGNALS.
I WILL TELL U WITH EXAMPLE CODE:
code:
time_signal=sin(linspace(0, 1, 10)*2*pi);
time_signal =
Columns 1 through 8
0 0.6428 0.9848 0.8660 0.3420 -0.3420 -0.8660 -0.9848
Columns 9 through 10
-0.6428 -0.0000
HERE IT DOESN'T EXHIBIT DFT CIRCULAR SYMMETRICITY.
SO CHANGE THE CODE LIKE THIS:
time_signal=sin(linspace(0, 1, 10)*2*pi);
N=length(time_signal);
time_signal=[time_signal(1:N/2) time_signal(N) time_signal(N/2+1:N-1) ];
freq_signal = fft(time_signal);
time_signal =
Columns 1 through 8
0 0.6428 0.9848 0.8660 0.3420 -0.0000 -0.3420 -0.8660
Columns 9 through 10
-0.9848 -0.6428
freq_signal =
Columns 1 through 5
-0.0000 -0.0000 - 4.6782i -0.0000 - 0.7117i 0.0000 + 0.3026i -0.0000 - 0.1276i
Columns 6 through 10
0.0000 -0.0000 + 0.1276i 0.0000 - 0.3026i -0.0000 + 0.7117i -0.0000 + 4.6782i
SEE THE REAL PART IS ZERO OFCOURSE AS PER THEORY (IT IS
BECAUSE OF DFT CIRCULAR SYMMETRIC)
IT IS ENOUGH IF WE CALCULATE DFT COMPUTATION FOR CEIL(N+1)/2 [ in matlab, as it
process the array from number 1 onwards ]
FOR BOTH N=EVEN CASE & N=ODD CASE
iN CASE OF REAL-EVENSIGNAL ( SAY CAUSE SIGNAL THE ZEROTH (DC COMPONENT) AS
WELL AS NYQUIST FREQ (N/2) SHOULD BE REAL (ANY ARBITRARY VALUE).
FINALLY, IF x[n] is made or padded symmetrically (i.e., if it follows dft symmetry)
one wont get real part in X[k] when x[n] is real & odd signal.spectrum will exhibit conjugate symmetric
from (N/2+1) to (N-1)
one wont get imaginary part in X[k] when x[n] is real & even signal.
spectrum will exhibit symmetric from (N/2+1) to (N-1)
it is enough if we compute dft for 0 to N/2.
happy learning