3

I am trying to implement FFT, and I am OK with the code etc, but the general order of things is confusing me.

Am I right in thinking that this is the correct order of things to do?

Input -> Overlap input -> Windowing -> FFT -> Phase calculations/Overlap compensation -> Output

I'm getting results close to my input frequency, but they are consistently off by some factor that I can't work out, i.e. 440Hz is always 407Hz, 430Hz is always 420Hz.

The main bit that is confusing me is the initial overlap, as I have been looking at some open source FFT code and that is the part that I can never quite work out whats going on. I seem to be getting the idea from looking at those that overlapping is supposed to happen before windowing, but to me logically, wouldn't that mess with the windowing?

Any advice would be great

Thanks

jacob
  • 31
  • 1
  • 4
  • This is a very nice question, but has little to do with C (at least that you have provided). Not sure this forum is the best one to answer your question. ***[Try posting on this one](http://math.stackexchange.com/)*** – ryyker Apr 29 '14 at 17:25
  • Ah, I meant to put it in signal processing. I've changed it now – jacob Apr 29 '14 at 17:28
  • The fact that you mention "Overlap Input" suggests that you're actually trying to implement a Discrete STFT rather than an FFT. Can you show your code, or explain in more detail what you're doing? – Babson Apr 29 '14 at 17:38
  • I thought an FFT was just an efficient computation of a discrete STFT, so basically the same thing. I might be wrong, I don't know. I am trying to get frequency detection and my frequencies are wrong. I assume this is due to how I am confused in regard to where to overlap my input. Do you know the actual work flow behind the STFT or FFT process? – jacob Apr 29 '14 at 17:44

2 Answers2

10

The FFT is a discrete version of the continuous Fourier Transform.

The FFT produces a 1D vector of complex numbers. This complex vector is often used to calculate a 2D matrix of Frequency Magnitude versus Frequency, and represented as a 2D graph, like this one:

Frequency spectrum female vocal soprano, Sooeet FFT calculator

A single FFT is used when you want to understand the frequency spectrum of a signal. For example, from the above FFT graph we can say that most of the energy in this female soprano's G5 note is concentrated in the 784 Hz and 1572 Hz frequencies.

STFT or "Short-Time Fourier Transform" uses a sliding-frame FFT to produce a 2D matrix of Frequency versus Time, often represented as a graph called a Spectrogram, like this one:

Spectrogram of a vocal phrase, Sooeet FFT calculator

The STFT is used when you want to know at what time a particular frequency event occurs in the signal. For example, from the above graph we can say that a large portion of the energy in this vocal phrase occurred between 0.05 and 0.15 seconds, in the frequency range of 100 Hz to 1500 Hz.

The workflow for the FFT is:

Sample the signal -> Window the entire sample frame -> FFT -> Calculate magnitude and phase -> Output something, usually a 2D graph

If your time-domain data is available in text form and if you can post it here, we can try to help you analyze it, or you can analyze it yourself with this online FFT: Sooeet FFT calculator

Babson
  • 909
  • 1
  • 7
  • 7
  • Thanks for the in-depth response. I am still not clear on the issue of overlapping though, which is my problem. Do I need to overlap my input before windowing or after windowing? – jacob Apr 30 '14 at 09:41
  • I'm still unclear as to what exactly you are trying to do. If you're implementing an FFT, the window function is used to reduce spectral leakage. Hence, for an FFT the window function is applied to all data samples, not to a subset of data samples. Therefore, there is no overlapping of the window function for an FFT. Overlapping is only a concern when you're implementing an STFT. Based on your comments about wrong output frequencies from your FFT it appears that your FFT code contains an error. – Babson Apr 30 '14 at 17:43
  • What is your data source, and exactly what information are you trying to extract from your data source? – Babson May 01 '14 at 00:38
  • Thanks for the follow up post, Babson. I am attempting to implement a method of pitch detection, where my data source is test sine wave tones, and my output is the peak magnitude frequency content. What you are saying about overlapping with FFT (you are to overlap all samples and not to a subset of samples), confuses me a bit though. My understanding of the process of windowing etc. is as follows: split the input signal into frames to be analysed, window each frame to prevent spectral leakage, overlap these frames so it is still possible to get the phase from the now attenuated parts. – jacob May 02 '14 at 08:45
  • But what you are saying is that you don't need to overlap in an FFT? If that is the case, how does it affect the phase calculations? If there is no overlap I would assume that you would no longer need to compensate for the expected phase advancement? Thanks again for the help Babson, I hope I'm describing my problem sufficiently. – jacob May 02 '14 at 08:46
  • If you answer these two questions, someone here may be able to help you: 1) What is your data source, and 2) Exactly what information are you trying to obtain from your data source. For example, your answers might be: 1) My data source is real-time audio from a microphone, and 2) I want to plot the real-time power spectrum of the signal coming from the microphone. – Babson May 02 '14 at 18:06
  • Hi, sorry I'm not being more helpful! My data source is real-time audio from a microphone (I'm using sine test tones), and I want to obtain the frequencies of said input sine tones in a method to implement pitch detection(i.e. my output could be as so: "at t=0, f = 440Hz, at t=1, f = 430, at t=2, f = 420", describing a sine wave going from 440Hz to 420Hz over the course of 3 seconds). Hope thats more clear – jacob May 02 '14 at 18:27
  • You'll need frequency-time analysis, akin to STFT. With pure sine test tones this should work fairly well. There is always a trade-off in frequency-time analysis, between frequency resolution and time resolution. This trade-off is controlled by the STFT frame size and the percent of frame overlap. However, for real acoustic signals (e.g. musical instrument or human vocal sounds), automatic pitch detection in real-time, or even off-line, is very challenging and is the subject of ongoing research. – Babson May 02 '14 at 20:16
  • 1
    I am aware that I need frequency-time analysis, and I am aware of the draw backs between frequency and time resolution. What I don't understand is the location of frame overlapping. I still don't understand where it is to happen within the algorithm work flow. Do you know the answer to my question? – jacob May 03 '14 at 08:44
0

If you use window for FFT, your computation will be a kind of STFT. There are some prepared codes of STFT like 'Spectrogram' etc. To write the code by FFT, the overlapping is inevitable,but you can use some optimization methods to minimize ghost effects.Also, the practical way for windowing may be choosing the window's bandwidth according to frequency extension. It is clear that in high frequency data's you need to select small windows which is so time consuming. I am not good enough in Matlab to write this code adhesively:)

Good Luck

Ala
  • 1