Hi Could anyone explain the Hamming window in REALLY simple terms and why it is useful and how it could be implemented in MATLAB?? I would be grateful for any response.

# Hamming window

Started by ●February 19, 2006

Posted by ●February 19, 2006

"rajgerman"wrote in message news:Ju6dnZUigbhAfmXenZ2dneKdnZydnZ2d@giganews.com... > Hi > > Could anyone explain the Hamming window in REALLY simple terms and why it > is useful and how it could be implemented in MATLAB?? > > I would be grateful for any response. >http://www.math.psu.edu/local_doc/matlab/toolbox/signal/hamming.html#1557 Best of luck - Mike

Posted by ●February 19, 2006

rajgerman wrote:> Hi > > Could anyone explain the Hamming window in REALLY simple terms and why it > is useful and how it could be implemented in MATLAB?? > > I would be grateful for any response.If you have the Signal Processing Toolbox, a Hamming window of length N can be obtained from Matlab as follows: w=hamming(N) Window functions like Hamming are typically applied as a point by point multiplication to the input of an FFT to control the level of adjacent spectral artifacts that appear in the magnitude of the FFT results for the case when the input frequencies do not correspond exactly with bin centers. These artifacts are referred to as leakage. Another common use for window functions is in the design of FIR filters using the window method. In this case a sinx/x lowpass function is multiplied point by point by a window to alter the frequency response of the filter. Google returns loads of useful information about window functions. Any introductory DSP book will discuss them as well. John

Posted by ●February 19, 2006

Thanks for that information but I'm still a little confused. The thing is I have a brain signal which is an audio file which I have fast fourier transformed. Now what I have to do is apply the Hamming window to that. How would I do that using MATLAB?? It seems confusing.

Posted by ●February 19, 2006

Hi, You can think of windowing in general as a convolution in frequency domain (you are multiplying both functions in the time domain). The result of this convolution on frequency domain is that samples outside one frequency affect the amplitude value at that frequency ! Ideally you would want your window to be an impulse in frequency domain, but note that you window would require infinite points in time.Thinking in frequency domain: So the goal of windowing can be thought as two fold, where we are trying to approximate the impulse in frequency domain with finite points: 1)Make the pass region of the window as narrow as possible. 2)Attenuate the other regions as much as possible The Hanning window does #2 pretty good, and you can get #1 to desired amount by increasing sample size. The rectangular window (which is the window you actually use if you don't multiply your data signal at all) is the best one on #1 (has the narrowest pas region), but is the worst on #2 ( largest amount of leakage). Check the posts above for implementation + additional info. Let me know if this is not clear. -Ikaro

Posted by ●February 19, 2006

rajgerman wrote:> Thanks for that information but I'm still a little confused. > > The thing is I have a brain signal which is an audio file which I have > fast fourier transformed.Why on earth? Are you sure there isn't something you misunderstood? Now what I have to do is apply the Hamming> window to that. How would I do that using MATLAB?? It seems confusing.Jerry -- Engineering is the art of making what you want from things you can get. �����������������������������������������������������������������������

Posted by ●February 19, 2006

"rajgerman"wrote in message news:qdidnQ5Hzq7-bWXe4p2dnA@giganews.com... > Thanks for that information but I'm still a little confused. > > The thing is I have a brain signal which is an audio file which I have > fast fourier transformed. Now what I have to do is apply the Hamming > window to that. How would I do that using MATLAB?? It seems confusing. >It's not likely that you want to window the FFTd sequence - as in multiply the FFTd sequence. It's much more likely that you want(ed) to window the temporal sequence (as in multiply) before the FFT. Or you could convolve in frequency to get the same affect. You have a few choices: 1) Generate the temporal window function. Someone has suggested how to do this in MATLAB. The window should be the same length as the temporal record you have unless you're processing in blocks. Then, either: Using the temporal record, multiply point by point by the window function in time. Then FFT if you need to. Using the FFT record that you have, IFFT it and proceed as above. FFT both the temporal data sequence and the temporal window. Convolve the two in frequency. Fred

Posted by ●February 19, 2006

rajgerman wrote:> Hi > > Could anyone explain the Hamming window in REALLY simple terms and why it > is useful and how it could be implemented in MATLAB?? > > I would be grateful for any response. > >Radjerman, Assume we have a set of time-domain samples, that have been taken from a signal waveform (if we are going to perform a FFT) or have been calculated from a desired impulse-response function )if we are going to implement a FIR filter.) When we selected the set of time-domain samples the selection process was in effect a 'chopping up' process that introduced high-frequency components that were not present originally in the continuously-sampled signal or in the unlimited impulse-response. These introduced components show up as high-frequency peaks in the FFT or as high-frequency peaks in the response of the FIR filter, both effects are generally undesirable. We can reduce the amplitude of these high-frequency components by 'tapering off' the amplitudes of the samples towards each end of the set in some systematic way, and the Hamming window is one of many similar functions that will do this job for us. If you look at the expression for a Hamming window you will see that if we multiply a set of signal samples by this function, the sample(s) at the centre of the set gets multiplied (or 'windowed')by the largest factor and this factor decreases in a smooth sinusoidal fashion as we go away from the centre, with the samples at each end being multiplied by zero. The end result is that instead of an abruptly 'chopped' set of samples we now have a set of samples that has been heavily modulated by one cycle of a sinusoidal function. The artifacts produced by this modulation are less objectionable for many applications. In the FFT the artifacts show up as spectral 'leakage' into adjacent frequency bins. In a FIR filter the pass-band response is altered sightly. In MATLAB, generate a set of values using the expression for the Hamming window function. Then generate the dot product between the set of Hamming window values and the set of signal samples. Regards, John

Posted by ●February 19, 2006

> > It's not likely that you want to window the FFTd sequence - as in multiply > the FFTd sequence. > It's much more likely that you want(ed) to window the temporal sequence > (as in multiply) before the FFT. > Or you could convolve in frequency to get the same affect. > > FFT both the temporal data sequence and the temporal window. > Convolve the two in frequency. >Hello Fred, Since the Hamming window is defined in terms of cosines, the Freq domain version turns out to have only 3 non-zero coefs. This makes for a pretty easy convolution. The coefs are -0.23, 0.54, -0.23 Clay

Posted by ●February 20, 2006

So are you saying that I do not need to fast fourier transform the audio signal, but apply the hamminng window first and the nfast fourier transform?? Sorry guys but I'm not to familiar with these topics but thanks for your help. If any of you would provide me their email address I could send you the files to show you what I mean.

Posted by ●March 28, 2006

Hey This is my modified code. My filtered signal looks like a V shape, where the centre is sloped down. I don't think that looks right, why is that?? figure(1) t = (0:2/(88200-1):2); plot(t,y) title('Brain Signal (2 sec)') xlabel('Time(t)') ylabel('Voltage(v)') Y = y.*hamming(length(y)); figure(2) plot(t,Y) title('Hamming window applied to signal') xlabel('Time(t)') ylabel('Voltage(v)') figure(3) X = fft(Y); plot(X) title('FFTed signal') xlabel('logf') ylabel('log|Y|') Z = X.*conj(X); figure(4) plot(Z) title('Hamming window + Conjugate applied') xlabel('logf') ylabel('log|Y|') figure(5) loglog(Z) title('loglog plot') figure(6) semilogx(Z) title('semilogx plot') figure(7) semilogy(Z) title('semilogy plot') A = fftshift(Z); figure(8) semilogy(A) title('Simplified signal in frequency domain') figure(9) f = (-fs/2:1/2:fs/2-1/2)/1000; semilogy(f,A) title('Simplified signal in frequency domain') xlabel('Frequency (KHz)') figure(10) f2 = (0+1/2:1/2:fs/2)/1000; A_p = A(end/2+1:end); semilogy(f2,A_p) title('Positive side of A') xlabel('Frequency (KHz)') figure(11) f3 = (-fs/2:1/2:0-1/2)/1000; A_n = A(1:end/2); semilogy(f3,A_n) title('Negative side of A') xlabel('Frequency (KHz)') figure(12) V = zeros(1,88200); f = (-44100/2:1/2:44100/2-1/2)/1000; S = 500/0.5; P = 44100-S:44100+S; V(1,P) = 1; plot(f,V) title('Filter') xlabel('Frequency (KHz)') F_filt=A(P); f_filt=f(P); figure(13) semilogy(f_filt,F_filt) title('Filtered data') xlabel('Frequency (KHz)') figure(14) I = ifft(fftshift(F_filt)); plot(t(P),abs(I)) title('Filtered signal in time domain') xlabel('Time(t)')

Posted by ●March 27, 2006

Search amazon.com for ["digital signal processing" matlab] and see the books that pop out. Ingle, Proakis Mitra Stearns all seem to get high marks. I wouldn't be surprised if you can't find some matlab code for dsp on the web. So, there would be examples. matlab is a language so you need to learn the language separately I should think - at least that would be my approach. Then you can use tricks learned from real code. A good book on matlab might be a good idea because the DSP books probably won't help much in learning how to construct things. But, hey, it's an iterative process and we've all used somebody else's code to avoid learning a whole lot of new stuff at once haven't we? Fred

Posted by ●March 27, 2006

rajgerman wrote:> Hey > > Thanks that explained alot. Could you recommend me a good book that deals > with matlab and dsp together or any good dsp book that will help me??I know very little about Matlab, but I do know that it has a good help system. Matlab is a tool for exploring your designs and for solving specific problems (like quickly computing window and filter coefficients, and transforms). It's like a very sophisticated bulldozer-backhoe combination. It's a lot faster than digging by hand, but in needs a plan to be useful. At your level, I can't think of any better book than Lyons: "Understanding Digital Signal Processing". There's an on-line book that's also good: "The Scientist and Engineer's Guide to Digital Signal Processing" by Steven W. Smith; http://dspguide.com/. There is a book that deals with doing DSP using Matlab. I don't know it. Conscious ignorance rarely gets me into deep trouble. Being wrong about what I think I know really hurts. I just bought a lens for $60 that I only thought I could use. Jerry -- Engineering is the art of making what you want from things you can get. �����������������������������������������������������������������������

Posted by ●March 27, 2006

Hey Thanks that explained alot. Could you recommend me a good book that deals with matlab and dsp together or any good dsp book that will help me?? Thanks Raj

Posted by ●March 27, 2006

rajgerman wrote:>>rajgerman wrote: >> >>>Hey >>> >>>Ok instead of X = Y.*hamming(length(Y)); it should be: >>> >>>W = hamming(length(Y)); >>> >>>X = conv(Y,W); >>> >>>Or do I have to fft W as well and then convolve Y and W?? >>> >>>Thanks Raj > > > No Y is in the frequency domain. I'm a bit confused.You start with a sequence of samples, equally spaced in time. To see the spectrum of the signal that the samples represent, you perform an FFT on those samples. Often the FFT will give a clearer picture of the spectrum if you modify the samples with a tapered window /before/ performing the FFT. Now: you can either multiply the window vector by the sample vector and FFT the product as I described -- that's the efficient way -- or FFT the sample array, and convolve the result with the FFTed window, taking care that the convolution isn't circular. The second way works in theory, but there's no reason to use it. Matlab is too automatic to be a good learning tool. It lets one easily do complicated operations without having to understand what they are or what they do. It lets one operate on vast amounts of data with no understanding of what the data mean, either before or after the operations. You will get more out of it after you have done a simple problem by hand. That will make the nature and sequence of the operations clear. Jerry -- Engineering is the art of making what you want from things you can get. �����������������������������������������������������������������������

Posted by ●March 27, 2006

Hey Y = frequency domain (data) W = which is the hamming window is in the time domain Am I right with W?? How will this change my code? Thanks Raj

Posted by ●March 27, 2006

>rajgerman wrote: >> Hey >> >> Ok instead of X = Y.*hamming(length(Y)); it should be: >> >> W = hamming(length(Y)); >> >> X = conv(Y,W); >> >> Or do I have to fft W as well and then convolve Y and W?? >> >> Thanks RajNo Y is in the frequency domain. I'm a bit confused.

Posted by ●March 27, 2006

rajgerman wrote:> Hey > > Ok instead of X = Y.*hamming(length(Y)); it should be: > > W = hamming(length(Y)); > > X = conv(Y,W); > > Or do I have to fft W as well and then convolve Y and W?? > > Thanks RajWe're at cross purposes. Assuming that X and Y are arrays of samples in time, then X = Y.*hamming(length(Y)) is exactly what you want to do. Then FFT X. Your use of capital X and Y lead me to wonder is they really are time samples. If not, they should be. Jerry -- Engineering is the art of making what you want from things you can get. �����������������������������������������������������������������������

Posted by ●March 27, 2006

Hey Ok instead of X = Y.*hamming(length(Y)); it should be: W = hamming(length(Y)); X = conv(Y,W); Or do I have to fft W as well and then convolve Y and W?? Thanks Raj

Posted by ●March 27, 2006

rajgerman wrote:> Hey > > Is it true that a Hamming window should be computed in the time domain and > not in the frequency domain like I have done??That's the way it's usually done. Applying it in the time domain uses multiplication, but in the frequency domain you must convolve. (If you multiply the time domain sequence by the frequency results, you get a hump in the middle without the expected benefits anywhere. Are you familiar with the silly joke about the man with "a knocking in the head and a ringing in the ears"? (On request.) Jerry -- Engineering is the art of making what you want from things you can get. �����������������������������������������������������������������������