On Jan 11, 3:20 pm, robert bristow-johnson <r...@audioimagination.com>

wrote:

> On Jan 11, 2:11 pm, Greg Heath <he...@alumni.brown.edu> wrote:

>

> > On Jan 11, 10:25 am, "orthocto" <ortho...@gmail.com> wrote:

>

> > > I've tried looking around for an answer to these questions

> > > ... and there are a few threads. Yet, I am still confused.

>

> > > My questions of this thread are:

> > > A. Why should one do fft( fftshift(x) )

>

> > I do not recommend it ... it leads to confusion.

> > To avoid confusion only use fftshift on the spectrum.

>

> another perpective.

>

> > If you have to shift in the time domain, use ifftshift.

>

> i didn't even know that existed. what does ifftshift() do

> that is different that fftshift()?

According to the MATLAB documentation:

Y = fftshift(X) rearranges the outputs of fft, fft2, and

fftn by moving the zero-frequency component to the center

of the array. It is useful for visualizing a Fourier

transform with the zero-frequency component in the middle

of the spectrum. For vectors, fftshift(X) swaps the left

and right halves of X.

and

ifftshift(X) undoes the results of fftshift

In particular, there is no mention of shifting in the

time domain.

So, the MATLAB convention is

1. Define x(t) over [0,T-dt]

2. Obtain X(f) = fft(x) defined over [0,Fs-df]

3. Obtain Xb = fftshift(X) defined over

a. df*[ -(N-1)/2 : (N-1)/2 ] for N odd

b. df*[ -N/2 : N/2 - 1 ] for N even

4. If X is no longer available, recover X = ifftshift(Xb)

5. Obtain x = ifft(X)

Notice that both fftshift and ifftshift are used on the

spectrum. However,steps 4 and 5 can be replaced by

6. Obtain xb = ifft(Xb) defined over

a. dt*[ -(N-1)/2 : (N-1)/2 ] for N odd

b. dt*[ -N/2 : N/2 - 1 ] for N even

7. Recover x = ifftshift(xb)

Therefore, fftshift is only used on the spectrum

and the time domain shift is obtained using ifftshift.

Consequently, to lessen the confusion, my advice to the

OP, and newbies in general, is "Use ifftshift in the

time domain to convert a "zero centered" waveform to one

that starts at t = 0 and conforms to the fft assumption.

Because of all the symmetry properties available there

are many different ways to approach the problem (e.g.,

fft(xb)).However, for giving advice to newbies who,

like the OP, will be flumoxed by the MATLAB documentation,

I think the above approach is the least confusing.

So, when starting with xb instead of x, my advice is to

use step 7 first.

> > However, beware that the function is not shifted, it is

> > reflected about point ceil((N+1)/2) which then becomes

> > the first point corresponding to t = 0 when using fft.

>

> okay. why would i use that?

Because the fft assumes the first point is t = 0.

> > Define

>

> > dt = 1/Fs, T = N*dt, df = 1/T

>

> > fft assumes

>

> > 1. x is defined over the nonnegative time interval

> > t = dt*(0:N-1) ; = 0:dt:T-dt ; = linspace(0,T-dt,N);

> > 2. x is periodic with period T = N*dt outside that interval.

> > If X = fft(x), then ifft(X) will automatically have

> > that property.

> > 3. f is defined over the nonnegative frequency interval

> > f = df*(0:N-1) = 0:df:Fs-df = linespace(0,Fs-df,N);

> > 4. X = fft(x) is automatically periodic with period

> > Fs = N*df outside that interval.

>

> > If either t or f are not defined that way, shifting of x

> > using ifftshift or X using fftshift should be considered.

>

> > Typically, x is defined over nonnegative t as specified

> > above. Consequently X = fft(x) will be defined over

> > nonegative f.

>

> if you put 1 & 2 together, then you *can* understand a manner

> that x(t) is defined for -N/2*T <= t < N/2*T. the portion of

> x(t) that is 0 <= t < N/2*T goes where it usually does and the

> portion of x(t) that is -N/2*T <= t < 0 goes into the second

> half. so that suggest a use for fftshift()( or you can do it

> explicitly in MATLAB without fftshift() ).

You can. However, as explained above, I think it is less

confusing to the inexperienced user to use fftshift in the

fft (frequency) domain and ifftshift in the ifft (time) domain.

How to do otherwise is more easily understood by you and me.

However, my advice to a newbie, like the OP, is to stick as

close as possible to the MATLAB documentation which,

unfortunately, is sorely lacking.

> so, imagine you have two pulses in the time domain. doesn't matter

> what kind of pulse, could be a rectangular pulse, or a gaussian pulse,

> or a piece of Hann-windowed data. one pulse is centered around t=0

> and the other pulse is centered around t=N/2*T. as the OP noticed,

> the magnitude will be the same, but what will happen is that the

> delayed pulse, the phase response will have +/- pi added to every odd

> numbered sample in the frequency domain.

>

> but since MATLAB is stupid and even though for two decades, *someone*

> in the know had been telling them that they should extend the language

> to accommodate zero and negative indices, they have never done it. so

> if you sample a piece of time-domain data and you window it and put it

> into a MATLAB array, it will go into that array centered at N/2*T and

> when you FFT the array you will see that annoying phase response. but

> if you fftshift() the time domain data going in, the phase response

> will look like one might expect of a windowed pulse (centered at 0).

>

> that, as far as i can tell, is what fftshift() is for.

No, as the documentation states, fftshift is for shifting ffts.

It is less confusing to use ifftshift to shift iffts or original

time functions.

I hope my reasoning is clear.

Greg

Thanks a lot Greg~ Very helpful.

So is it guaranteed that ifft(ifftshift(spectrum)) always == ifftshift(ifft(spectrum))?

Let me know. Thank you~

Greg Heath <heath@alumni.brown.edu> wrote in message <b3f4c206-5d9b-4876-8b0d-c0bbe8dd1b95@j24g2000yqa.googlegroups.com>...

> On Jan 11, 3:20 pm, robert bristow-johnson <r...@audioimagination.com>

> wrote:

> > On Jan 11, 2:11 pm, Greg Heath <he...@alumni.brown.edu> wrote:

> >

> > > On Jan 11, 10:25 am, "orthocto" <ortho...@gmail.com> wrote:

> >

> > > > I've tried looking around for an answer to these questions

> > > > ... and there are a few threads. Yet, I am still confused.

> >

> > > > My questions of this thread are:

> > > > A. Why should one do fft( fftshift(x) )

> >

> > > I do not recommend it ... it leads to confusion.

> > > To avoid confusion only use fftshift on the spectrum.

> >

> > another perpective.

> >

> > > If you have to shift in the time domain, use ifftshift.

> >

> > i didn't even know that existed. what does ifftshift() do

> > that is different that fftshift()?

>

> According to the MATLAB documentation:

>

> Y = fftshift(X) rearranges the outputs of fft, fft2, and

> fftn by moving the zero-frequency component to the center

> of the array. It is useful for visualizing a Fourier

> transform with the zero-frequency component in the middle

> of the spectrum. For vectors, fftshift(X) swaps the left

> and right halves of X.

>

> and

>

> ifftshift(X) undoes the results of fftshift

>

> In particular, there is no mention of shifting in the

> time domain.

>

> So, the MATLAB convention is

>

> 1. Define x(t) over [0,T-dt]

> 2. Obtain X(f) = fft(x) defined over [0,Fs-df]

> 3. Obtain Xb = fftshift(X) defined over

> a. df*[ -(N-1)/2 : (N-1)/2 ] for N odd

> b. df*[ -N/2 : N/2 - 1 ] for N even

> 4. If X is no longer available, recover X = ifftshift(Xb)

> 5. Obtain x = ifft(X)

>

> Notice that both fftshift and ifftshift are used on the

> spectrum. However,steps 4 and 5 can be replaced by

>

> 6. Obtain xb = ifft(Xb) defined over

> a. dt*[ -(N-1)/2 : (N-1)/2 ] for N odd

> b. dt*[ -N/2 : N/2 - 1 ] for N even

> 7. Recover x = ifftshift(xb)

>

> Therefore, fftshift is only used on the spectrum

> and the time domain shift is obtained using ifftshift.

>

> Consequently, to lessen the confusion, my advice to the

> OP, and newbies in general, is "Use ifftshift in the

> time domain to convert a "zero centered" waveform to one

> that starts at t = 0 and conforms to the fft assumption.

>

> Because of all the symmetry properties available there

> are many different ways to approach the problem (e.g.,

> fft(xb)).However, for giving advice to newbies who,

> like the OP, will be flumoxed by the MATLAB documentation,

> I think the above approach is the least confusing.

>

> So, when starting with xb instead of x, my advice is to

> use step 7 first.

>

> > > However, beware that the function is not shifted, it is

> > > reflected about point ceil((N+1)/2) which then becomes

> > > the first point corresponding to t = 0 when using fft.

> >

> > okay. why would i use that?

>

> Because the fft assumes the first point is t = 0.

>

> > > Define

> >

> > > dt = 1/Fs, T = N*dt, df = 1/T

> >

> > > fft assumes

> >

> > > 1. x is defined over the nonnegative time interval

> > > t = dt*(0:N-1) ; = 0:dt:T-dt ; = linspace(0,T-dt,N);

> > > 2. x is periodic with period T = N*dt outside that interval.

> > > If X = fft(x), then ifft(X) will automatically have

> > > that property.

> > > 3. f is defined over the nonnegative frequency interval

> > > f = df*(0:N-1) = 0:df:Fs-df = linespace(0,Fs-df,N);

> > > 4. X = fft(x) is automatically periodic with period

> > > Fs = N*df outside that interval.

> >

> > > If either t or f are not defined that way, shifting of x

> > > using ifftshift or X using fftshift should be considered.

> >

> > > Typically, x is defined over nonnegative t as specified

> > > above. Consequently X = fft(x) will be defined over

> > > nonegative f.

> >

> > if you put 1 & 2 together, then you *can* understand a manner

> > that x(t) is defined for -N/2*T <= t < N/2*T. the portion of

> > x(t) that is 0 <= t < N/2*T goes where it usually does and the

> > portion of x(t) that is -N/2*T <= t < 0 goes into the second

> > half. so that suggest a use for fftshift()( or you can do it

> > explicitly in MATLAB without fftshift() ).

>

> You can. However, as explained above, I think it is less

> confusing to the inexperienced user to use fftshift in the

> fft (frequency) domain and ifftshift in the ifft (time) domain.

>

>

> How to do otherwise is more easily understood by you and me.

> However, my advice to a newbie, like the OP, is to stick as

> close as possible to the MATLAB documentation which,

> unfortunately, is sorely lacking.

>

> > so, imagine you have two pulses in the time domain. doesn't matter

> > what kind of pulse, could be a rectangular pulse, or a gaussian pulse,

> > or a piece of Hann-windowed data. one pulse is centered around t=0

> > and the other pulse is centered around t=N/2*T. as the OP noticed,

> > the magnitude will be the same, but what will happen is that the

> > delayed pulse, the phase response will have +/- pi added to every odd

> > numbered sample in the frequency domain.

> >

> > but since MATLAB is stupid and even though for two decades, *someone*

> > in the know had been telling them that they should extend the language

> > to accommodate zero and negative indices, they have never done it. so

> > if you sample a piece of time-domain data and you window it and put it

> > into a MATLAB array, it will go into that array centered at N/2*T and

> > when you FFT the array you will see that annoying phase response. but

> > if you fftshift() the time domain data going in, the phase response

> > will look like one might expect of a windowed pulse (centered at 0).

> >

> > that, as far as i can tell, is what fftshift() is for.

>

> No, as the documentation states, fftshift is for shifting ffts.

> It is less confusing to use ifftshift to shift iffts or original

> time functions.

>

> I hope my reasoning is clear.

>

> Greg

oh i tried

plot(T, abs(ifft(ifftshift(AT0))), T, abs(ifftshift(ifft(AT0))));

they are very different... Did I misunderstand you? Could you help me with this Greg? Thanks~

You can think of your watch list as threads that you have bookmarked.

You can add tags, authors, threads, and even search results to your watch list. This way you can easily keep track of topics that you're interested in. To view your watch list, click on the "My Newsreader" link.

To add items to your watch list, click the "add to watch list" link at the bottom of any page.

To add search criteria to your watch list, search for the desired term in the search box. Click on the "Add this search to my watch list" link on the search results page.

You can also add a tag to your watch list by searching for the tag with the directive "tag:tag_name" where tag_name is the name of the tag you would like to watch.

To add an author to your watch list, go to the author's profile page and click on the "Add this author to my watch list" link at the top of the page. You can also add an author to your watch list by going to a thread that the author has posted to and clicking on the "Add this author to my watch list" link. You will be notified whenever the author makes a post.

To add a thread to your watch list, go to the thread page and click the "Add this thread to my watch list" link at the top of the page.

Got questions?

Get answers.

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

Learn moreDiscover what MATLAB ^{®} can do for your career.

Opportunities for recent engineering grads.

Apply TodayThe newsgroups are a worldwide forum that is open to everyone. Newsgroups are used to discuss a huge range of topics, make announcements, and trade files.

Discussions are threaded, or grouped in a way that allows you to read a posted message and all of its replies in chronological order. This makes it easy to follow the thread of the conversation, and to see what’s already been said before you post your own reply or make a new posting.

Newsgroup content is distributed by servers hosted by various organizations on the Internet. Messages are exchanged and managed using open-standard protocols. No single entity “owns” the newsgroups.

There are thousands of newsgroups, each addressing a single topic or area of interest. The MATLAB Central Newsreader posts and displays messages in the comp.soft-sys.matlab newsgroup.

**MATLAB Central**

You can use the integrated newsreader at the MATLAB Central website to read and post messages in this newsgroup. MATLAB Central is hosted by MathWorks.

Messages posted through the MATLAB Central Newsreader are seen by everyone using the newsgroups, regardless of how they access the newsgroups. There are several advantages to using MATLAB Central.

**One Account**

Your MATLAB Central account is tied to your MathWorks Account for easy access.

**Use the Email Address of Your Choice**

The MATLAB Central Newsreader allows you to define an alternative email address as your posting address, avoiding clutter in your primary mailbox and reducing spam.

**Spam Control**

Most newsgroup spam is filtered out by the MATLAB Central Newsreader.

**Tagging**

Messages can be tagged with a relevant label by any signed-in user. Tags can be used as keywords to find particular files of interest, or as a way to categorize your bookmarked postings. You may choose to allow others to view your tags, and you can view or search others’ tags as well as those of the community at large. Tagging provides a way to see both the big trends and the smaller, more obscure ideas and applications.

**Watch lists**

Setting up watch lists allows you to be notified of updates made to postings selected by author, thread, or any search variable. Your watch list notifications can be sent by email (daily digest or immediate), displayed in My Newsreader, or sent via RSS feed.

- Use a newsreader through your school, employer, or internet service provider
- Pay for newsgroup access from a commercial provider
- Use Google Groups
- Mathforum.org provides a newsreader with access to the comp.soft sys.matlab newsgroup
- Run your own server. For typical instructions, see: http://www.slyck.com/ng.php?page=2

You can also select a location from the following list:

- Canada (English)
- United States (English)

- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)

- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)