**Al momento, stai seguendo questa domanda**

- Vedrai gli aggiornamenti nel tuofeed del contenuto seguito.
- Potresti ricevere delle e-mail a seconda delle tuepreferenze per le comunicazioni.

# Huge difference between the result of fft function Matlab and analytical Fourier transform of the same function

##### 2 Commenti

### Risposta accettata

##### 6 Commenti

- So based on your explanations, I can only use fft for a sin(t) if it is a finite signal and has a start and end point. Is that correct?
- I think I do have a confusion regarding how we transfer time to frequency when calculating the fourier transform. My undrestanding is for example for fft because in the fourier transform definition there is exp(-i2*pi*t*k) so for going from time to frequency if ts is time intervals then 1/(N*ts) would be the frequency interval (because indeed it is frequency and not angular frequency). But I see you have a 2*pi factor as well. Could you please comment on it?
- Indeed, all of your explanations to instruct me about the sample reordering and the fact that the result of the fft is properly viewed as the right and left sides of a single peak centered at w = 0 and the phase adjustment point that you mentioned we should do, all of these stuff are done by fftshift(fft). Is that correct? I mean indeed our correct answer for fourier transform of a function would be fftshift(fft) and if we use fftshift of fft and not fft itself, indeed we are incorporating all of the points you mentioned above to instruct me. Is that correct?

- The DFT, which is what fft computes, is only applicable to discrete-time, finite duration signals (discussed above). sin(t) is not of finite duration, so it can't be sampled into a disctete-time, finite duration signal from which a DFT can be computed. We can immediately see a problem when we realize that the DFT samples of any finite duration signal are finite in magnitude (and duration), but the DTFT of x[n] = sin(n*Ts) is given in terms of Dirac deltas (link), as is the CTFT of sin(t) (entry 305). The output of fft will never be a Dirac delta. What one can do, and examples abound on this forum, is take samples of sin(t) over a finite duration, and then compute the DFT of those samples. In this case, the DFT yields frequency domain samples of the DTFT of samples of sin(t)*window(t), which in turn is an approximation ot the CTFT of sin(t)*window(t). But sin(t)*window(t) is not the same as sin(t). Alternatively, with an appropriate selection of Ts and appropriate selection of the finite number of samples of sin(n*Ts), the DFT of the samples can be related to Fourier series coeffients of sin(t), but, again, that's not the Fourier transform. Of course, all of these concepts are related to each other, but (IMO) it's important to understand the differences between them.
- The 2*pi factor comes directly from the definiton of the DFT (link). Each sample of the DFT, X[k], is a weighted sum of powers of exp(-1j*2*pi/N*k), where k goes from 0 to N-1. We see that the unit circle is being sampled at angles (rad) of 2*pi/N*k. So my preference is to keep the 2*pi scaling because it reminds me of what's happening mathematically, but its just a preference. I've seen treatments that explicilty bring Ts into the fft sum, but it's really just multiplying by 1, i.e., exp(-1j*2*pi/Ts/N*k*Ts), which can be way of viewing the frequency domain samples as being spaced by 2*pi/Ts/N.
- I'm afraid that's not totally correct. When using fft we have to keep in mind two things. First, fft as implemented in Matlab assumes that the first point in the input sequence is a sample at n = 0 (or t = 0 if viewed as a sample of a continuous-time signal). But, in our example problem, the first point in our sequence is sampled at a negative time, corresponding to n = -N/2. We could define the fft as a sum from -N/2 to N/2 -1 (N even), which would then fit nicely with the problem at hand (but wouldn't for others), but that's not how Matlab does it, so we have to compensate for what Matlab assumes relative to what we actually have. For this particular problem, with N even and n defined as -N/2 : (N/2-1) we could take advantage of ifftshift before taking the fft as a different option. Second, because the Matlab implementation of fft takes the sum from 0 to N-1 (all positive numbers) the corresponding frequency samples are also all positive and monotonically increaing from 0 to ~2*pi (or 2*pi/Ts is scaling by Ts). Then we use fftshift to just reorder the ouput from fft as if fft computed the DFT sum from -N/2 to N/2 - 1 (N even), and then we compute the corresponding frequency vector in whatever units we prefer. In short, we can always use fftshift if we choose (we don't have to), but whether or not we need to phase-adjust the output of fft is problem-dependent, and only matters if we care about the phase in the first place.

### Più risposte (1)

##### 1 Commento

### Vedere anche

### Categorie

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!**Si è verificato un errore**

Impossibile completare l'azione a causa delle modifiche apportate alla pagina. Ricarica la pagina per vedere lo stato aggiornato.

Seleziona un sito web

Seleziona un sito web per visualizzare contenuto tradotto dove disponibile e vedere eventi e offerte locali. In base alla tua area geografica, ti consigliamo di selezionare: .

Puoi anche selezionare un sito web dal seguente elenco:

Come ottenere le migliori prestazioni del sito

Per ottenere le migliori prestazioni del sito, seleziona il sito cinese (in cinese o in inglese). I siti MathWorks per gli altri paesi non sono ottimizzati per essere visitati dalla tua area geografica.

Americhe

- América Latina (Español)
- Canada (English)
- United States (English)

Europa

- 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)

Asia-Pacifico

- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)