# Accurate scaling of Fourier coefficients

A free video tutorial from Mike X Cohen
Neuroscientist, writer, professor
4.6 instructor rating • 20 courses • 110,831 students

## Lecture description

The units that fft outputs are "wrong"; learn how to fix them!

Master the Fourier transform and its applications

Learn the Fourier transform in MATLAB and Python, and its applications in digital signal processing and image processing

06:41:42 of on-demand video • Updated April 2021

• Learn about one of the single most important equations in all of modern technology and therefore human civilization.
• The fundamental concepts underlying the Fourier transform
• Sine waves, complex numbers, dot products, sampling theorem, aliasing, and more!
• Interpret the results of the Fourier transform
• Apply the Fourier transform in MATLAB and Python!
• Use the fast Fourier transform in signal processing applications
• Improve your MATLAB and/or Python programming skills
• Know the limitations of interpreting the Fourier transform.
English [Auto] Usually in the foyer transform, you want to be able to relate the power spectrum directly back to the signal that you measured, and that means that you need to have the results of the Fourier transform in the same units as the original signal. But this is not natively the case. And the purpose of this video is to show you the two normalization factors that you need to include in the foyer transform in order to have the results of the Fourier transform be in the same units, the same scale as the original signal. First, I'd like to demonstrate to you that the results of the Fourier transform do not have the correct units natively. So here we are in Matlab. This is really easy to demonstrate using simulated data. Simulated data is always a great way to test analysis methods because you know what the ground truth is and so you can easily check your results. So here I'm simulating a sign wave at four hertz with an amplitude of 2.5. Here I run the foyer, transform exactly as shown in a previous video, extract the amplitudes of the foyer coefficients as the magnitude of the complex. For the coefficients here, I compute the frequencies vector in Hertz. So we go linearly spaced numbers from zero up to Nykvist in and over two plus one steps or GNR is the number of time points in the signal. OK, and then I just make a stem plot of the amplitudes. So you can see that the frequencies are correct, we have zero energy at all of these frequencies here, positive energy at for her. So that part is consistent. However, the amplitude here is somewhere around 1900, which is definitely not 2.5, which is what we specified. So the amplitude value is definitely incorrect in this case. And it gets even worse than this, because if I make the signal longer, that's going to affect this amplitude value. So here I'm stimulating up to one point five seconds. If I would go up to three seconds, for example. Now the amplitude appears to be even higher than it was before. So this leads us to the first normalization factor, which is to divide the four year coefficients by the number of time points. So I can do that. You can do that inside the loop or you can do it outside the loop here. I'll do it outside the loop. So I'm going to say F clefs equals F Karloff's divided by points. The reason why you have to divide by the number of points in the signal is that the basis of the foyer transform is a dot product between the signal and the complex sine wave. And so this involves adding a lot of additions, a lot of summations. And so the more numbers you add, the larger the DOT product will get. So by dividing by the total number of points, essentially we are taking the average of the DOT product or this measure of similarity between the signal and the sine wave. So let's try running this again. OK, so now we get a value of a little over one point two. In fact, it's one point twenty five. So that's still not the correct value. But at least with this first normalization factor, this is now going to be robust to the length of the signal. So watch, when I change from three down to one point five seconds, I can rerun the code. And that doesn't change the amplitude value. It's still at one point twenty five. But the amplitude still doesn't match the value that I specified here. In fact, it seems to be exactly half of the correct value, which it is. This is two point five that I specified. And here I only see one point twenty five. So what's happening here is that the amplitude gets split between the positive and the negative frequencies, as I explained in a previous video, and because the amplitude of the negative frequencies is the same as the amplitude of the positive frequencies, in practice, what you can do is ignore the negative frequencies altogether and simply double the amplitude of the positive frequencies. So that's what I'm going to do here and say two times the magnitude of the coefficients. And then here I'm only plotting the first half of the spectrum, which corresponds to the positive frequencies. So now I can run this again and now we get the correct amplitude, 2.5 and you can test that. That is robust to the total duration of the signal. So here, I'll do four point five seconds and this remains the same. You can try changing this to, let's say, two point eight five. And now this becomes well, I guess it's harder to see in this case. Let's set it to be four. Now, you can see it's at exactly four. So now these two normalization factors are correct. Divided the four year coefficients by the length of the signal, the number of points and signal and multiply the positive frequencies by two. Now, it turns out that this is not entirely 100 percent accurate, the way I've written this here, this is a little bit of a shortcut, and that's because the DC component or the zero frequency component does not have a corresponding negative frequency. So, in fact, you only double the amplitude of the positive frequencies between but not including DC and Nyqvist. It turns out that in this particular case, with this signal, that doesn't matter because there is no zero hertz component that's already at zero. So multiply that by two or not. Multiplying it by two has no effect. I will have more to say about the special case of the D.C. frequency in a separate video on the DC component. In this video, I showed you the two normalization factors that you need to apply in order to accurately reconstruct the amplitudes of the 48 transform in the units of the original signal.