Fourier Transforms FFT in MATLAB | MATLAB Tutorial

Поделиться
HTML-код
  • Опубликовано: 29 янв 2025

Комментарии •

  • @rostamr4096
    @rostamr4096 Месяц назад +1

    Thank you, you make the best tutorials, hands down...

  • @samblake9953
    @samblake9953 Год назад +1

    Really awesome, a couple light bulbs definitely went off throughout this video

    • @philparisi_
      @philparisi_  Год назад

      Perfect!! Glad some things clicked for you

    • @samblake9953
      @samblake9953 Год назад

      @@philparisi_ with high frequency samples can you expect it to get a lot harder to distinguish between where to start zeroing out frequencies? my data samples @ 440 hz and my subplots are coming out as a jumbled line (amplitude) or a massive mess of values with no order (phase angle)
      you responded to my comment so i figured id ask!

    • @philparisi_
      @philparisi_  Год назад

      @@samblake9953 Hmmm that's really hard to say as I am too far removed from the problem at hand. In general I would expect the FFT to perform worse when you have sparse data (hard to determine what frequencies are present when you aren't fully sampling the signal). 440Hz may be enough for your application, but this goes into the Nyquist sampling theorem to ensure you are sampling high enough!

  • @alexarunyan
    @alexarunyan 3 года назад +2

    Thanks for the helpful reminder to filter out the insignificant frequencies every day

    • @philparisi_
      @philparisi_  3 года назад

      Just focus on the dominant ones!

  • @黃毅民
    @黃毅民 2 года назад +4

    Thank you so much!! This video really helps me a lot on my graduate project of master's degree!! Hope you can keep on helping others. By the way my name is Jonathan.

    • @philparisi_
      @philparisi_  2 года назад +2

      Hi Jonathan! Glad I could help out. Be sure to use the most updated code here: github.com/PhilParisi/YouCode/blob/main/fourier_transform.m
      Let me know if you have other questions!

    • @黃毅民
      @黃毅民 2 года назад +1

      Hi! Phil, after few weeks of working, there are two questions I want to ask:
      1. At 9:03, I still can't get it why is the first term of amplitude spectrum be the mean of the dataset? Could you explain more details, please.
      2. At 5:59, why would some people prefer to use the zero mean data? What are the differences between keeping the mean and not keeping it? Also, is there any advantages of keeping the mean in the data?

    • @philparisi_
      @philparisi_  2 года назад

      @@黃毅民 Hi Jonathan! Great question. The mean can be useful (or useless) depending in your application. Let’s say you are trying to determine the ocean height (tides) of the coast of an island. The data you are able to record is depth of ocean, and you record data from a sensor with values between 50m to 52m over the course of a day.
      In this example, one does not care about the mean of 51m, but does care about the +/- 1m FROM the mean. So de-meaning the data in this case would be useful for viewing the data and the subsequent analysis.
      Note that if you de-mean the data, the FFT still does the same thing. Simply, the first reconstruction term (the mean with no frequency) will have a value of zero (rather than 51 if you kept the mean in).
      The reason the FFT gives you the mean in the first place is because you are breaking the signal down into components. The components have varying frequency from 0 to a max_freq (depends on how many components you have). A component with freq = 0 does not ‘move’ or fluctuate with time. Meanwhile, all the other components have freq ~= 0 (not equal to zero) and will fluctuate with time. It can be reasoned that the only feature if the data that doesn’t change with time be the mean, and the deviations from the mean could be represented as components that vary with time!
      Lastly, if you would like additional help, consider becoming a Patron! I provide a ton of support to help you better understand concepts, answer all your questions, and edit your code to get things working -> saves you lots of time! www.patreon.com/philsbeginnercode

  • @milanandesilic896
    @milanandesilic896 2 года назад +1

    Hi Phil, thanks for the great video! But I believe you should be adding a .' to transpose the X_norm variable into a column to preserve the correct complex number. Matlab will give the complex conjugate if you just put ' on its own after the variable

    • @philparisi_
      @philparisi_  2 года назад +1

      Hi Milan, thank you for pointing this out. I corrected it in the script and have the code available here
      github.com/PhilParisi/YouCode/blob/main/fourier_transform.m

  • @naftilos76
    @naftilos76 2 года назад +8

    Hi Phil, isn't the Fs supposed to be samples/sec just like you indicate in the comments? Well that (frequency) would be 1/period. 0.5s is the period not the frequency! So the frequency should be 2 samples / sec (1/0.5). Pls correct me if i m wrong.

    • @philparisi_
      @philparisi_  2 года назад +3

      Hi Naftilos, thank you for brining this up. I think you may be right!
      We have 32 datapoints over 16 seconds, which means we have 32 samples / 16 seconds = 2 samples/sec. Fs = 2; T = 1/Fs, T = 0.5.
      So in reality the Fs should be Fs = 1/mean(diff(t)); in Line 12!
      What's intriguing about the FFT is it has a way of hiding errors. Most mathematical procedures would have found my error when recreating the signal, yet the frequencies here tend to be independent when it's reconstructed.
      Upon correcting the Fs, this changes the Amplitude and Phase plots --> instead of going from 0 to 0.5, it should go from 0 to 2 for frequencies. I have updated the pinned comment on this video to reflect that error. Thank you!

    • @blackcoffee9470
      @blackcoffee9470 Год назад

      Thank you. I noticed this as well. Thanks Phil for the clarification.

  • @BDCVT-VuQuangLuong
    @BDCVT-VuQuangLuong 8 месяцев назад

    16:00
    Can I use fftshift( ) function instead of "reconstruct using k dominant frequencies" code ?

    • @philparisi_
      @philparisi_  8 месяцев назад

      I’ll have to refer to the MATLAB documentation for fftshift() on this one, as I haven’t used that function before
      Run ‘doc fftshift’ in your command window

  • @guruparan7510
    @guruparan7510 Год назад

    Hi Phil, the Sampling frequency is actually 1 divided by mean(diff(t)) , because in your code mean of diff(t) gives only the mean of delta t ?

    • @philparisi_
      @philparisi_  Год назад

      Hi Guru, from a quick look I think you’re right! I’ll dig more into this later and make updates accordingly.

  • @philparisi_
    @philparisi_  3 года назад

    UPDATED CODE HERE:
    github.com/PhilParisi/YouCode/blob/main/fourier_transform.m
    ERROR 1 in video. UPDATE Line 12 to:
    Fs = 1/mean(diff(t));
    This error shows up on your Amplitude and Phase Plots, the x-axis frequencies should be 0 to 2 Hz (not 0 to 0.5 Hz). My apologies!
    ERROR 2 in video. Between Lines 40-50 when we make the table of values:
    Change the X_norm' to X_norm.' (add a dot before the apostrophe)
    This ensures that the data is purely transposed as opposed to the conjugate transpose.

    • @mohammedalharbi1034
      @mohammedalharbi1034 2 года назад

      It is one of the best videos, I've ever seen 😍 ... can you support to add sine waves summation for dominant frequency/amplitude/phase using sine wave equation ( amp × sine*2pi*f*dt+angel ) instead of using IFFT function of X_recon_dom(i)... please help, appreciated

    • @philparisi_
      @philparisi_  2 года назад

      @@mohammedalharbi1034 I can't promise I will be able to support, but can you provide a link to the method you are describing?

  • @PashuLLer_2OO7
    @PashuLLer_2OO7 5 месяцев назад +1

    Top video, thank you!

    • @philparisi_
      @philparisi_  5 месяцев назад +1

      You are very welcome!

  • @kiriakospipigkas5090
    @kiriakospipigkas5090 2 года назад +1

    Do you have to make any change if the sample frequency is 0,005 ? I mean 0.00000-->0.00500-->0.01000-->0.01500 etc. Or i will just take Fs=0,005?

    • @philparisi_
      @philparisi_  2 года назад

      Hi Kiriakos, you should be able to change Fs in the code to whichever value you want and everything should adjust accordingly 👍🏽

  • @tomasastudillo3139
    @tomasastudillo3139 2 года назад +2

    Best explanation! Thankss

    • @philparisi_
      @philparisi_  2 года назад

      Thank you Tomas! Glad it could help.
      Be sure to update Line 12 if you haven't already!!
      Fs = 1/mean(diff(t));
      This error shows up on your Amplitude and Phase Plots, the x-axis frequencies should be 0 to 2 Hz (not 0 to 0.5 Hz). My apologies!

  • @hariskhan485
    @hariskhan485 6 месяцев назад +1

    Thanks, can you do this with large data and reconstruct them and with Unperiodical signals

    • @philparisi_
      @philparisi_  6 месяцев назад

      Hey there, you can certainly use Fourier Transforms for large data.
      For non-periodic data, you may consider spectrograms. They do fourier transforms on portions (section in time) of your data.

  • @med7756
    @med7756 2 года назад +1

    I think you should multiply the left hand side amplitudes by 2 to get the exact amplitudes at each frequency and to get rid of all other amplitudes on the other right hand side . Am I true?

    • @philparisi_
      @philparisi_  2 года назад +1

      Hi MED, I think you're on the right path. I didn't 'fold over' the amplitude/frequency diagrams in this tutorial. The fold would effectively double the amplitudes and put them all on the right hand side, as you mentioned.

    • @med7756
      @med7756 2 года назад

      @@philparisi_ thanks for your efforts

  • @cryfier
    @cryfier Год назад

    Can you maybe say where you get this A*cos(2pi*f+phase) from? Where did the sine go? Why do you use plus for the phase?

    • @philparisi_
      @philparisi_  Год назад

      Hey there, I'd suggest digging into MATLAB's documentation on this one, they have good examples as well www.mathworks.com/help/matlab/ref/fft.html
      Can't guarantee my approach is exactly right, depending on which set of theory you want to use. I will be updating this video soon with some improvements and clarity. Every grad class I take seems switch between sin and cos, but I don't have a good answer as to why... except for there are likely trig identities that allow for this.

  • @caistead5622
    @caistead5622 2 года назад +1

    Hi, thank you so much for the video! I am trying to use this method to find a Fourier transform for a collection of irregularly spaced values. My reconstructed graph matches on matlab, but when I plug in the amplitude, phase and frequency into a graph the graph no longer matches my raw data. Any idea what I have done wrong?

    • @philparisi_
      @philparisi_  2 года назад

      Hi Cal, it's pretty hard to know what's off without knowing your setup, code, etc.
      In general, you should be able to use fft() and then ifft() to go back and forth easily.
      Then, if you want to manually reconstruct your data, be sure you aligning the proper values up with each other. Typically the 'first' term of your FFT is the 'average' or 'DC value' that will have no oscillations (it's simply a constant value like 4.2 or something) - don't forget that term!
      That's the best I can give you going blind here!

  • @answertoextremism
    @answertoextremism Год назад +1

    very well explained, how can we use windowing in the code

    • @philparisi_
      @philparisi_  Год назад

      Hi Muhammad, thanks for watching! What do you mean by ‘windowing in the code’?

  • @hakimacherifi5636
    @hakimacherifi5636 Год назад +1

    How I used FHT fast hartley transform in matlab or simulink from the FFT

    • @philparisi_
      @philparisi_  Год назад

      Hi! I‘ve honestly never heard of the FHT, you‘ll need to consult MATLAB‘s documentation on this one!

  • @harrisonedokpolor2642
    @harrisonedokpolor2642 Год назад +1

    How can plot the FFT of accelerometer data with three axis

    • @philparisi_
      @philparisi_  Год назад +1

      I would look at each axis vs time and do 3 FFTs separately

    • @harrisonedokpolor2642
      @harrisonedokpolor2642 Год назад

      Thanks, is it possible to do the FFT of an accelerometer values in real-time ? That is, as the data are streaming, we see the FFT moving.

    • @philparisi_
      @philparisi_  Год назад

      @@harrisonedokpolor2642 I have never done this, but it should be doable. Here's how I would approach it:
      1. get the data streaming live into MATLAB from your sensor
      2. segment the data so you are looking at the most recent window in time (i.e. most recent 2000 points let's say)
      3. when you isolate that window of data, queue up the streaming data as the 'next data'
      4. perform an FFT (as shown in this video) on the current window of data and display that. then move onto the 'next data' and perform an FFT on that. And so on and so on.
      You will need to tweak your system/pipeline based on how much information is needed to get good FFT values (100pts? 1000 pts? 100,000 pts? Your sensor data rate is also important. And how fast your system can process FFTs and display. Play around with it and have fun, there may be packages that already exist in MATLAB (or other languages) that do exactly what I have described. I'd suggest looking around in Simulink as well to see.

  • @antoine1407
    @antoine1407 Год назад +1

    Could you please make a video on how to get the power spectrum density from fft? It would be very useful

    • @philparisi_
      @philparisi_  Год назад

      Hey there, I plan to make an updated FFT video in the coming months, and I’ll try to include power spectrum density too. Thank you for letting me know!

  • @guliyevshahriyar
    @guliyevshahriyar 7 месяцев назад +1

    Thanks

    • @philparisi_
      @philparisi_  7 месяцев назад

      You are welcome! Fourier can always be tricky…

  • @mediwise2474
    @mediwise2474 8 месяцев назад

    Please hwlp me sir
    I have a graph of vibration damping of material in frequency vs amplitude
    I want a graph in time domain
    What to do

    • @philparisi_
      @philparisi_  8 месяцев назад

      Checkout MATLAB’s ifft() function!

  • @eschool8812
    @eschool8812 Год назад +1

    Hi, I have a discrete voltage and current signal in time domain, what will be the formula to calculate the power using both voltage and current waveform in FFT method, it will be sum of the Individual powers in frequency domain or if you can put some insights or share your mail I can send you a email stating the exact problem. Thanks for the video.

    • @philparisi_
      @philparisi_  Год назад

      Hey there, it’s been a minute since I’ve done power spectrum analysis. Check out the fft() documentation and tutorials, they may have an example calculating power. Also Steve Brunson might have what you’re looking for! Good luck out there.

  • @lucutes2936
    @lucutes2936 3 месяца назад +1

    thx

  • @mxdnxss4390
    @mxdnxss4390 Год назад +1

    Great video

  • @sadullahesmer5153
    @sadullahesmer5153 10 месяцев назад +1

    Thank you

  • @eefunhuang6958
    @eefunhuang6958 Год назад +2

    I think sampling frequency is 1/dt

    • @jobaua
      @jobaua Год назад

      Same

    • @philparisi_
      @philparisi_  Год назад

      Haven’t look deep into this, but yes in general you are correct. I think the data set I used had a set sampling rate which is why I used what I did

  • @yehiamoustafa9801
    @yehiamoustafa9801 2 года назад +1

    Thank you very much

    • @philparisi_
      @philparisi_  2 года назад

      You are very welcome Yehia! Be sure to check out the most recent code - link in the description!

    • @yehiamoustafa9801
      @yehiamoustafa9801 2 года назад +1

      @@philparisi_ Hi Phil, i just want to ask. Why is the Plot of the Amplitude Symmetric. Is it about the Fourier Series ? Or it depends on the raw data ? I mean if i try another raw data, it will not be Symmetric ?

    • @philparisi_
      @philparisi_  2 года назад

      Hi Yehia, if you look at comments between me and MED, this will help answer your question.
      What I’ve shown in this video is the ‘raw’ amplitude and phase spectrum. However, another common way to view it is by ‘folding over’ the range of frequencies, in which case it wouldnt be symmetric.
      To explicitly answer your question, yes. For any data you use my code on, it will give a symmetric output (and this is the case in general for Fourier Transforms). It’s simply a preference for viewing the ouput of FFT.

    • @yehiamoustafa9801
      @yehiamoustafa9801 2 года назад

      @@philparisi_ Thank you very much for your answer

  • @kairiannah
    @kairiannah 2 года назад +1

    fantastic

    • @philparisi_
      @philparisi_  2 года назад

      Thank you Kairiannah! Please look at the updated code as well github.com/PhilParisi/YouCode/blob/main/fourier_transform.m

  • @mohammedalharbi1034
    @mohammedalharbi1034 2 года назад

    It is one of the best videos, I've ever seen 😍 ... can you support to add sine waves summation for dominant frequency/amplitude/phase using sine wave equation ( amp × sine*2pi*f*dt+angel ) instead of using IFFT function of X_recon_dom(i)... please help, appreciated

    • @philparisi_
      @philparisi_  2 года назад

      Hi Mohammed, it seems like you know enough to do this yourself! Just stop the code right before the X_recom_dom() stuff and do the reconstruction / summation you desire! I believe in you :)

    • @mohammedalharbi1034
      @mohammedalharbi1034 2 года назад

      @@philparisi_ thanks Phil for kind words ... I tried to make it in "For loop function to do sine_waves summations for dominant frequencies but I failed :( ... I need your support, please 🙏

  • @alimozaffar6884
    @alimozaffar6884 Год назад

    thanks a lot

  • @KwabenaAsiedu
    @KwabenaAsiedu Год назад +1

    Thank you so much Sir. would you mind if i can get your email address and email you regarding a signal problem please.

    • @philparisi_
      @philparisi_  Год назад

      Hi Kwabena, you can send queries to philsbeginnercode@gmail.com!