Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
ifft and fft in matlab

Subject: ifft and fft in matlab

From: zingas

Date: 7 May, 2009 07:02:46

Message: 1 of 12

hi
i want to ask whether there is any difference between taking n-point
ifft and then fft for OFDM Vs taking ifft and then n-point fft in
matlab.


the difference i get is the signal with n-point ifft and then fft has
a spectrum which do not have good resolution can anyone help me in
this regard.



Regards

Subject: ifft and fft in matlab

From: Wayne King

Date: 7 May, 2009 08:06:02

Message: 2 of 12

Hi Zingas, Can you be a little more specific in your question and perhaps give some example code,than perhaps somebody can help you. I take it that OFDM is orthogonal frequency division multiplexing, but give us your specific problem in context with code snippets so we can see why you feel you are not getting sufficient "resolution".

wayne
zingas <shammashahbaz@gmail.com> wrote in message <60e7c453-80cc-440a-a3e6-b65daca510c7@z19g2000vbz.googlegroups.com>...
> hi
> i want to ask whether there is any difference between taking n-point
> ifft and then fft for OFDM Vs taking ifft and then n-point fft in
> matlab.
>
>
> the difference i get is the signal with n-point ifft and then fft has
> a spectrum which do not have good resolution can anyone help me in
> this regard.
>
>
>
> Regards

Subject: ifft and fft in matlab

From: zingas

Date: 7 May, 2009 10:28:54

Message: 3 of 12

On May 7, 1:06 pm, "Wayne King" <wmkin...@gmail.com> wrote:
> Hi Zingas, Can you be a little more specific in your question and perhaps=
 give some example code,than perhaps somebody can help you. I take it that =
OFDM is orthogonal frequency division multiplexing, but give us your specif=
ic problem in context with code snippets so we can see why you feel you are=
 not getting sufficient "resolution".
>
> wayne
>
>
>
> zingas <shammashah...@gmail.com> wrote in message <60e7c453-80cc-440a-a3e=
6-b65daca51...@z19g2000vbz.googlegroups.com>...
> > hi
> > i want to ask whether there is any difference between taking n-point
> > ifft and then fft for OFDM Vs taking ifft and then n-point fft in
> > matlab.
>
> > the difference i get is the signal with n-point ifft and then fft has
> > a spectrum which do not have good resolution can anyone help me in
> > this regard.
>
> > Regards- Hide quoted text -
>
> - Show quoted text -

hi
thanku sir for your response
mycode is like this


x = [1 0 0 0]
x=ifft(x)
x=fft(x,16)
plot(abs(x))
hold on;


y = [1 0 0 0]
y=ifft(y,16)
y=fft(y)
plot(abs(y),'r')


Actually in OFDM(orthogonal frequency division multiplexing )we need
to implement a pair of ifft and fft .for example i explain the case of
2n-point fft /ifft ;the results are same for 8n-point ifft /fft

CASE#1 (bad resolution results)

my data =1024 , i take chunks of data and implemet ifft on it

i-e for example a take a chunk of 16 samples and apply ifft on the
vector which consists of 16 zeros; 8 zeros before and 8 zeros after
it .

0 0 0 0 0 0 0 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 0 0 0 0 0 0 0 0

and all of the ifft samples are vectored in another vector z and fft
of z is taken

CASE#2 (good resolution results )
another scenario is i take ifft of the data values 1024 and then i
perform 2n-point fft on the resulting vector


the result for the two is quiet different
is there any way to improve the resolution (other than increasing the
points and using the second case because the it takes a lot of
computation time)


Regards

Subject: ifft and fft in matlab

From: Greg Heath

Date: 7 May, 2009 19:02:43

Message: 4 of 12

CORRECTED FOR THE HEINOUS SIN OF TOP-POSTING

On May 7, 6:28 am, zingas <shammashah...@gmail.com> wrote:
> On May 7, 1:06 pm, "Wayne King" <wmkin...@gmail.com> wrote:
> > zingas <shammashah...@gmail.com> wrote in message
> > <60e7c453-80cc-440a-a3e6-b65daca51...@z19g2000vbz.googlegroups.com>...
> > >
> > > i want to ask whether there is any difference between taking n-point
> > > ifft and then fft for OFDM Vs taking ifft and then n-point fft in
> > > matlab.
>
> > > the difference i get is the signal with n-point ifft and thenffthas
> > > a spectrum which do not have good resolution can anyone help me in
> > > this regard.
>
> > Hi Zingas, Can you be a little more specific in your question and
> > perhaps give some example code,than perhaps somebody can help
> > you. I take it that OFDM is orthogonal frequency division multiplexing,
> > but give us your specific problem in context with code snippets so we
> > can see why you feel you are not getting sufficient "resolution".
> thanku sir for your response
> mycode is like this
>
> x = [1 0 0 0]
> x=ifft(x)

ARRRRRGH!

1. Do not use the same variable name for the input and output
     of a function.
2. Since this is a small problem, why not explicitly show the
     numerical outputs of each command? I don't have Matlab
     available right now, so I'm guessing (See "?" below)
3. You are starting with an ifft. Does that mean that x is a
   transform?

> xÿt(x,16)
> plot(abs(x))
> hold on;
> y = [1 0 0 0]
> y=ifft(y,16)
> yÿt(y)
> plot(abs(y),'r')

Using uppercase for transforms:
X = [1 0 0 0]
x = ifft(X) % x = ones(1,4) ?
Z = fft( [ x, zeros(1,12) ] ) % sinc function is the fft of a square
pulse
plot(abs(Z))
hold on;

y = ifft( [ X, zeros(1,12) ] ) % y = ones(1,16)?
Y = fft(y) % Y = [1, zeros(1,15)] = [X, zeros
(1,12)]?
plot(abs(Y),'r')


> Actually in OFDM(orthogonal frequency division multiplexing )we need
> to implement a pair of ifft andfft.for example i explain the case of
> 2n-pointfft/ifft ;the results are same for 8n-point ifft /fft
>
> CASE#1 (bad resolution results)
>
> my data 24 , i take chunks of data and implemet ifft on it
>
> i-e for example a take a chunk of 16 samples and apply ifft on the
> vector which consists of 16 zeros; 8 zeros before and 8 zeros after
> it .
>
> 0 0 0 0 0 0 0 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 0 0 0 0 0 0 0 0
>
> and all of the ifft samples are vectored in another vector z andfft
> of z is taken
>
> CASE#2 (good resolution results )
> another scenario is i take ifft of the data values 1024 and then i
> perform 2n-pointffton the resulting vector
>
> the result for the two is quiet different
> is there any way to improve the resolution (other than increasing the
> points and using the second case because the it takes a lot of
> computation time)

I really don't understand what you are trying to do and I don't have
Matlab handy... so, don't take the following comments literally:

Fourier Interpolation:

If you wish to interpolate a N-point time-sampled function at
M equally spaced points, inverse transform the zero-padded
transform. However, the zero padding has to be at the high
frequency part of the spectrum. Therefore you need to use
fftshift, zero-pad at both ends, then ifftshift before the final
inversion. Details will be different according to whether M
and/or N is even or odd.

Something like

xint = ifft(ifftshift([ones(1,(M-N)/2), fftshift(fft(x)),ones(1,(M-N)/
2]))

It's a little simpler if you wish to interpolate an existing N-point
frequency-sampled spectrum at M equally spaced points,

Xint = fft( [ ifft(X), ones(1,M-N)] )
     = fft(ifft(X),M)

Hope this helps.

Greg

Subject: ifft and fft in matlab

From: Royi Avital

Date: 7 Jun, 2009 10:35:02

Message: 5 of 12

Greg Heath <heath@alumni.brown.edu> wrote in message <c4a7477c-c4e5-4822-b7a1-a069eadb31fe@l28g2000vba.googlegroups.com>...
> CORRECTED FOR THE HEINOUS SIN OF TOP-POSTING
>
> On May 7, 6:28 am, zingas <shammashah...@gmail.com> wrote:
> > On May 7, 1:06 pm, "Wayne King" <wmkin...@gmail.com> wrote:
> > > zingas <shammashah...@gmail.com> wrote in message
> > > <60e7c453-80cc-440a-a3e6-b65daca51...@z19g2000vbz.googlegroups.com>...
> > > >
> > > > i want to ask whether there is any difference between taking n-point
> > > > ifft and then fft for OFDM Vs taking ifft and then n-point fft in
> > > > matlab.
> >
> > > > the difference i get is the signal with n-point ifft and thenffthas
> > > > a spectrum which do not have good resolution can anyone help me in
> > > > this regard.
> >
> > > Hi Zingas, Can you be a little more specific in your question and
> > > perhaps give some example code,than perhaps somebody can help
> > > you. I take it that OFDM is orthogonal frequency division multiplexing,
> > > but give us your specific problem in context with code snippets so we
> > > can see why you feel you are not getting sufficient "resolution".
> > thanku sir for your response
> > mycode is like this
> >
> > x = [1 0 0 0]
> > x=ifft(x)
>
> ARRRRRGH!
>
> 1. Do not use the same variable name for the input and output
> of a function.
> 2. Since this is a small problem, why not explicitly show the
> numerical outputs of each command? I don't have Matlab
> available right now, so I'm guessing (See "?" below)
> 3. You are starting with an ifft. Does that mean that x is a
> transform?
>
> > x?t(x,16)
> > plot(abs(x))
> > hold on;
> > y = [1 0 0 0]
> > y=ifft(y,16)
> > y?t(y)
> > plot(abs(y),'r')
>
> Using uppercase for transforms:
> X = [1 0 0 0]
> x = ifft(X) % x = ones(1,4) ?
> Z = fft( [ x, zeros(1,12) ] ) % sinc function is the fft of a square
> pulse
> plot(abs(Z))
> hold on;
>
> y = ifft( [ X, zeros(1,12) ] ) % y = ones(1,16)?
> Y = fft(y) % Y = [1, zeros(1,15)] = [X, zeros
> (1,12)]?
> plot(abs(Y),'r')
>
>
> > Actually in OFDM(orthogonal frequency division multiplexing )we need
> > to implement a pair of ifft andfft.for example i explain the case of
> > 2n-pointfft/ifft ;the results are same for 8n-point ifft /fft
> >
> > CASE#1 (bad resolution results)
> >
> > my data 24 , i take chunks of data and implemet ifft on it
> >
> > i-e for example a take a chunk of 16 samples and apply ifft on the
> > vector which consists of 16 zeros; 8 zeros before and 8 zeros after
> > it .
> >
> > 0 0 0 0 0 0 0 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 0 0 0 0 0 0 0 0
> >
> > and all of the ifft samples are vectored in another vector z andfft
> > of z is taken
> >
> > CASE#2 (good resolution results )
> > another scenario is i take ifft of the data values 1024 and then i
> > perform 2n-pointffton the resulting vector
> >
> > the result for the two is quiet different
> > is there any way to improve the resolution (other than increasing the
> > points and using the second case because the it takes a lot of
> > computation time)
>
> I really don't understand what you are trying to do and I don't have
> Matlab handy... so, don't take the following comments literally:
>
> Fourier Interpolation:
>
> If you wish to interpolate a N-point time-sampled function at
> M equally spaced points, inverse transform the zero-padded
> transform. However, the zero padding has to be at the high
> frequency part of the spectrum. Therefore you need to use
> fftshift, zero-pad at both ends, then ifftshift before the final
> inversion. Details will be different according to whether M
> and/or N is even or odd.
>
> Something like
>
> xint = ifft(ifftshift([ones(1,(M-N)/2), fftshift(fft(x)),ones(1,(M-N)/
> 2]))
>
> It's a little simpler if you wish to interpolate an existing N-point
> frequency-sampled spectrum at M equally spaced points,
>
> Xint = fft( [ ifft(X), ones(1,M-N)] )
> = fft(ifft(X),M)
>
> Hope this helps.
>
> Greg

Adding zeros at the end of "fftshifted" vector will break symmetry for Even vectors.
How do you solve that?

Subject: ifft and fft in matlab

From: Matt

Date: 7 Jun, 2009 15:02:00

Message: 6 of 12

"Royi Avital" <RoyiREMOVEAvital@yahoo.com> wrote in message <h0g54m$96i$1@fred.mathworks.com>...

> Adding zeros at the end of "fftshifted" vector will break symmetry for Even vectors.
> How do you solve that?

Always pad on the right by ceil(NumZeros/2) and on the left by

Numzeros-ceil(NumZeros/2)

and you will be fine.

Subject: ifft and fft in matlab

From: Matt

Date: 7 Jun, 2009 15:13:01

Message: 7 of 12

zingas <shammashahbaz@gmail.com> wrote in message <182c6608-c217-49b5-9551-a4904951acfe@c18g2000prh.googlegroups.com>...

> CASE#1 (bad resolution results)
>
> my data =1024 , i take chunks of data and implemet ifft on it
>
> i-e for example a take a chunk of 16 samples and apply ifft on the
> vector which consists of 16 zeros; 8 zeros before and 8 zeros after
> it .
>
> 0 0 0 0 0 0 0 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 0 0 0 0 0 0 0 0
>
> and all of the ifft samples are vectored in another vector z and fft
> of z is taken
>

It's obvious why this won't do any good. When you take the fft you're just undoing the previous ifft step, apart from the preliminary zero-padding. So, you'll always get your original vector back again - with no change in sampling resolution - but zero-padded on the ends.

> CASE#2 (good resolution results )
> another scenario is i take ifft of the data values 1024 and then i
> perform 2n-point fft on the resulting vector
>
>
> the result for the two is quiet different
> is there any way to improve the resolution (other than increasing the
> points and using the second case because the it takes a lot of
> computation time)

The 2nd case is equivalent to sinc-interpolating your frequency samples. If you want something faster than this, you might ask yourself whether you really need sinc interpolation values or if another kind of interpolation (e.g. linear, cubic splines, etc...) would be sufficient. If so, then just use interp1().

Subject: ifft and fft in matlab

From: Matt

Date: 7 Jun, 2009 15:45:17

Message: 8 of 12

"Matt " <xys@whatever.com> wrote in message <h0gkp8$3hq$1@fred.mathworks.com>...
> "Royi Avital" <RoyiREMOVEAvital@yahoo.com> wrote in message <h0g54m$96i$1@fred.mathworks.com>...
>
> > Adding zeros at the end of "fftshifted" vector will break symmetry for Even vectors.
> > How do you solve that?
>
> Always pad on the right by ceil(NumZeros/2) and on the left by
>
> Numzeros-ceil(NumZeros/2)
>
> and you will be fine.

For even sized vectors, that is. For odd-sized vectors, pad on the left with
ceil(NumZeros/2)

Subject: ifft and fft in matlab

From: Royi Avital

Date: 7 Jun, 2009 21:29:02

Message: 9 of 12

"Matt " <xys@whatever.com> wrote in message <h0gnad$j2v$1@fred.mathworks.com>...
> "Matt " <xys@whatever.com> wrote in message <h0gkp8$3hq$1@fred.mathworks.com>...
> > "Royi Avital" <RoyiREMOVEAvital@yahoo.com> wrote in message <h0g54m$96i$1@fred.mathworks.com>...
> >
> > > Adding zeros at the end of "fftshifted" vector will break symmetry for Even vectors.
> > > How do you solve that?
> >
> > Always pad on the right by ceil(NumZeros/2) and on the left by
> >
> > Numzeros-ceil(NumZeros/2)
> >
> > and you will be fine.
>
> For even sized vectors, that is. For odd-sized vectors, pad on the left with
> ceil(NumZeros/2)

wouldn't work.
Will break symmetry.
let's assume Xk = [4 2 3 5 3 2] - The symmetry holds.
I want to pad with 4 zeros, you say it should be Xk = [ 4 2 3 0 0 0 0 5 3 2]
That vector isn't symmetric.

Subject: ifft and fft in matlab

From: Matt

Date: 7 Jun, 2009 23:08:00

Message: 10 of 12

"Royi Avital" <RoyiREMOVEAvital@yahoo.com> wrote in message <h0hbeu$d6n$1@fred.mathworks.com>...
> "Matt " <xys@whatever.com> wrote in message <h0gnad$j2v$1@fred.mathworks.com>...
> > "Matt " <xys@whatever.com> wrote in message <h0gkp8$3hq$1@fred.mathworks.com>...
> > > "Royi Avital" <RoyiREMOVEAvital@yahoo.com> wrote in message <h0g54m$96i$1@fred.mathworks.com>...
> > >
> > > > Adding zeros at the end of "fftshifted" vector will break symmetry for Even vectors.
> > > > How do you solve that?
> > >
> > > Always pad on the right by ceil(NumZeros/2) and on the left by
> > >
> > > Numzeros-ceil(NumZeros/2)
> > >
> > > and you will be fine.
> >
> > For even sized vectors, that is. For odd-sized vectors, pad on the left with
> > ceil(NumZeros/2)
>
> wouldn't work.
> Will break symmetry.
> let's assume Xk = [4 2 3 5 3 2] - The symmetry holds.

what symmetry are you refering to? In what way is this vector symmetric?

> I want to pad with 4 zeros, you say it should be Xk = [ 4 2 3 0 0 0 0 5 3 2]
> That vector isn't symmetric.

And in what way is this vector asymetric? It looks fine to me. DC is still Xk=4. All other samples Xk are at the same frequencies as in the original array as well

Subject: ifft and fft in matlab

From: Royi Avital

Date: 8 Jun, 2009 07:37:01

Message: 11 of 12

"Matt " <xys@whatever.com> wrote in message <h0hh8g$19k$1@fred.mathworks.com>...
> "Royi Avital" <RoyiREMOVEAvital@yahoo.com> wrote in message <h0hbeu$d6n$1@fred.mathworks.com>...
> > "Matt " <xys@whatever.com> wrote in message <h0gnad$j2v$1@fred.mathworks.com>...
> > > "Matt " <xys@whatever.com> wrote in message <h0gkp8$3hq$1@fred.mathworks.com>...
> > > > "Royi Avital" <RoyiREMOVEAvital@yahoo.com> wrote in message <h0g54m$96i$1@fred.mathworks.com>...
> > > >
> > > > > Adding zeros at the end of "fftshifted" vector will break symmetry for Even vectors.
> > > > > How do you solve that?
> > > >
> > > > Always pad on the right by ceil(NumZeros/2) and on the left by
> > > >
> > > > Numzeros-ceil(NumZeros/2)
> > > >
> > > > and you will be fine.
> > >
> > > For even sized vectors, that is. For odd-sized vectors, pad on the left with
> > > ceil(NumZeros/2)
> >
> > wouldn't work.
> > Will break symmetry.
> > let's assume Xk = [4 2 3 5 3 2] - The symmetry holds.
>
> what symmetry are you refering to? In what way is this vector symmetric?
>
> > I want to pad with 4 zeros, you say it should be Xk = [ 4 2 3 0 0 0 0 5 3 2]
> > That vector isn't symmetric.
>
> And in what way is this vector asymetric? It looks fine to me. DC is still Xk=4. All other samples Xk are at the same frequencies as in the original array as well

Let's reorder it: xk = [0 0 5 3 2 4 2 3 0 0]
You see the asymmetry? the sample with amplitude 5 breaks the symmetry.
If you apply IDFT on this vector you'll get a complex vector.

Subject: ifft and fft in matlab

From: Greg Heath

Date: 8 Jun, 2009 23:04:38

Message: 12 of 12

On Jun 8, 3:37 am, "Royi Avital" <RoyiREMOVEAvi...@yahoo.com> wrote:
> "Matt " <x...@whatever.com> wrote in message <h0hh8g$19...@fred.mathworks.com>...
> > "Royi Avital" <RoyiREMOVEAvi...@yahoo.com> wrote in message <h0hbeu$d6...@fred.mathworks.com>...
> > > "Matt " <x...@whatever.com> wrote in message <h0gnad$j2...@fred.mathworks.com>...
> > > > "Matt " <x...@whatever.com> wrote in message <h0gkp8$3h...@fred.mathworks.com>...
> > > > > "Royi Avital" <RoyiREMOVEAvi...@yahoo.com> wrote in message <h0g54m$96...@fred.mathworks.com>...
>
> > > > > > Adding zeros at the end of "fftshifted" vector will break symmetry for Even vectors.
> > > > > > How do you solve that?
>
> > > > > Always pad on the right by ceil(NumZeros/2) and on the left by
>
> > > > > Numzeros-ceil(NumZeros/2)
>
> > > > > and you will be fine.
>
> > > > For even sized vectors, that is. For odd-sized vectors, pad on the left with
> > > > ceil(NumZeros/2)
>
> > > wouldn't work.
> > > Will break symmetry.
> > > let's assume Xk = [4 2 3 5 3 2] - The symmetry holds.
>
> > what symmetry are you refering to? In what way is this vector  symmetric?

Conjugate symmetry.

> > > I want to pad with 4 zeros, you say it should be Xk = [ 4 2 3 0 0 0 0 5 3 2]
> > > That vector isn't symmetric.

To get M interpolated points from the ifft:

[4 2 3 5 3 2] --> [4 2 3 2.5 2.5 3 2] --> [4 2 3 2.5 zeros
(1,M-7) 2.5 3 2 ]

Hope this helps.

Greg

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us