DSPRelated.com
Forums

Hamming window

Started by rajgerman February 19, 2006
Hey Fred

I didn't quite understand your explanation. 

I applied fftshift so that it looks more simple. Now my data goes from -fs
to 0 and then from 0 to fs. I know that the negative half is just a mirror
image of the other side. All I need to know is how to represent the x-axis
in frequency terms?? What would be the coding??

Thanks for your help.

"rajgerman" <rajgerman@msn.com> wrote in message 
news:_sWdnTxyGJPA65nZnZ2dnUVZ_tWdnZ2d@giganews.com...
> Hey Fred > > I didn't quite understand your explanation. > > I applied fftshift so that it looks more simple. Now my data goes from -fs > to 0 and then from 0 to fs. I know that the negative half is just a mirror > image of the other side. All I need to know is how to represent the x-axis > in frequency terms?? What would be the coding??
Do you mean you want someone to write the code for you? I'll bet Google would result in a listing for you. Here's how it might go: Make a vector that has the x values according to the frequency sample spacing. Spacing=1/T where T is the length of the signal ... that's what I tried to tell you in my last post. x(i)=(1/T)*(i-1) Is that all you're asking? As far as applying fftshift it's important to understand your objective. I would not do it if I were just doing signal processing. However, if the objective is to make "pretty pictures" then OK. Then you have to modify the x vector from above of course but that's a very simple matter. You may also consider repeating the value at fs/2 at each end so there are N+1 samples in order to make the picture symmetrical around zero. Examples: If there are 100 samples going from zero to fs-1/T and you circularly shift them by N/2 then the zeroeth sample will be at x2=51, the 100th sample will be at x2=50 and the the 51st sample will be at x2=1 and the 50th sample will be at x2=100. This isn't symmetrical. It looks like this: x1(1) == 0 x1(2) == 1/T x1(51) == fs/2 x1(100) == fs-1/T repeats at x1(1) == fs.... Shifting by N/2 = 50: x2(1) == fs/2 x2(51) == 0 x2(100) = fs/2-1/T repeats at x2(1) == fs/2 So, you may wish to add another point just so it's symmetrical: x2(101) == fs/2 and add the corresponding value to the y vector in the plot. It that what you mean? Now, if N is odd, then there won't be a value that corresponds to frequency = fs/2 at all because fs/2 is not an integer multiple of 1/T. For N=101 you will have: x1(1) == 0 x1(2) == 1/T . x1(51) == fs/2 - 1/2T x1(52) == fs/2 + 1/2T . x1(101) == fs - 1/T repeats at x1(1) == fs .... Shifting by fs/2 corresponds to a shift of an odd integer multiple of 1/2T, and causes the samples to align on odd intervals of 1/2T and we need a new definition for x2 so I will define x3 to have 2*N samples = 202 samples. We will get that by adding an extra samples in the x1 vector to get x1' and adding zeros in the y value vector. Then you can shift by 101 samples: Start with x1'(1) == 0 x1'(2) == 1/2T with a zero value in the y values to be plotted x1'(3) == 1/T . x1'(100) == fs/2- 1/2T .. which is an integer multiple of 1/T x1'(101) == fs/2 with a zero value in the y values to be plotted x1'(102) == fs/2 + 1/2T .. which is an integer multiple of 1/T . x1'(201) == fs - 1/T repeats at x1(1) == fs .... x1'(202) == fs - 1/2T which is a sample added to fill in the array with a zero value in the y values to be plotted Now shift to get x3(103) == 0 ... this means a shift of 102: x3(1) == fs/2 with a zero value in the y values to be plotted . x3(103) == 0 . x3(202) = fs/2-1/2T repeats at x3(1) == fs/2 So, you may wish to add another point just so it's symmetrical: x2(203) == fs/2 and add the corresponding zero value to the y vector in the plot. If I didn't make any mistakes then that's it. Fred
Hey 

Thanks for your help Fred.

I was told that I can filter my data much simpler without having to use
FIR filters. Does anyone know how I could do that??

semilogy(f,A), where:

f = -fs/2:1/2:fs/2-1/2;       fs = 44100Hz
A = fftshift(Z);              Z has been ffted.
Length of signal = 2 seconds

I want to be able to KEEP everything between -5Hz and 5Hz. How can I do
that without using pass filters?? 

Once I have done that I will need to apply the hamming window and ifft.

I will appreciate any help.

Raj



                              
                               
                               



"rajgerman" <rajgerman@msn.com> wrote in message 
news:fbmdnaY_h7RZoprZnZ2dnUVZ_tmdnZ2d@giganews.com...
> Hey > > Thanks for your help Fred. > > I was told that I can filter my data much simpler without having to use > FIR filters. Does anyone know how I could do that?? > > semilogy(f,A), where: > > f = -fs/2:1/2:fs/2-1/2; fs = 44100Hz > A = fftshift(Z); Z has been ffted. > Length of signal = 2 seconds > > I want to be able to KEEP everything between -5Hz and 5Hz. How can I do > that without using pass filters?? > > Once I have done that I will need to apply the hamming window and ifft. > > I will appreciate any help. > > Raj
I am very concerned by your last comment: "once I have that done, apply the Hamming window and ifft". Windowing is normally done at the very beginning to avoid spectral leakage. It's normally done as a time domain multiply. So, I really don't understand what you're doing there. If you have a signal sampled at 44100Hz and you want to lowpass filter the data with a 5Hz frequency cutoff, that's a tall order because the filter will be very long indeed. You will have to filter lots of data just to fill up the filter *before* you get any good data out. Example: Lowpass filter with 5Hz cutoff. Assume 1Hz transition band in view of the 5Hz specification. This is 20% of the bandwidth and may not be good enough. A 1Hz transition band implies a filter that is around 1 second long 1/1Hz=1sec. That is 22050 samples long. That's a very long filter and I worry about roundoff errors, etc. After all, how can 22050 filter coefficients all have substantial impact on the filter output unless they are held to high precision? They can't. I imagine that the "much simpler" method for doing what you want is "fast convolution" which uses frequency domain multiplication. And, maybe that's why you want to use a Hamming window... let's see: Start with a perfect 5Hz Lowpass filter with a 1Hz transition from passband to stopband. The mid-point of the transition band will be at 5.5Hz. So, let's define a perfect lowpass filter with cutoff at 5.5Hz. Using the windowing method, you smooth out the edges of this filter to make it "real" I assume you will be using a Hamming window because that's what you've been talking about. The key is to get a filter that's reasonable and the perfect filter is not reasonable. So, you smooth the edges of the frequency transition to make it reasonable. You could do it this way: Define the perfect filter in the frequency domain. ifft the perfect filter. Multiply it by the window of choice. fft the result to get the reasonable filter in the frequency domain. Use that filter in fast convolution: fft the data multiply in frequency by the filter ifft the result to get the temporal filter output. THere are little details about the length of the arrays you work with: You need a filter that's about 1 second long to get the transition bandwidth you need in frequency. The data is 2 seconds long. Conceptually, you would convolve the two in time. The result would be 3 seconds long (less one sample). There will be a 1 second startup transient, 1 second of "good data" and 1 second of decay. Instead of convolving in time, fast convolution does it with multiplication in frequency: fft/multiply/ifft To do the multiply in frequency, you need to have an array that's the equivalent of a 3 second record in time to avoid temporal overlap in the convolution - that's a 1/3Hz sample interval in frequency. Since the sample rate is 44100Hz, that's a frequency record of length 132300 complex samples. So, do this: Compute a temporal Hamming window of length 1 second. Define a perfect filter of length 44100 samples. [1 1 1 1 1 1 0 0 ....... 1 1 1 1 1] it has 1 sample per Hz for a sample rate of 44100Hz. ifft the perfect filter to get a temporal filter of length 1 second. Multiply the Hamming window by the filter. Add enough zeros to the end of the filter to make it 3 secoonds long. fft the result. Now, take the data in time. Add enough zeros to the end of the data to make it 3 seconds long. fft the result. Multiply the filter times the data in frequency. ifft the result to get the filtered time data. Remember the beginnig and ending transient parts of this sequence.... Fred
Hey

As you know my x-axis is in frequiency terms.

f = -fs/2:1/2:fs/2-1/2;       fs = 44100Hz
A = fftshift(Z);              Z has been ffted.
Length of signal = 2 seconds

Isnt there just a way of saying that I want everything outside -5Hz and
5Hz to be deleted or just get rid of it and store the new reduced data A
into F??

I'm not too good with matlab so I'm trying to find the most easiest way. I
also don't want to use the signal processing tools. 

Thanks

Raj


"rajgerman" <rajgerman@msn.com> wrote in message 
news:5sCdnYPZPYNH4ZrZnZ2dnUVZ_tudnZ2d@giganews.com...
> Hey > > As you know my x-axis is in frequiency terms. > > f = -fs/2:1/2:fs/2-1/2; fs = 44100Hz > A = fftshift(Z); Z has been ffted. > Length of signal = 2 seconds > > Isnt there just a way of saying that I want everything outside -5Hz and > 5Hz to be deleted or just get rid of it and store the new reduced data A > into F?? > > I'm not too good with matlab so I'm trying to find the most easiest way. I > also don't want to use the signal processing tools. > > Thanks > > Raj > >
I think you already said it. There is no magic wand that you can wave and say those words and expect any results. If you mean is there a simple method, yes there is. But, it isn't considered to be a good thing. That's why you asked about the Hamming window no doubt. You can simply zero out all of the terms in the fft that are above 5Hz and below fs-5Hz. Then ifft. In other words, apply the perfect filter with no windowing. While you're at it you may as well scrunch the spectrum by eliminating a bunch of those zeros so the sample rate comes down close to 10Hz. Then ifft. The sample rate will be a lot lower. But then, you don't need a higher sample rate if the bandwidth is lower. Or, go in between to fs=100Hz or so and have a nicely interpolated signal but with lots less samples to deal with. The problem with this is that it will cause temporal leakage. The closer the data is to zero at 5Hz, the less error. Fred
Hey

I think I have an idea. I will create a vector (V) of the same length as
my signal, which will mostly contain 0's and 1's. 0's will get rid of the
frequncies I don't want and so on...

Does that sound ok??

Raj
rajgerman wrote:
> Hey > > I think I have an idea. I will create a vector (V) of the same length as > my signal, which will mostly contain 0's and 1's. 0's will get rid of the > frequncies I don't want and so on... > > Does that sound ok??
No. It will do what you want at the bin centers, but in between the response will be horrible. Jerry -- Engineering is the art of making what you want from things you can get. &#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;
Jerry Avins wrote:
> rajgerman wrote: > > I think I have an idea. I will create a vector (V) of the same length as > > my signal, which will mostly contain 0's and 1's. 0's will get rid of the > > frequncies I don't want and so on... > > > > Does that sound ok?? > > No. It will do what you want at the bin centers, but in between the > response will be horrible.
Trying to brick-wall an FFT seems to be a common misconception of how to filter. Is there a nice clear set of graphics on the web which shows what really happens to the complete continuous spectrum when one tries to do this? Thanks. -- rhn A.T nicholson d.0.t C-o-M

Jerry Avins wrote:
> > rajgerman wrote: > > Hey > > > > I think I have an idea. I will create a vector (V) of the same length as > > my signal, which will mostly contain 0's and 1's. 0's will get rid of the > > frequncies I don't want and so on... > > > > Does that sound ok?? > > No. It will do what you want at the bin centers, but in between the > response will be horrible.
Why will it be horrible? As far as I can tell The OP has never explained what he wants to do this time domain signal once he gets it. Given that you have no idea what purpose this signal might serve how can you make a judgment that it will be horrible. Maybe he doesn't want the in between frequencies. Or maybe he doesn't know what he wants. -jim ----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==---- http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups ----= East and West-Coast Server Farms - Total Privacy via Encryption =----