Using matlabs fft function 2 - zero padding and windowing

Поділитися
Вставка
  • Опубліковано 5 вер 2024

КОМЕНТАРІ • 74

  • @rameshnagaraju9204
    @rameshnagaraju9204 10 років тому +7

    Best dsp videos I have watched ..thanks for such wonderful lecture. Looking forward to learning more.

    • @ddorran
      @ddorran  10 років тому +8

      Thanks for that. Nice to know people are getting benefit from them.

  • @markcardeno8290
    @markcardeno8290 9 років тому +3

    I don't usually post comments, but this video is excellent. Keep up the good work.

  • @MatiasVico
    @MatiasVico 11 років тому +3

    Best explanation I have ever found! Thank you so much!

  • @andreregis13
    @andreregis13 10 років тому

    Professor, working on your example x = 0.5*cos(2*pi*f1*t+0.2)+0.85*cos(2*pi*f2*t+1.8) using zero-padding (L = 99000) and windowing (hanning (length(x)) the results were showed in your youtube class. (I fixed the amplitude values as you told me before: COR = max(abs(fftshift(fft(hanning(256),10000)/256))).
    First main lobe: X_mag(251)=0.4987; X_phase(251)=0.2002; f1=250*fs/length(x_zeropadding) = 2.5;
    Second main lobe: X_mag(1226)=0.8476; X_phase(1226)=1.7998; f1=1225*fs/length(x_zeropadding) = 12.25;
    However, If I put a DC signal (still using zero padding(L=99000) and windowing) the answer of phase in first main lobe is not accurate anymore.
    x = 1+0.5*cos(2*pi*f1*t+0.2)+0.85*cos(2*pi*f2*t+1.8)
    First main lobe: X_mag(251)=0.5101; X_phase(251)=0.2901 (45% bigger than 0.2); f1=250*fs/length(x_zeropadding) = 2.5;
    Second main lobe: X_mag(1226)=0.8478; X_phase(1226)=1.8000; f1=1225*fs/length(x_zeropadding) = 12.25;
    How can I deal with it? Why the phase is shifted? Thanks a lot!

    • @ddorran
      @ddorran  10 років тому +1

      The change in phase is due to "intererence" of the DC component. This interence can be significant if components are close together like the 2.5Hz and 0Hz (DC) components. Windowing can reduce these effects but doesn't remove them entirely.

    • @andreregis13
      @andreregis13 10 років тому

      David Dorran
      Professor Dorran, when I put a DC signal, a maximum value (last one in table) arises out off of points of interest like this:
      Amplitude
      Frequency
      Phase
      Bin
      1
      0
      0
      0
      0.5
      2.5
      0.2
      250
      0.85
      12.25
      1.8
      1225
      1.9989
      0.01
      -0.0315
      1
      I sweep the signal at looking for points (amplitudes) of interest (in this example: 1, 0.5, 0.85), but now I have 1.9989, and the result will be wrong. Is better take off DC before computing fft (with zero padding and windowing)? May I use x - mean(x) (It works?) to take it off ? Thank you very much.

    • @ddorran
      @ddorran  10 років тому +1

      André Luiz Regis Monteiro Removing the DC component will help. x - mean(x) is a perfectly good way of achieving this

    • @andreregis13
      @andreregis13 10 років тому

      David Dorran Thank you professor for your reply. Regards.

  • @peerpraia672
    @peerpraia672 8 років тому

    Thank you so much! Been looking for this for a while. Finally I understood, how to implement the window-function.

  • @sujitbanerjee65
    @sujitbanerjee65 10 років тому

    Very useful and clear explanation.

  • @kyang1305
    @kyang1305 4 роки тому +1

    This is really helpful! Thank you!

  • @upant11
    @upant11 4 роки тому +1

    thanks .....keep doing the good work!!

  • @shekharsrivastava5535
    @shekharsrivastava5535 9 років тому

    Its a very helpful video for me, sir. Thank u v much. If u can provide this example for the same problem using kaiser window to keep side lobes and remove main lobe, i will be highly obliged.

  • @andreregis13
    @andreregis13 10 років тому +1

    Another question. You calculate abs(X1(position)) /(length(x1 not X1, right?)/4), because of windowing process. If I use another kind of window, I need to use the same denominator [ length(x1)/4]? How number 4 was chosen? Thanks a lot!!

  • @alonealonesupervisor537
    @alonealonesupervisor537 8 років тому

    why don't you explain Laplace Transform
    i really don't know what to say ; you are really amazing dr david
    why don't you explain Laplace Transform cause i'm looking to understand it deeply as i have got with you in each lecture you made
    thanks in advanced

  • @thucpham4598
    @thucpham4598 7 місяців тому

    nice, thank you so much!

  • @mdesm2005
    @mdesm2005 10 років тому

    Great video ( it's not too 'long' ... some of us can't get enough...)

  • @RichardSmart
    @RichardSmart 11 років тому

    This is EXACTLY what I was looking for - thanks! I'm using R (and R Studio) rather than MATLAB but I am considering changing as I'm very new to R too. I'd be interested to know if you have any knowledge/advice/observations/comments as to the relative merits of each tool?

  • @milkiastareke4289
    @milkiastareke4289 3 роки тому

    it was really helpful, thanks!

  • @YunikMaharjan
    @YunikMaharjan 5 років тому

    this was a huge help thanks

  • @lazarocouso9310
    @lazarocouso9310 5 років тому

    How does the width of these side lobes compare to the main lobe?

    • @lazarocouso9310
      @lazarocouso9310 5 років тому

      I realized that you just answered it in the video! What a geat video! Thanks

  • @sergioaraujo3103
    @sergioaraujo3103 7 років тому +1

    T H A N K Y O U! You save my day!

  • @tengoliver
    @tengoliver 10 років тому

    Thanks for your video which is well made. A quick question, it shows some components at high bins, frequencies if we say in freq domain. Can you explain that? Thanks

    • @ddorran
      @ddorran  10 років тому

      Where abouts in the video are you referring to?

  • @qalk100
    @qalk100 10 років тому

    first thanks a lot for the videos, they are really amazing, I just got one question thought, when you determine the amplitude for the wave in frequency domain, you tell that its the amplitude in time domain multiplied by the number of samples divided by two, can i ask where did you get that two from? thanks in advance.

    • @ddorran
      @ddorran  10 років тому

      The 2 is there because the spikes I associate with sinusoids are more correctly associated with two complex exponentials (the sum of the two complex exponentials produce a sinusoidal component) see ua-cam.com/video/M1bLPZdNCRA/v-deo.html and ua-cam.com/video/K_C7htSXORY/v-deo.html

  • @sam-zy2dn
    @sam-zy2dn 5 років тому

    Thank you David for your amazing guides. For Flat top window how could I find the scale factor (for hanning window it is N/2/2)? For Flat top window is N/2? In general how did you get N/4 for hanning window to scale ?Thanks

    • @ddorran
      @ddorran  5 років тому +1

      Hi Sam. You can see the magnitude spectrum associated with the window function using the following code (a hamming window in this example). You can find the peak of the magnitude spectrum and divide by 2 to get the scale factor.
      win_len = 100; plot(abs(fft(hamming(win_len),win_len*10))/win_len);

    • @sam-zy2dn
      @sam-zy2dn 5 років тому

      @@ddorran Thanks David!

    • @sam-zy2dn
      @sam-zy2dn 5 років тому

      Dear David, One more question popped up into my mind from your video. If we have many sin waves ( assume 1000) then even though we use windowing, the side lopes interfere with each other. In such scenario what is the best way to have a correct estimation of the amplitude of each sinusoidal components? however, I think it is not necessarily by increasing sinusoidal components the noise from side bands increases as the side bands could interfere in complex plane and could cancel each other our the same as they could be constructive.

    • @ddorran
      @ddorran  4 роки тому

      @UCJqXm40VS_zuhI4cTthkVLA divide the peak by N*max(abs(fft(hamming(win_len),win_len*10))/win_len)/2

  • @theambient2951
    @theambient2951 8 років тому

    Hello David, thanks for this video it's really very helpful. I have a question pls, can zero padding and windowing be applied to a noisy signal without filtering out the noise first? Thanks in advance

    • @ddorran
      @ddorran  8 років тому

      +Segun Ilori Yes they can. Why did you think they couldn't be? I have a feeling there's something more to your question.

  • @fathallaeldali8491
    @fathallaeldali8491 10 років тому

    useful video, what are the parameters that affect choosing the window ?
    how can we judge this is going to be a good window or not ?

    • @ddorran
      @ddorran  10 років тому +1

      The choice of window mainly has two considerations 1) side lobe attenuation 2) main lobe width. A wider main lobe generally means greater side lobe attenuation but you'll need a longer time-domain window to separate individual components.
      Check out DFT windowing for more on windowing
      and DFT in Practice - Frequency Resolution Issues for a discussion on choice of window length

  • @akmmonsurulalam9091
    @akmmonsurulalam9091 4 роки тому

    All the cases you’ve used abs value. If you deal with real value windowing doesn’t work. Why??

  • @andreregis13
    @andreregis13 9 років тому

    Professor, working on your example x = 0.5cos(2pi.f1.t+0.2), I choose f1 = 2.73 (not friendly) keeping zero-padding with 11000. In this case I got abs(X1(34))=0.4977 and angle(X1(34)) = 0.1392 (differente from 0.2 I was expected). So, I put more zeros in zero-padding (99000). then I got : abs(X1(274))=0.4978 and angle(X1(274)) = 0.2019 as expected. How can I explaing this kind of issue? Thank you.

    • @ddorran
      @ddorran  9 років тому

      see How DFT zero padding works

  • @kevinnugent8309
    @kevinnugent8309 5 років тому

    So why the length of signal to analyze is 1.5sec - 1/fs and not just 1.5sec ? Same question wrt previous Part1 video .

    • @ddorran
      @ddorran  5 років тому

      It's to ensure that you have the samples associated with an integer number of cycles of a sinusoid (when the frequency of the sinusoid is also an integer number of cycles per second). If you didn't subtract the 1/fs value from the duration you would have one additional sample, which would introduce a phenomenon known as spectral leakage in the frequency domain.

  • @andreregis13
    @andreregis13 10 років тому

    It is a very nice video, professor. But I have some doubts yet. Without window and zero- padding, the amplitude in frequency returned 250. After windowing and zero-padding returned 125. If I need working using this value to multiply another function, for example, what is the correct value to use? How can I analyze this situation? Thanks.

    • @ddorran
      @ddorran  10 років тому

      check out DFT windowing Explanation and Demo for an explanation of how windowing works.

    • @andreregis13
      @andreregis13 10 років тому

      David Dorran Thanks. I will try to understand.

  • @lazarocouso9310
    @lazarocouso9310 5 років тому

    How can you calculate the exact amount of zeros to be added in order to obtain an exact value for the frequency of our input signal?

  • @pictressli3750
    @pictressli3750 10 років тому

    Thanks a lot to ur video! May I ask if the window is not symmetry? How can I achieve it?

    • @ddorran
      @ddorran  10 років тому +1

      Do you need code to make a window symmetrical?

  • @alessandroaimone416
    @alessandroaimone416 10 років тому

    Thank you for the very nice video.
    Something you could maybe help me with: If I have to use windowing and zero padding when moving to frequency domain, if some elaborations of the spectrum are required and a transformation back in time is applied, the obtained signal will be also padded and windowed. Now, depending on the transformation done on the spectrum, dividing for the hanning window will not recover the same signal that would have been obtained without the window. Is there a way to overcome this issue? Thank you!

    • @ddorran
      @ddorran  10 років тому

      The problem you are encountering is common. In a lot of situations you are analysing signals on a frame by frame basis and you need to recombine the frames after processing. If you use the process of dividing by the hamming window you will get a lot of distortion at the edges of the frames (as I think you are seeing). The way around this problem is to first of all use overlapping frames (50% or 75% is common), then modify your frame in the frequency domain, then inverse back into the time-domain, then window again to smooth out distortions at the frame boundary (after removing zero padding). If you use a hann window function using either 50% or 75% overlap you will recover a scaled version of the original in the event of no modifications- so you will need to rescale to get back to the original. See eleceng.dit.ie/arg/main.php?page=Code for an example in which an audio signal is time scaled using a STFT.

    • @alessandroaimone416
      @alessandroaimone416 10 років тому

      David Dorran
      I thank you very much!

  • @claypipkin
    @claypipkin 9 років тому

    Can you provide a link to the code in this video? Thanks!

  • @ananyatrivedi2791
    @ananyatrivedi2791 6 років тому

    Hello,
    In a time domain signal with a lot of hidden frequency components, how can i separate out individual frequencies in the form of an array from their peaks? Any suggestions?

    • @ddorran
      @ddorran  6 років тому

      apply an fft of an appropriate window length (see the video on frequency resolution - DFT in Practice - Frequency Resolution Issues
      ) and then use the findpeaks function if you're using matlab.

  • @jeroenreurink2589
    @jeroenreurink2589 7 років тому +4

    I love you.

  • @babaraziz5048
    @babaraziz5048 11 років тому

    excellent

  • @Axceed1
    @Axceed1 9 років тому

    Hello, can you point to me the video if any where you discuss the relationship between magnitude in time domain and frequency domain? I am very much interested,
    thanks

    • @ddorran
      @ddorran  9 років тому

      Axceed1 ua-cam.com/video/dM1y6ZfQkDU/v-deo.html might help

  • @themanthis837
    @themanthis837 8 років тому

    so how do you cout out freqencies or say double them?

    • @ddorran
      @ddorran  8 років тому +1

      +The Manthis You can just multiply certain bins by 2 (or zero to remove/cut out)

  • @shenglifan6487
    @shenglifan6487 9 років тому

    good video.

  • @allynl25
    @allynl25 5 років тому +1

    I love you

  • @louzanne6377
    @louzanne6377 3 роки тому

    completely unrelated but this guy sounds like Moriarty from the BBC Sherlock series

  • @ayadsobhan6195
    @ayadsobhan6195 3 роки тому

    Sir pleass i need heelp me

  • @andreregis13
    @andreregis13 10 років тому

    Another question. You calculate abs(X1(position)) /(length(x1 not X1, right?)/4), because of windowing process. If I use another kind of window, I need to use the same denominator [ length(x1)/4]? How number 4 was chosen? Thanks a lot!!

    • @ddorran
      @ddorran  10 років тому +1

      If no window function is explicitly used you multiply by 2 (because the magnitude corresponds to that of one of two complex exponentials rather than a single sinusoid (see negative frequencies in the frequency domain) - if you don't appreciate this don't be too concerned).
      If a window function is used then the magnitude of sinusoidal components in the frequency domain are also altered so you need to take account of this. Essentially what happens is that the magnitude spectrum of each sinusoidal component is multiplied by the magnitude spectrum of the window function used (see DFT windowing Explanation and Demo ). So if you were to look at the magnitude spectrum of the window function you'd see how much the magnitude of the sinusoidal component was modified by the window function in the frequency domain.
      As an example if you were to plot the magnitude spectrum of the hamming window plot(abs(fftshift(fft(hanning(256),10000)/256))) you will see that the maximum is about 0.5. Therefore each sinusoidal component will be reduced by a factor of 2 in the magnitude spectrum if a hanning window is applied. So each sinusoidal component needs to be multiplied by 2 to take into account the fact that it has been reduced by 2 by the window function and it further needs to multiplied by 2 to take into account the complex exponential business, giving a total of 4.
      The value of 4 for a hamming window is approximate. The value of 2/max(abs(fft(hanning(256))/256)) is closer to the exact.
      Different window functions require different scaling factors because they have different magnitude spectrums. The Blackman window has a max of 0.4184 plot(abs(fftshift(fft(blackman(256),10000)/256))). You'd therefore need to multiply by 4.78 rather than 4.

    • @andreregis13
      @andreregis13 10 років тому

      David Dorran Thank you very much, professor. I will watch your videos again to understand a little bit more.