Forums

Scilab Inverse FFT

Started by Richard Owlett November 11, 2003
How do I perform an inverse FFT in Scilab?

Richard Owlett <rowlett@atlascomm.net> wrote:

> How do I perform an inverse FFT in Scilab?
y=fft(x,-1) perfom an FFT and y=fft(x,1) perform a inverse FFT
Richard Owlett <rowlett@atlascomm.net> wrote in message
news:<vr2fmckbrtq1c9@corp.supernews.com>...
> How do I perform an inverse FFT in Scilab?
I don't know. But if you manage to do the forward FFT in scilab, you can use the same routine to compute the ifft like this: x = fft(conj(X)); where x is in time domain and X is in frequency domain. You would need to scale the result properly. I'd guess that you need to divide by N, the length of X, to get everything right. To check, try this: xx=1/N*fft(conj(fft(x))); for some x of length N. When everything works out correctly, real(xx) eqauals x. Rune
On 11 Nov 2003 14:25:19 -0800, allnor@tele.ntnu.no (Rune Allnor)
wrote:

>Richard Owlett <rowlett@atlascomm.net> wrote in message
news:<vr2fmckbrtq1c9@corp.supernews.com>...
>> How do I perform an inverse FFT in Scilab? > >I don't know. But if you manage to do the forward FFT in scilab, >you can use the same routine to compute the ifft like this: > > x = fft(conj(X)); > >where x is in time domain and X is in frequency domain. >You would need to scale the result properly. I'd guess >that you need to divide by N, the length of X, to get everything >right. To check, try this: > >xx=1/N*fft(conj(fft(x))); > >for some x of length N. When everything works out correctly, >real(xx) eqauals x. > >Rune
Hi Rune, I'm trying to recall, isn't it: x = conj(fft(conj(X))) ?? Richard can also try: 1. Swap real and imag parts of each X(m) freq-domain sample to get sequence X'(m). 2. Take forward FFT of X'(m) to yield x'(n). 3. Swap real and imag parts of each x'(n) sample to get the desired time sequence x(n). [I learned this last scheme here on comp.dsp!] There's a 3rd technique, but it's not nearly as simple as the above two schemes. See Ya, [-Rick-]
Rick Lyons wrote:

   ...
> There's a 3rd technique, but it's not nearly as > simple as the above two schemes.
Besides, it's too long to fit the ....
> > See Ya, > [-Rick-]
Jerry -- Engineering is the art of making what you want from things you can get. &#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;
ricklyon@REMOVE.onemain.com (Rick Lyons) wrote in message
news:<3fb3fc88.46575921@news.west.earthlink.net>...
> On 11 Nov 2003 14:25:19 -0800, allnor@tele.ntnu.no (Rune Allnor) > wrote: > > >Richard Owlett <rowlett@atlascomm.net> wrote in message
news:<vr2fmckbrtq1c9@corp.supernews.com>...
> >> How do I perform an inverse FFT in Scilab? > > > >I don't know. But if you manage to do the forward FFT in scilab, > >you can use the same routine to compute the ifft like this: > > > > x = fft(conj(X)); > > > >where x is in time domain and X is in frequency domain. > >You would need to scale the result properly. I'd guess > >that you need to divide by N, the length of X, to get everything > >right. To check, try this: > > > >xx=1/N*fft(conj(fft(x))); > > > >for some x of length N. When everything works out correctly, > >real(xx) eqauals x. > > > >Rune > > Hi Rune, > > I'm trying to recall, isn't it: > > x = conj(fft(conj(X))) ??
It could very well be. Although Richard didn't say so, I assumed the result of the IFFT to be a real-valued signal, in which case the outer conj shouldn't matter... or am I too quick in dismissing that now...? Rune
> Richard can also try: > > 1. Swap real and imag parts of each X(m) freq-domain > sample to get sequence X'(m). > 2. Take forward FFT of X'(m) to yield x'(n). > 3. Swap real and imag parts of each x'(n) sample > to get the desired time sequence x(n). > > [I learned this last scheme here on comp.dsp!] > > There's a 3rd technique, but it's not nearly as > simple as the above two schemes. > > See Ya, > [-Rick-]
Rune Allnor wrote:

> ricklyon@REMOVE.onemain.com (Rick Lyons) wrote in message
news:<3fb3fc88.46575921@news.west.earthlink.net>...
> >>On 11 Nov 2003 14:25:19 -0800, allnor@tele.ntnu.no (Rune Allnor) >>wrote: >> >> >>>Richard Owlett <rowlett@atlascomm.net> wrote in message
news:<vr2fmckbrtq1c9@corp.supernews.com>...
>>> >>>>How do I perform an inverse FFT in Scilab? >>> >>>I don't know. But if you manage to do the forward FFT in scilab, >>>you can use the same routine to compute the ifft like this: >>> >>> x = fft(conj(X)); >>> >>>where x is in time domain and X is in frequency domain. >>>You would need to scale the result properly. I'd guess >>>that you need to divide by N, the length of X, to get everything >>>right. To check, try this: >>> >>>xx=1/N*fft(conj(fft(x))); >>> >>>for some x of length N. When everything works out correctly, >>>real(xx) eqauals x. >>> >>>Rune >> >>Hi Rune, >> >> I'm trying to recall, isn't it: >> >>x = conj(fft(conj(X))) ?? > > > It could very well be. Although Richard didn't say so, I assumed the > result of the IFFT to be a real-valued signal,
I was _assuming_ it would be real. the sequence roughly would be .WAV(real) --> FFT --> manipulate in freq domain --> IFFT --> real output(?) Caveat doctor -- I'm just learning scilab and over thirty years since I attempted a BSEE ;)
> in which case the outer > conj shouldn't matter... or am I too quick in dismissing that now...? > > Rune > > >>Richard can also try: >> >>1. Swap real and imag parts of each X(m) freq-domain >> sample to get sequence X'(m). >>2. Take forward FFT of X'(m) to yield x'(n). >>3. Swap real and imag parts of each x'(n) sample >> to get the desired time sequence x(n). >> >>[I learned this last scheme here on comp.dsp!] >> >>There's a 3rd technique, but it's not nearly as >>simple as the above two schemes. >> >>See Ya, >>[-Rick-]
Richard Owlett <rowlett@atlascomm.net> wrote in message
news:<vr9di0n910g23e@corp.supernews.com>...
> Rune Allnor wrote: > > > ricklyon@REMOVE.onemain.com (Rick Lyons) wrote in message
news:<3fb3fc88.46575921@news.west.earthlink.net>...
> > > >>On 11 Nov 2003 14:25:19 -0800, allnor@tele.ntnu.no (Rune Allnor) > >>wrote: > >> > >> > >>>Richard Owlett <rowlett@atlascomm.net> wrote in message
news:<vr2fmckbrtq1c9@corp.supernews.com>...
> >>> > >>>>How do I perform an inverse FFT in Scilab? > >>> > >>>I don't know. But if you manage to do the forward FFT in scilab, > >>>you can use the same routine to compute the ifft like this: > >>> > >>> x = fft(conj(X)); > >>> > >>>where x is in time domain and X is in frequency domain. > >>>You would need to scale the result properly. I'd guess > >>>that you need to divide by N, the length of X, to get everything > >>>right. To check, try this: > >>> > >>>xx=1/N*fft(conj(fft(x))); > >>> > >>>for some x of length N. When everything works out correctly, > >>>real(xx) eqauals x. > >>> > >>>Rune > >> > >>Hi Rune, > >> > >> I'm trying to recall, isn't it: > >> > >>x = conj(fft(conj(X))) ?? > > > > > > It could very well be. Although Richard didn't say so, I assumed the > > result of the IFFT to be a real-valued signal, > > I was _assuming_ it would be real. > the sequence roughly would be > .WAV(real) --> FFT --> manipulate in freq domain --> IFFT --> real > output(?)
In that case the output will be real-valued but represented by complex- valued numerics, i.e. the imaginary parts of the numbers are of vanishing magnitudes. This assumes that you are careful about the symmetry properties of real-valued signals in f domain: X(-f) = conj(X(f)). Now, you could half the work and take away some book-keeping drudgery by manipulating only the "useful" half-band ( f = [0,fs/2>, fs is sampling frequency ). Set the remaining half-band ( f= [fs/2, fs> ) to zero and compute the complex IDFT to find z(n) (complex-valued) in time domain. Then, reconstruct the real-valued time domain signal x(n) as x(n)=2*real(z(n)). Rune
Rune Allnor wrote:
> Richard Owlett <rowlett@atlascomm.net> wrote in message
news:<vr9di0n910g23e@corp.supernews.com>...
> >>Rune Allnor wrote: >> >> >>>ricklyon@REMOVE.onemain.com (Rick Lyons) wrote in message
news:<3fb3fc88.46575921@news.west.earthlink.net>...
>>> >>> >>>>On 11 Nov 2003 14:25:19 -0800, allnor@tele.ntnu.no (Rune Allnor) >>>>wrote: >>>> >>>> >>>> >>>>>Richard Owlett <rowlett@atlascomm.net> wrote in message
news:<vr2fmckbrtq1c9@corp.supernews.com>...
>>>>> >>>>> >>>>>>How do I perform an inverse FFT in Scilab? >>>>> >>>>>I don't know. But if you manage to do the forward FFT in scilab, >>>>>you can use the same routine to compute the ifft like this: >>>>> >>>>>x = fft(conj(X)); >>>>> >>>>>where x is in time domain and X is in frequency domain. >>>>>You would need to scale the result properly. I'd guess >>>>>that you need to divide by N, the length of X, to get everything >>>>>right. To check, try this: >>>>> >>>>>xx=1/N*fft(conj(fft(x))); >>>>> >>>>>for some x of length N. When everything works out correctly, >>>>>real(xx) eqauals x. >>>>> >>>>>Rune >>>> >>>>Hi Rune, >>>> >>>> I'm trying to recall, isn't it: >>>> >>>>x = conj(fft(conj(X))) ?? >>> >>> >>>It could very well be. Although Richard didn't say so, I assumed the >>>result of the IFFT to be a real-valued signal, >> >>I was _assuming_ it would be real. >>the sequence roughly would be >>.WAV(real) --> FFT --> manipulate in freq domain --> IFFT --> real >>output(?) > > > In that case the output will be real-valued but represented by complex- > valued numerics, i.e. the imaginary parts of the numbers are of vanishing > magnitudes. This assumes that you are careful about the symmetry > properties of real-valued signals in f domain: X(-f) = conj(X(f)). > > Now, you could half the work and take away some book-keeping drudgery > by manipulating only the "useful" half-band ( f = [0,fs/2>, fs is > sampling frequency ). Set the remaining half-band ( f= [fs/2, fs> ) to > zero and compute the complex IDFT to find z(n) (complex-valued) in time > domain. Then, reconstruct the real-valued time domain signal x(n) as > > x(n)=2*real(z(n)). > > Rune
I don't know if Scilab hides something from me, but both Rune's and Rick's approach give the same answer in a test case (using ding.wav as input). Also, using Scilab syntax f = fft(x,1) // do forward transform of x Someone said I could do x2 = fft(f,-1) // Scilab docs say this does *NOT* do an IFFT but just changes sign of an exponent It however gives the same result as Rune or Rick scaled by number of samples.
On 14 Nov 2003 02:04:49 -0800, allnor@tele.ntnu.no (Rune Allnor)
wrote:

  (snipped)
>> >> Hi Rune, >> >> I'm trying to recall, isn't it: >> >> x = conj(fft(conj(X))) ?? > >It could very well be. Although Richard didn't say so, I assumed the >result of the IFFT to be a real-valued signal, in which case the outer >conj shouldn't matter... or am I too quick in dismissing that now...? > >Rune >
Good point Rune! [-Rick-]