Forums

Help with FFT and IFFT

Started by marc...@gmail.com April 13, 2008
Hi!!

I am new to matlab so please bear with me. I don't understand the IFFT and FFT matlab functions. Here is the code i am using:

[sig,fs]=wavread('aemixed.wav');
time=(1:length(sig))'/fs;

figure(1)
plot(time,sig)

fsig1 = fft(sig,fs);
Y=real((ifft(fsig1,length(sig))));
figure(3)
plot(time,Y)

What I don't understand is that Y and sig are not the same. Can someone please explain this to me. And some help as to to what to do to fsig1 so that when I take the ifft, the result is the same as sig.
Marciful-

> I am new to matlab so please bear with me. I don't understand the IFFT
> and FFT matlab functions. Here is the code i am using:
>
> [sig,fs]=wavread('aemixed.wav');
> time=(1:length(sig))'/fs;
>
> figure(1)
> plot(time,sig)
>
> fsig1 = fft(sig,fs);
> Y=real((ifft(fsig1,length(sig))));
> figure(3)
> plot(time,Y)
>
> What I don't understand is that Y and sig are not the same. Can someone
> please explain this to me. And some help as to
> to what to do to fsig1 so that when I take the ifft, the result is the
> same as sig.

You're confusing fs (sampling rate in Hz) with length (samples) when you call the fft() function. Try:

fsig1 = fft(sig);
Y = real((ifft(fsig1)));

Note -- if the .wav file is long, this may not be what you want. You may need to process the .wav file in "frames"
with length that is meaningful relative to the nature of the data, a typical method for speech and audio processing.

-Jeff
When you take FFT/IFFT, the result is a complex exponential ( a complex no : a+bi). When u take IFFT of that, do not take it of real part of the previous signal only. Otherwise the imaginary part would be clipped and you wont get the same signal. So in general it should be like

xT(a);
y=IFFT(x);

then you will get y=a.

Farrukh
Farrukh-

> When you take FFT/IFFT, the result is a complex exponential
> ( a complex no : a+bi). When u take IFFT of that, do not take it of real
> part of the previous signal only.

The OP didn't do that.

> Otherwise the imaginary part would be
> clipped and you wont get the same signal. So in general it should be like
>
> xT(a);
> y=IFFT(x);
>
> then you will get y=a.

The OP started with a real-valued signal, then applied real() after the iFFT. To use
your example, this would be:

x = FFT(a);
y = real(IFFT(x));

and you would still get y = a.

-Jeff
-------- Original Message --------
Subject: [matlab] Help with FFT and IFFT
Date: Sat, 12 Apr 2008 17:26:56 -0400
From: m...@gmail.com
Reply-To: m...@gmail.com
To: m...

Hi!!

I am new to matlab so please bear with me. I don't understand the IFFT and FFT matlab
functions. Here is the code i am using:

[sig,fs]=wavread('aemixed.wav');
time=(1:length(sig))'/fs;

figure(1)
plot(time,sig)

fsig1 = fft(sig,fs);
Y=real((ifft(fsig1,length(sig))));
figure(3)
plot(time,Y)

What I don't understand is that Y and sig are not the same. Can someone please
explain this to me. And some help as to to what to do to fsig1 so that when I take
the ifft, the result is the same as sig.
Leelavathy-
> I am working with video watermarking. Can you please help me in suggesting how to
> separate a audio information from a *.avi file and relate it to video
> information. I am able to retrieve frames but I also want the audio signal
> separately.

Please post to the group, not to me.

-Jeff
> On 4/13/08, Jeff Brower wrote:
>
> Marciful-
>
> > I am new to matlab so please bear with me. I don't understand the IFFT
> > and FFT matlab functions. Here is the code i am using:
> >
> > [sig,fs]=wavread('aemixed.wav');
> > time=(1:length(sig))'/fs;
> >
> > figure(1)
> > plot(time,sig)
> >
> > fsig1 = fft(sig,fs);
> > Y=real((ifft(fsig1,length(sig))));
> > figure(3)
> > plot(time,Y)
> >
> > What I don't understand is that Y and sig are not the same. Can someone
>
> > please explain this to me. And some help as to
> > to what to do to fsig1 so that when I take the ifft, the result is the
> > same as sig.
>
> You're confusing fs (sampling rate in Hz) with length (samples) when you
> call the fft() function. Try:
>
> fsig1 = fft(sig);
> Y = real((ifft(fsig1)));
>
> Note -- if the .wav file is long, this may not be what you want. You may
> need to process the .wav file in "frames"
> with length that is meaningful relative to the nature of the data, a
> typical method for speech and audio processing.
>
> -Jeff
>
I'm sorry for the delay.
I do not know what is your problem.
If you think is useful , you can read a tutorial for FFT that I submitted to
the The MathWorks web page.
I analyzed 3 case of FFT (time-symmetric signal, time-asymmetric signal and
periodic signal) verifying
that the numeric results are super imposable to the analytic ones.
I analyzed also the possibility to use the pair FFT-IFFT to translate the
signal of a quantity smaller than the sampling time.
(so in this tutorial I faced the problem of the IFFT).
I hope this will be useful for you
http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectIdV54&objectType=file

BR
Daniele

On Sat, Apr 12, 2008 at 11:26 PM, wrote:

> Hi!!
>
> I am new to matlab so please bear with me. I don't understand the IFFT and
> FFT matlab functions. Here is the code i am using:
>
> [sig,fs]=wavread('aemixed.wav');
> time=(1:length(sig))'/fs;
>
> figure(1)
> plot(time,sig)
>
> fsig1 = fft(sig,fs);
> Y=real((ifft(fsig1,length(sig))));
> figure(3)
> plot(time,Y)
>
> What I don't understand is that Y and sig are not the same. Can someone
> please explain this to me. And some help as to to what to do to fsig1 so
> that when I take the ifft, the result is the same as sig.
>
>
>