DFT windowing Explanation and Demo
Вставка
- Опубліковано 14 жов 2024
- Shows why applying a window function, such as hamming, prior to DFT analysis results in a reduction in sidelobes in the magnitude spectrum. See dadorran.wordpr... for matlab code
Documentation on the DFT is available at dx.doi.org/10.1...
Other notes available at at pzdsp.com/docs.
Great video sir, I just have difficulty understanding why the spectrum of the rectangular window looks the way it does. Does it mean that it has frequency components at all values whose magnitude slowly decreases as the frequency increases? And why is this is the case?
Thanks again.
Thanks for wonderful explanation on windowing function, it was really helpful, how can we cite the results of the MATLAB code in any academic report or journal papers.
Professor Dorran, I am sorry for boring you again, but I'm having some troubles. I'm working with two signals (S1 and S2) acquired from osciloscope, S1 is real vector and S2 become a complex vector after divided a complex number that I need to work with. Both are 1000 samples. I need to compute fft from S1 and S2 separately and after , multiply the correspondents results with correspondent angles, to get only one vector. Add all elements to get only one result (number). The result I expected was around 27-32. When I computed without zero padding and without windowing the result was 29.72. However when I put zero padding and windowing the result was 332.3, very very different. I compared the results from S1 into two ways (with and without zero padding and windowing) and they are little bit different, but the S2 is very different using zero padding and windowing. The structure I used to compute S1 and S2 with zero padding and windowing is exactly the same. So I don't know where I am wrong. Could you give some tips? Thanks a lot!!
Great Video.
Although could you tell me a way how I could apply a hamming window of a smaller length to an audio signal of a longer length?
what is the difference between zero padding and windowing ? at the beginning of the video ( 2nd half of 2nd min) you zero-padded and later you used windowing . the magnitude of spectrum differs in both cases though padding can be understood as windowing .
secondly ; what is the need for windowing initially ? why we do not just take the spike fashioned mag response only ?
let us differentiate them . say that padding enhances spectrum .
then windowing reduces side lobs of the padded signal that were created because of the padding . .
questions : 1/ padding increases freq of signal which distorts the signal . so is it an innocent process ?
2/ by someway .. padding can be equated to windowing .
Aewsome Vídeo! Thanks!
Thank you very much for the video.
can u explain by your own word david.. in your opinion. why is the dft windowing is preferable compared to hanning, hamming window.. ? i am familiar with hamming and hanning. and when came across the dft windowing. i seriously would like to know why do u chose dft over the hanning and hamming? thanx!
hanning and hamming windows are types of window that can be used during a DFT analysis - when I talk about DFT windowing I am using a window function like hanning or hamming. Each window window function has different properties (like main lobe width and side lobe attenuation).
Hello sir.Your videos are very interesting.I have few doubts.Suppose if i want to know the frequency of the signal,can i take the dft via fft and use max function to find the max peak(fundamental freq) and conclude tht the location(freq)where the max freq occurs is the freq of the signal(without windowing and zero padding).Also in of your videos you mentioned tht fft cant be implemented for small no of samples ..then how do we find the freq of those samples?
In answer to your first question yes but the accuracy of your frequency estimate will be limited to fs/N.
The DFT can be implemented on any number of samples but the frequency resolution will be very poor. The fft (an efficient implementation of the DFT) works on data that is 2^k samples in length, where k is an integer. Matlabs fft function will work on a signal of any length.
David Dorran Thank you for your reply sir.So i would have to increase the no of samples(by zero padding) to increase the frequency resolution ?Or is there any other technique to improve frequency resolution?(since i want to estimate the frequency range as accurately as possible) If so can you please attach the link which explains the same?
Jyothi Jain There is a method called parabolic interpolation (Search PARSHL by Julius Smith). Also you could determine a frequency estimate by analysing the phase change over successive frames (see improved phase vocoder by Jean Laroche). I'd imagine that both of these approaches would be computationally more efficient - I haven't really considered the accuracy of them before so can't really comment - I'm pretty sure Smith talked about the limitation in his paper.
Thank you so much sir :)
Thanks for the video
Hi ,
could you tell me what are the main steps if :
A signalx(t) after a perfect anti-aliasing filter is sampled at 2 kHz to become a discrete- time sequence x[n] . A 16 -point DFT is performed on x[n]; 0
A single non-zero bin/sample at k=3 implies x(t) is a complex exponential (Ae^(-jwt+phi)) which has amplitude A=5/16, phase phi=pi/6 and a frequency associated with 3 cycles over 16 samples i.e. 3 cycles over 16(1/2000) seconds . NOTE that DFT bins are sometimes scaled by 1/N in some algorithms in which case the amplitude would be 5.
David Dorran
Thank you
I was asking about the procedure, I assume that the steps to convert a DFT of sampled signal to x(t) is to apply IDFT first to get x[n], then convert it back to x(t) (the method?) right? . I want to approve that mathematically
Professor, I am working with the script bellow (showing only S1(real) part, S2(complex) is similar) with windowing and zero padding.
Question:
1 - Why changing 'L' (length of zero padding) the answer changes too? Is the problem in the phase or magnitude?
2 - How can I get a solution to trust in answer?
Could you please, help me? Thank you very much for your time.
Fs = 100MHz;
% frequency sample
Tw = 9.99E-6
% time window
L = 99000
% for zero padding
N = length(s1)
% 1000 samples
win = hanning(N);
COR = max(abs(fftshift(fft(hanning(256),10000)/256)))
% correction value (for window)
S1_zpad_win = s1.*win;
%windowing
S1_zpad_win = [s1_zpad_win' zeros(1, L)];
%zero padding
S1_ZPAD_WIN = fft(s1_zpad_win);
S1_ZPAD_WIN = S1_ZPAD_WIN(1:length(S1_ZPAD_WIN)/2+1);
S1_ZPAD_WIN = 1/N.*S1_ZPAD_WIN;
S1_ZPAD_WIN = S1_ZPAD_WIN/COR;
% amplitude DC correct
S1_ZPAD_WIN(2:end-1) = 2*S1_ZPAD_WIN(2:end-1);
% all amplitudes fixed less DC (upper line)
freq = 0:Fs/(2*length(S1_ZPAD_WIN)):Fs/2 - Fs/(2*length(S1_ZPAD_WIN));
% frequency associated
angles1=angle(S1_ZPAD_WIN);
%phase
S_intermediate=S1.*S2.*cos(angle1-angle2);
% intermediate vector for solution
S_final = sum(S_intermediate)
% Solution
When I change 'L' (length of zero padding) the result changes too. For example:
S_final
'L' (zero padding)
windowing
2.9743
No
No
29.7206
10000
No
148.6045
50000
No
297.2092
100000
No
6.64
1000
Hanning
36.5479
10000
Hanning
169.4489
50000
Hanning
335.5753
100000
Hanning
Please note that if you are dealing with complex signals the left hand side of the DFT is not a conjugate pair of the right hand side (positive frequencies aren't a complex conjugate of corresponding negative frequencies).
I suggest that you try out your code with synthesised signals. First try with real sinusoids and see if you are getting expected results. If that works then move on to complex signals.
David Dorran Thank you professor. I will do this. After I'll tell you.
David Dorran
Professor Dorran, I made a fake signal with these functions(as you suggested before):
F1=760; F2=360; F3=180; F4=90;
tt=1; Fs = 10000; Ts=1/Fs; N=tt/Ts;
t = 0:(1/Fs):(tt-1/Fs);
s1 = 1+10*cos(2*pi*F1*t)+4*cos(2*pi*F2*t)+2*cos(2*pi*F3*t);
s2 = 2+10*cos(2*pi*F1*t+(2*pi/360)*60)+4*cos(2*pi*F2*t+(2*pi/360)*90)+2*cos(2*pi*F4*t);
Computing by hand the result is: S = 27 (Mathematically right).
Applying the code developed in MATLAB, with 10000 points (original vector above, without zero padding and without windowing) the result is exactly the same. On the other hand, when zero padding is added (without windowing) the result 'S' becomes the multiple by the length after zero padding, like this: n =length(s1+zeropadding)/ length(s1) . So, if I use zero padding = 10000, n=2 and S = 54, for n=3, S=81. I understood that zero padding couldn't affect the signal , it needs to be used only for better fit the basic function of fft to original signal (and windowing for decreasing spread leakage in the ends). If I use the factor 'n' in S , I am forcing the result. But if I use 'n' factor to fix the problem and apply windowing, the problems start again(not as a multiple factor).
Could you help me with some idea? Thank you a lot!! Regards.
David Dorran
Hi Professor, I solved the problem with real numbers (input signal). The program is working now. Now I need to apply the program using a complex vector as input signal. Youo told before: "Please note that if you are dealing with complex signals the left hand side of the DFT is not a conjugate pair of the right hand side (positive frequencies aren't a complex conjugate of corresponding negative frequencies)." If I understood you are telling that if I get (a+jb) in positive frequencies , I get (-a-jb) in negative frequencies. So I can´t work with only half of frequencies as we make with real input signals. So , how can I work with? Could you please give me some advice or indicate a specific book to study this issue? Thanks a lot.
Once you understand the terms complex exponentials and negative frequencies then you won't have any major problem working with complex data. One book you could try out is 'Understanding Digital Signal Processing' by Richard Lyons. It goes into more detail that www.dspguide.com which is where I normally point anyone starting out with DSP.