Using Matlab's fft function
Вставка
- Опубліковано 13 чер 2012
- Explains how to interpret the values returned by matlabs fft function for well defined signals.
Notes on the DFT is available at pzdsp.com/docs/
The fft is an efficient implementation of the DFT discrete fourier Transform. For more tutorials on the DFT and FFT see • Video
Thanks for the selfless service. It's helping many university students and research scholars around the globe.May God be with you all the way.Also, long live youtube and google.
Thanks David. I have watched this for four at different times. Yours help me visualise the frequencies. Keep the work going!
This is a great tutorial on fft! I've watched it a few times over the years.
This has helped me advance my work on my thesis. Thank you so much!
You really did a wonderful job explaining this most complicated concept. Thank you.
your videos are so helpful. I literally learned signal processing here.
Hi, thank you for your presentation. I have one question. What are the effects of sampling frequency on FFT?
f_hertz = bin_num/N*fs
N = number of samples in the signal being analysed by the DFT
fs = sampling frequency
Actually f_hertz = (bin_num-1)/N*fs because Matlab's index starts at 1 (so index 1 corresponds to frequency f_hertz = 0)
Thanks! It's really useful! You've changed my life!
thanks Dave for all the excellent videos you published, great contents and pleasure to hear your english accent as well.
happy New Year.
Excellent explanation David Dorran sir.very helpful to me as a DSP Teacher. Thanks a lot
Thanks for the easy to understand video. May the force be with you!
Great video! Can you explain what the sampling frequency is? I am taking the FFT of my signal. The time domain data is 1 cycle and lasts 0.69 seconds long. So does that mean my sampling frequency is 1 / 0.69?
Great explanation. I really like the way you build the case for each step. I was able to follow pretty much all of the video. Thank you. I was wondering if by default the Matlab fft function would give the same answer if I was to use a flat top window (flattopwin)? In other words, is there a default window assumed in the fft function? I find windowing to be a bit confusing at this point, but I am always wondering if I need one.
thank you so much for making all the things clear to me. i read a lot of material but i couldnt really understand the idea of ffts and abs. You video helped me a lot more especially the relationship between the Bins and the freq. much much appreciated
+kutlo kgaladua Glad it helped. Nice to hear this feedback.
David Dorran hey David. do you have a video on the Goertzel algorithm?
Hello David
Thank you for quick response
I need to find the frequency without any leakage for a wav file like a piano wave file all the key frequency pressed using fft or any other code
Thanks
Thank you so much, Sir. I have tried the same program what you explained, but I have used the 'sin' instead of 'cos' to get the time domain amplitudes (small x). Every thing is good except the phase shift is not matching. Could you please help me, I want to know where I made wrong.
You literally saved me. Many thanks
thank you ,that really helped me a lot, keep up the good work .
Great explanation!
Excellent video !! Solved most of my doubts
clear and straight forward,very helpful.it'll be great if any DC component involved.
Pretty sweet video man, thanks!
Hi David, very nice explanation. Appreciate a lot
Thank you very much for your knowledgeable video. I am working on EMG signal . I made a device which taking EMG signal from human body. The signal I took looks like good. But I don't know how to get frequency of this signal. I have ADC,sampling time,total sample and also used fft to get frequency. But its giving 0.03 Hz (Aprx.) which seems to me not correct. Because EMG signal frequency range is around 5-450 hz. So my question is do I need to change ADC or any other things thats give me correct frequency?
Thanks a lot! Very Clear! Good Teaching!
Hi David, this tutorial is very helpful. Thanks so much. I do have an enquiry. I am processing trajectory data (much like accelerometer data) from a patient who has neurological tremor. My data set consist of 2048 data points collected at 250Hz. I followed the tutorial but I do not know get the dominant frequency of the tremor. Would the solution be to convert the bins to Hz? If so, how do I go about doing so? Thanks again.
that was great and it worked perfectly :) the only thing is that it gives a value for the peak_val (eg.8.8012e+003) but the peak_location always appear to be 1, is there any way i could change this to get values because i need the height of the peak and the time at which it occured. Thanks again
Thanks, Do you know how to analyse non-stationary signals where the frequency changes with time? FFT doesn't seem to work with me or at least using it in the same way doesn't make any progress.
One approach is to segment the signal into frames and analyse each frame using the fft. There are issues related to frequency resolution in doing this but this process would be my starting point.
ua-cam.com/video/wpXtsRpaLOA/v-deo.html - frame analysis
ua-cam.com/video/eg8eebQPfAo/v-deo.html - frequency resolution
Does the magnitudes corresponds to the coefficients of the fft of that function?? Thank you in advance!!
wow best explanation on the internet
Hello David,
I am conducting a series of tests with wave propagation but am now having some difficulties! I have a .csv with the information regarding the waveform (time, channelA [mV], channelB [mV]) and I need to know the dominant frequency of that wave. My problem with using the FFT to figure this out is that I don't have the wave function required in this tutorial neither the Frequency Sample (fs) because the trigger is a spring with a hardened point which contacts with the rock sample.
Do you think you can help me?
you are my savior, thanks a lot
Hello David,
I am conducting a series of tests with wave propagation but am now having some difficulties! I have a .csv with the information regarding the waveform (time, channelA [mV], channelB [mV]) and I need to know the dominant frequency of that wave. My problem with using the FFT to figure this out is that I don't have the wave function required in this tutorial neither the Frequency Sample (FS) mentioned in other tutorials because the trigger is a spring with a hardened point which contacts with the rock sample.
Do you think you can help me?
Thanks so much! You saved me!
Hello Dr.David.,
I'd like to ask you the following: How do i get, via code in matLab, not via users analysis , the correspondent frequency of the amplitudes ploted?
Thank You Very Much for the Atention,
José Lucas
Jose Lucas Cordeiro This video might help ua-cam.com/video/tvrweDqrLSg/v-deo.html
Very helpful.
Thank you for sharing.
Really wonderful explanation. Thanks for making this. I wonder if you could go on to explain how to change with window settings to give different amounts of bins when you plot the power.
Does the following video link help? ua-cam.com/video/2IkdNsGQgEM/v-deo.html
Thank you for this awsome video!!!! it was really helpfull
you would get a plot of the phase spectrum i.e. the phase values associated with each frequency bin.
Very informative! Does this also work if I have a set of discrete points instead of a continuous signal?
Of course
how do I get , sin wave amplitude in y-axis instead of magnitude
I need to understand why did you substracted 1/fs , could you explain it in some other video or tell me where can I found the explanation i.e some book. thanks a lot
should i need to deduct one every time to get the correct answer. please tell me David Javaid
How can I use FFT to determine if a sound wave is Harmonic?
thank you very muuuuch!!! I will appreciate if you keep analysing signals in frequency domain. :D
Thanks for the educative video, surely helped a lot.
How to you convert bind to Hertz ? Thank you very much in advance. Much appreciated.
Do you have a rough idea of what frequency the tremor would be? You can send the data on for me to look at, on condition you'll allow me use the data for teaching/training purposes - I'm always trying to get interesting real-world signals for my students to analyse!
Thank you so much. Very helpful video.
hello i am working on a FMCW Project and have a problem to plot the baseband Signal after mixing the recive Signal and the transmited one.?? please help me!!!! :( :( :(
Hey I need help. I want to do 8 sampling of this signal, how should the code be like?
Fs=1000;
T=1/Fs;
L=8;
n=(-2:L-3)*T;
x=cos(((pi/4)*n)+pi/6);
X=fft(x);
y=length(X);
X_mag=abs(x);
X_phase=angle(X);
stem(X_mag);
X_phase=angle(-1);
I would like to fourier transform four columns, one column represents pixel values at 0 degree phase, second column 90 degrees, third 180 and fourth 270 degrees, so i would like to create amplitude image from amplitude data after fourier transform. i have binary .raw file images. how can i do this? i fread the images, convert the pixel values in four columns, and get amplitude data. but i could not see the image.
Dear Dr. David,
Could you tell me what bibliographic reference did you use to know that the factor of N/2 can be used for each spectrum beam to represent the amplitud of the sinusoids ?
Alejandro Rodríguez I can't remember where I first read it. Any DSP text book will mention this. dspguide.com is an online book you can check out.
Thank you for your instruction.
Hi David, very good presentation. One question I have is that the 3 bin values seen in the freq. bin plot were 31, 46 and 61 instead of 30 (750*20/500), 45 (750*30/500) and 60 (750*40/500). Why the values seen in the freq. bin plot are +1 the expected calculated values?
The index into a Matlab array starts at 1 and by default Matlab will plot the indices of the array against the values in the array. Most programming languages and mathematical notation will use 0 as am index to the first element in an array. The first bin is referred to as the 0th bin.
How to use DFFT in image processing? thanks for the video
thank you very much on this very well discussion and learning FFT function i think your method to illustrate this concept is ideal thanks very very much
Hi I was wondering if it was possible to do a FFT in matlab with data from an external file. I have a text fill with 10000 results and i need to put these into a fourier transform and then plot this and then find the peak on this plot. Any thanks would be amazing, thanks
Nice tutorial.
Great tutorial.. thx a lot!
Thanks for the video! This is a great introduction.
I'm wondering how you can find the frequencies and amplitudes from the FFT without reading them off the plot. In this case, we knew the frequencies in advance, but how would I find that they were exactly 20, 30 and 40 Hz if I only had the FFT? Thanks!
You would use some code to find peaks within the magnitude spectrum.
For example in matlab it would be something like the following:
fs = 1000;
N = length(x);
X = fft(x);
X_mags = abs(X(1:N/2)); %magnitude spectrum of first half
[pk_vals pk_locs] = findpeaks(X_mags);
%remove pks below a threshold
inds = find(X_mags(pk_locs) < 1);
pk_locs(inds) = [];
%determine frequencies associated with the peaks
pk_freqs = (pk_locs-1)/N*fs
Thank you very much for the quick reply!
Hi David, Thank you for the video. I have one question, why are the peaks shifted right by one frequency bin?
It's down to how matlab indexes its arrays. The first element in a matlab array has an index of 1 which corresponds to bin number 0. This isn't an issue in most other programming languages where the first element of an array uses an index of 0.
Okay. And does bin number zero represent the dc quantity in the signal?
Hi dear Dr. David ,
As i know that you know well of FFT(Fast Fourier Transformation).
FFT are working in 2^N Data , But how to do calculate MATLAB without 2^N data
i am face a problem that MATLAB are work without 2^n Data, but i am not able to do this Please Help me
Very useful!! Thanks a lot!!
Try the following (it should work if there is just numerical data in the file which is formatted neatly i.e. spaced or with each value on a new line):
ip = load('filename.txt');
X = abs(fft(ip));
plot(X)
[peak_val peak_location] = max(X)
What happened if you plot the X_angle?
its very nice lecture.
sen adamsın bilader.
Very helpful - thank u very much
is the right hand side mirror image information pre-filter ringing?
Hi Rob. They are associated with what are referred to as negative frequencies. Check out ua-cam.com/video/M1bLPZdNCRA/v-deo.html.
Hi David,
How can we decide sampling frequency for a continuous signal?
+Ashu Sharma it supposed to be twice or greater than that frequency of your continous signal. Nyquist criterea.
Hello Dr. David,
can you tell me the logic mathematically as to why fft function produces a mirror on the right side after half of sampling frequency?
Muhammad Irfan First point I'd like to make is that this is only the case when you are dealing with signals which have no imaginary terms.
The reason for the mirror image requires an understanding of negative frequency complex exponentials which is explained in ua-cam.com/video/M1bLPZdNCRA/v-deo.html
Complex exponentials can be visualied as shown in ua-cam.com/video/K_C7htSXORY/v-deo.html
David Dorran Thank you very much :)
I don't know whether this is correct, but here is an intuitive answer:
Isn't it because of potential aliasing which could have happened during the sampling?
A continuous sine wave at 0.95 times the sampling frequency (0.95*Fs) would be sampled in the same way as a continuous sine at 0.05*Fs due do aliasing.
Thus, the sampled signal resulting from a continuous 0.05*Fs sine wave could be the result of sampling a 0.05*Fs or a 0.95*Fs sine wave, which is why both show up on the fft
(The same sampled signal could also originate from a sine wave at 1.05*Fs or 1.95*Fs, but the fft spectrum ends at 1*Fs, which is why we don't see those frequencies on the spectrum.)
Disclaimer:
I haven't yet watched the video on negative frequency complex exponentials and do not know what those are. Maybe my answer is circular reasoning, because the next question could be: "Why does a 0.95*Fs sine alias as a 0.05*Fs sine?"
Please, anybody who knows more about this than I do:
Does my answer make sense? Is there an error in my understanding of the matter?
Not sure if this would still help, considering you commented 9 months ago. Anyway, your reasoning is not wrong per se, but as you've figured, it's circular reasoning. Aliasing is the consequence of the negative frequencies, and not the other way round.
- For discrete time signals, the frequency spectrum is periodic with period f_s (there are many sources that explain this; see DTFT & DFT).
- This means that the frequency components from -0.5f_s to 0 (bin -0.5N to -1) are the same as the components from 0.5f_s to f_s (bin 0.5N to N -1). N is the number of bins in a period.
- I can take a period in the frequency domain to be from -0.5f_s to 0.5f_s (bin -0.5N to 0.5N -1) instead of 0 to f_s (bin 0 to N -1).
- Most importantly, for real signals in the time domain, the component of any frequency -f_k is the conjugate of the component of f_k. In math terms, F(-f_k) = (F(f_k))*.
- In terms of bins, the component of bin -k is the conjugate of the component of bin k: F[-k] = (F[k])*.
- The reason why they are conjugates is because when we combine the sinusoids to reconstruct the time domain signal, we need the imaginary terms to cancel. If F[-k] ≠ (F[k])*, the imaginary terms do NOT cancel and we end up with a complex time domain signal.
- Complex conjugates have the same magnitude: |F[-k]| = |F[k]|. Also, don't forget the periodicity: F[k] = F[N+k].
- This means that |F[k]| = |F[N-k]| = |F[N+k]| = |F[2N-k]| = ...
- Aliasing just follows as a natural consequence of the above. The "mirroring" would be the first 2 terms.
It was fantastic video. Thanksssss
how to get frequency using fft function with guide?
yes. There is a difference of one between Matlab's indexing of its arrays and the corresponding bin number.
X(1) in matlab refers to bin 0, for example.
Note that this is an unusual approach to indexing. Most programming languages will use 0 to refer to the first element in an array.
David Dorran hi, thanks for the great video! I am trying to plot fft for a set of discrete points but I am unsure how to calculate what the frequency on the x axis should be?
David Dorran for reference I have solved a system of 3 differential equations (Lorenz system) so I am not sure what Fs would be
Thank you very much sir !!!
Hi David
thank you for this great video, but i am confused on how you specified fs or sampling frequency. Actually I am performing fft and psd analysis of pressure values (fluctuations) over time (with a fixed time step dt) , so will the sampling frequency be 1/dt?
yes Ramandeep. It'll be 1/dt.
David Dorran thank u so much :) do you a video on PSD using pwelch functions and windows used for this function ? :)
I'm afraid not
Would is the difference between taking the abs(fft(X))/length(X) and multiplying X by its complex conjugate? I saw this being done but what changes is the scaling of the Y axis.
It is the case that if x = a+jb, then abs(x) = sqrt(x*conj(x)).
So you could determine the magnitude by multiplying the result of the fft by its conjugate and finding the square root of the result. Howeve you'd still need to scale by the length to get the amplitude of the corresponding time-domain components.
David Dorran Thank you for the prompt answer! I'm not a mathematician, if I may, could I ask what would be the other cases that are not x = a+jb? You mean, not always I can take the fft and apply that rule?
Gahariet Melanthios You can use that rule always for the fft. Apologies for the confusion.
David Dorran Great, and thanks! By the way, where are you from? Exotic accent.
Gahariet Melanthios Ha ha! My accent has certainly never been described as exotic before! I'm from Ireland!
The fuck happened to you mic 13 minutes in?
Thank you so much for this vid, it helped a lot! Also ASMR voice
Thank you.
Hello Dr. David,
I need to find the difference between dropping sounds of Copper and Gold using frequency peak. So far I took the fft(); of both sound files and plotted the amplitude/freq. diagram. How should I continue with my progress?
Thanks!
Atakan Arıkan You could look for differences in the plots that reoccur for multiple drops and use those features to differentiate between the two sounds.
Uuu8u. Pcsaaa! ... :
Apollonkyyyt! Cdx9kxkxkiop0nkmzkkxo
tnx. It is very useful. Please make a video on matlab pwelch...
Thank you very much
your bin no here is 31 for lower frequency one. it is giving me 31/1.5*2 which is not exactly what you have assumed as 20 Hz.
Good tutorial video
Your video is great, thanks... Just if you can enhance the recording quality, it'd be much better 🌸
Yeah. It's not great. When I put the video up I didn't anticipate it would become popular!
I'm afraid the answer is quite involved and requires a good understanding of the Discrete Fourier Transform (DFT). Check out the chapter on the DFT on the dspguide website.
Hello David,
I am new to FFT concept and i have been going through all your playlists to learn more about digital signal processing using matlab. Many thanks for the wonderful job you have done here to help us all out.
Here in this video,
1) How did we get the initial magnitude values for all the frequencies? Like i have no idea how did you get the value over 2000 for the lowest frequency and then in the ratio 3:1:2 for the remaining 2 frequencies.
2) I am also unable to make sense of why we would divide by number of samples to find the absolute value while we have already used the abs function to find our absolute values.
It seems like we already had it multiplied somewhere and we just divided by the number of samples to bring it back to the 3:1:2 ratio.
I am really confused in this concept of getting the absolute and also the 1st point.
Kindly help!
And going through the video over and over i also came to realise that : We have a column of 1500 samples which have 1500 signal value at every sample point. We perform FFT over every sample point and generate Frequency domain information from time domain information in exactly 1500 rows in a column. What i do not understand is that i take up row number equal to the value of my frequencies and find out the magnitudes of these rows is the highest.
All i mean to say is i find it surprising that the a column of 1500 time samples transforms into a column of 1500 frequencies and then we just pick up the right frequencies and see that they have the magnitudes in the ratio of their amplitudes.
I saw it again and realized that the bins just do not simply relate to the frequencies. Infact then you show there is a relation and i zoomed in to find out that the frequencies 20,30 & 40 and sitting at bin numbers 31,46 & 61. And the bins and frequencies in this case are also very close because of the number of samples not being very different from the Max frequency.
I changed my time to 2.0s (2000 samples) and the frequency values shifted to 41,61 & 81.
So now my confusion that the bin values were directly related to the exact frequency values is busted.
Hy David, ty for the video. I would like to restore the X from the magnitude and the freq. I use F = mag_X.*exp(t.*sqrt(-1)) to d it but I can't get the normalization of t right. What t should be in our example? Thanks in advance
The following should get you on the right track for real signals.
t = (0:N-1)*1/fs; % N is the length of the signal
F = mag_X/(N/2)*cos(2*pi*freq_X*t + phase_X);
ty
@@ddorran Hi, why do we divide it by (N/2)? If we do so, do these correspond to Fourier series coefficients?
Hey David,
I tried the angle to find out the phase of the signals. Its not returning the exact values of the phase those are used in the signal but an order of 10^-2 less or higher than those values. I am using Matlab 2013a, 2011a. What could be the possible reason for that? Would appreciate your help.
+Someswar Dutta You'll notice that in the example that I provided I had exactly an integer number of cycles in the signal I analysed. If this isn't the case then the phase values are less predictable.
Спасибо!
Y=y1+y2+y3+.....yn. I have Y signal. i want to extract y1 y2 y3 .... yn signals out of it. I used fft function and got the frequency spectrum. but the frequency domain didn't consist of any particular-clear peaks. I have tried zero padding and windowing too.
The objective is 1) to get the information about every sine wave 2) if i combine all the sine waves together i should get back of the original signal.
Is there any direct method to extract every sine wave from fft. ?
Thanks in advance.
If y1, y2,etc. are sinusoids of different frequencies then this is possible (even relatively straightforward) but of they are more general signals then this becomes extremely complicated. The problem is known as source separation in audio signal processing and there are numerous approaches which are quite complex.
Hi david! thank you for yours helpfull video tutorials. I would like to make a question to you. I'm trying to do the fft of a vector(X) with 2000 values. I started calculating b=fft(x); then i found the modulus c=abs(b) and finally i plotted c: plot(c).
I think the result it's not correct because observing the plot i can see two peaks on the left hand side and only one on the right hand side. Now i know tha my starting signal it's generated by a sin+gaussian noise so i imagine that i should obtain a plot with only two simmetrical peaks. i hope in some help. thank you for your great job
Is there a peak at bin 0? If so then you have DC offset in your signal. The DC component is a special case and isn't 'reflected' on to the right hand side of the double sided spectrum.
David Dorran no i generated my signal with sin(2*pi*100000*t) plus and additive white gaussian noise. i acquired my signal with an oscilloscope in a time-window of 2 ms. So i have no DC signal. i supposed that maybe it's because my vector have not a power of two elements. what do you think about that?
The power of 2 is irrelevant. If the discrete signal has no DC component and contains only real values, i.e. no imaginary terms, then it has to be symmetrical.
Francesco Vatrano every other day and the other side of things to be a great day to get to the inbox to the inbox to the phone and I will have a good time and the kids are in the bank account details are as below the email and any other questions please feel like I was wondering how much I love the opportunity and I have a
Francesco Vatrano to TD by TD TD Rd Ed he ifg August IH he is not a problem for me know if you are not in a few weeks ago I was thinking about you but I am a very good and the kids are doing well I was wondering if I have a good time and consideration and time for me to be able to make sure to check the attached file for my son is a good day to day basis for further details on the sake I have been able to make sure to my other email I sent from my frame and the guy that was in the past and present to the inbox by boomerang view Post by the end up in a few days and then you can get the chance to see the status is a great weekend to get to know what to say that the phone with you and your family and I have a great weekend to get the chance of getting a little more about your order has been off for me to be a problem with my own family and I will get back with you to the phone with me on my way to do it is not a
nice explanation
Great video, especially like that you named two variables with the same letter! :/
THANKKSSS!!
I am confused how to use exponential function of x
So is it amplitude or magnitude. Can anybody explain to me the difference?
Magnitude doesn't have a sign or direction associated with it. So an amplitude of -1.25 has a magnitude of 1.25.
Sir i have transfer fcn. in z-domain H(z) and i want to plot |H(w)|,,,,how can i do that, and can you make a tutorial about this topic, that would be great , thanks in advance
+67artun substitute z with e^(jw) in the H(z) expression to get H(w)
The best