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!
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.
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.
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.
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!!
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
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?
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
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.
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
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
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);
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.
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
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
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.
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.
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.
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!
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.
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?
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.
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
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!!
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.
Best dsp videos I have watched ..thanks for such wonderful lecture. Looking forward to learning more.
Thanks for that. Nice to know people are getting benefit from them.
I don't usually post comments, but this video is excellent. Keep up the good work.
Best explanation I have ever found! Thank you so much!
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!
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.
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.
André Luiz Regis Monteiro Removing the DC component will help. x - mean(x) is a perfectly good way of achieving this
David Dorran Thank you professor for your reply. Regards.
Thank you so much! Been looking for this for a while. Finally I understood, how to implement the window-function.
Very useful and clear explanation.
This is really helpful! Thank you!
thanks .....keep doing the good work!!
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.
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!!
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
nice, thank you so much!
Great video ( it's not too 'long' ... some of us can't get enough...)
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?
it was really helpful, thanks!
this was a huge help thanks
How does the width of these side lobes compare to the main lobe?
I realized that you just answered it in the video! What a geat video! Thanks
T H A N K Y O U! You save my day!
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
Where abouts in the video are you referring to?
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.
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
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
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);
@@ddorran Thanks David!
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.
@UCJqXm40VS_zuhI4cTthkVLA divide the peak by N*max(abs(fft(hamming(win_len),win_len*10))/win_len)/2
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
+Segun Ilori Yes they can. Why did you think they couldn't be? I have a feeling there's something more to your question.
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 ?
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
All the cases you’ve used abs value. If you deal with real value windowing doesn’t work. Why??
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.
see How DFT zero padding works
So why the length of signal to analyze is 1.5sec - 1/fs and not just 1.5sec ? Same question wrt previous Part1 video .
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.
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.
check out DFT windowing Explanation and Demo for an explanation of how windowing works.
David Dorran Thanks. I will try to understand.
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?
What is the formula?
Thanks a lot to ur video! May I ask if the window is not symmetry? How can I achieve it?
Do you need code to make a window symmetrical?
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!
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.
David Dorran
I thank you very much!
Can you provide a link to the code in this video? Thanks!
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?
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.
I love you.
Beetje gay is oke
Bas ten Brinke is pas echt gay
Dat is wel echt waar, hij wil graag vlees in zijn lichaam
Mannenvlees
En lauwwarm genormaliseerd zaad in zijn bek
excellent
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
Axceed1 ua-cam.com/video/dM1y6ZfQkDU/v-deo.html might help
so how do you cout out freqencies or say double them?
+The Manthis You can just multiply certain bins by 2 (or zero to remove/cut out)
good video.
I love you
hahaha .... nice comment!
completely unrelated but this guy sounds like Moriarty from the BBC Sherlock series
Sir pleass i need heelp me
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!!
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.
David Dorran Thank you very much, professor. I will watch your videos again to understand a little bit more.