© François Le Coat
©Karl Samyn

Last modified :
         July 6 2012

3. Discrete Fourier Transformation (DFT)

Something what makes this package very powerful and unique is that it can handle the DFT.
With the DFT you can calculate the frequency content of a discrete signal with a limited length. But the DFT has also his restrictions and shortcomings. When you use the DFT you have to know what you're doing. In this way you suppose that the signal, from which you calculate the spectrum, is periodic with a period of the length of this signal. This is usually not true. The frequency content of a DFT isn't a continuous signal. It are also a number of samples (as much samples as the original signal) of the frequency spectrum. This means we have to take account of the resolution in the frequency domain. The DFT and his inverse are given by :

[formula DFT]

[formula Invers DFT]

The DFT can also be written in matrix form :

(see next version)

a. DFT of a sinus

Little example of a sinus at f=100 Hz and the DFT of this sinus, with in amplitude two peaks with value != 0 at 100 Hz and in phase two peaks with value = 0 at 100 Hz.

[figure DFT(sinus)]

b. Tuning of a guitar

  • Using samples

Take a classic guitar and play the note mi. We will sample this note. You can do this with a program like SAM.PRG. This program was supplied with every Falcon 030. Everybody knows that the frequency of a pure mi is 82 Hz, and of a pure la it is 110 Hz. So when we want to sample this note, the mi, we have to make sure that we take enough samples so we can make a correct digital version of our sampled note. SHANNON tells us that :

fs = (1/Ts) >= 2*fmax

But what does it say actually?
If you have a signal with a certain maximum frequency fmax, then you have to sample at a frequency fs that is 2 times fmax. If you don't do this you will have a loss of information.
So now we know we have to sample at a frequency higher than 164 Hz. But SAM.PRG samples only beginning from a value of 8 kHz. So do most of the programs. 8000 Hz satisfies definitely at the theorem of SHANNON.
When you take a look at the sampled note you'll see that the whole signal won't be the same. So select a part of 4096 samples that almost look the same. Why do you take 4096 samples. 4096 is 2^12 , with a power of two the speed of the calculation of the DFT will be increased (this is only true with FFT, because FFT is Cooley-Tukey with zero padding !). Save the selected sample. Now we only have a sample, we still can't use this in Eureka. We still have to convert this sample with an extension *.avr, *.wav to a file that Eureka can read. This should be a *.raw file. On the Atari you should use 525. Also SAM saves samples in RAW format. Hen you use a PC, you can use WaveStudio to do this. Now we have a *.raw of our sampled note mi that can be read in Eureka.

All these steps, described above have already been done for you. You can find the result in the directory /Fourier. In this directory you will also find some other files. See fig. 3.2.1

Now we can go over to the calculation of the DFT of our sample in Eureka.

[figure 3.2.1]

  • Calculating the DFT of our sample

Now we have to load the mi.raw file into Eureka. Go to the graph-menu -> data :

[figure 3.2.2]

We have to load a *.raw file, so click on the appropriate box :

[figure 3.2.3]

A file selector will appear. Load /Fourier/mi.raw .

We sampled the signal in 8 bits mono, click on the appropriate boxes : (warning : the samples are Unsigned)

[figure 3.2.4]

Like we now all know, we sampled at 8000 Hz :

[figure 3.2.5]

Now our data has been introduced in Eureka. The only thing we still have to do is to perform the DFT. (you can hear the sample at a frequency of 6258 Hz pressing A on the keyboard, otherwise press ESC for the other sampling frequency)

This we have to do like always. The system is Cartesian analytic.
So first we go to system -> cartesian. Here we introduce the borders of the plain. Normally these borders are :

abscissa : [0, fs/2]
ordinate : [0, 150]

But fs/2 means that our x-axis will go from 0 to 4000 Hz. And like we said before the frequency of the "mi" is 82 Hz. So we must get a frequency around the 82 Hz. Otherwise is our guitar not tuned very good, or did we play another note. That's why we will take these border limits :

abscissa : [0, 400]
ordinate : [0, 150]

This will give us a better view. Of course we won't see all what is after 400 Hz but in this case this isn't very important. But beware, you can't do this always, you might loose some important information.
Now we have to introduce our function to calculate the DFT.

We are only interested in the frequency content, so we will take the absolute value of our DFT. The function we have to use is . The second "d" stands for a "direct" transformation (inverse DFT : dftiL) and the L indicates which data series we will use. The data series we will use is our mi.raw, and since there were no other series loaded in Eureka, it is called the "a"-series.

We go to graph -> describe and enter our function : abs(dftda(x))
Now click on A, and you will get the DFT of the mi on your screen.

A file mi.img has also been included in the directory /Fourier. So you can verify your result with the right one.

  • Discussion of the result

On the graph you get on your screen you will see a lot of peaks, which one is now that one of the mi? And why are the others there ?

The answer to the first question is rather difficult. There isn't only one peak of the mi. There are a whole series of peaks. We have one major peak of the mi, the basic frequency. This is the highest one, at 80.5 Hz. We see that our guitare isn't tuined very well. The other high peaks are the harmonics (n*80.5) which are a result of the DFT (see n at the mathematic expressions). These harmonics decrease when the frequency gets higher. The basic frequency determines the pitch of the note. The ratio between the amplitudes of the different harmonics determine the timbre of the instrument. You can also notice a little peak around 110 Hz and one around 148 Hz. These peaks are here because not only the string of the "mi" vibrated, but also the string of the la (pure la : 110 Hz) and the re (pure re : 147 Hz).