Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

FFT using window method and FFT filtering

Status
Not open for further replies.

seharryssona

Newbie level 1
Joined
Nov 3, 2011
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,298
Dear all,

I am new to the subject of signal processing and have some (probably elementary) questions that I currently could not find the answer to. The questions are all related to FFT and filtering.

I think I have figured out why the window method is used then doing a FFT, and have also tested this with some simple python code as below:


Code Python - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# Sampling data
sr = 40
t_end = 4
n_samp = sr*t_end
n = 512
 
# Create time axis and freq axis
t = linspace(0,t_end,n_samp)
F1 = arange(-n/2.0,n/2.0)/n*sr
 
# Create output
y2 = 2*sin(4.03452*pi*t)+3*sin(5.2123*pi*t)+1*sin(8.3212*pi*t)
 
# Window
w = hamming(len(t))
 
# Do fft of signal
X2 = fft(y2*w,n=n)
X2_s = fftshift(X2)



However, when it comes to FFT filtering, how does the different window methods enter into the equations? If I would like to construct a bandpass filter, say with the the amp = [0,1,1,0] at freqs = [2.0, 2.2, 2.8, 3.0], how do the different windows come into the code? I have tried according to:


Code Python - [expand]
1
2
3
4
5
6
7
ff = (0,1,1,0)
Hz = (2.0, 2.2, 2.8, 3.0)
k1 = interp(-F1,Hz,ff)+interp(F1,Hz,ff)
w2 = hamming(len(k1))
X2_f = X2_s*k1*w2
X2_f = ifftshift(X2_f)
x2_f = ifft(X2_f,n=int(n))



i.e. I used the result from the FFT when the hamming window was applied to the original signal as a starting point to do the filtering. In order to check if this code ended up in something useful, I imported the signal into the music program Cool Edit, and performed a similar filtration. However, the results was not very similar when it comes to the amplitudes of the filtered signal.


If any one could give me some ideas on what to do, and perhaps point out where I get things wrong in my code, I would be very happy.


Regards,
Anders
 


Code Python - [expand]
1
2
3
4
5
6
7
ff = (0,1,1,0)
Hz = (2.0, 2.2, 2.8, 3.0)
k1 = interp(-F1,Hz,ff)+interp(F1,Hz,ff)
w2 = hamming(len(k1))
X2_f = X2_s*k1*w2
X2_f = ifftshift(X2_f)
x2_f = ifft(X2_f,n=int(n))



i.e. I used the result from the FFT when the hamming window was applied to the original signal as a starting point to do the filtering. In order to check if this code ended up in something useful, I imported the signal into the music program Cool Edit, and performed a similar filtration. However, the results was not very similar when it comes to the amplitudes of the filtered signal.

I hope this will still be useful after a year! I don't understand your code 100% (especially what fftshift and ifftshift do), but one thing that jumps out at me is that you seem to be rewindowing the frequency coefficients before inverse-transforming back to the time domain. This will effectively introduce an extra set of frequency weightings on top of the actual filter characteristic in k1. This is implied by the line:

Code Python - [expand]
1
X2_f = X2_s*k1*w2


From what I gather, X2_s is the array of complex frequency coefficients from the forward FFT, and k1 is the array of real or complex frequency coefficients by which X2_s is multiplied to perform the filtering operation. The multiplication by w2 shouldn't be here - windowing is most easily done by multiplying in the time domain (doing it in the frequency domain would require convolution), and you did the time-domain multiplication further up, just before the FFT, which is correct. Re-windowing through multiplication here will just change the effective frequency response of the filter, which is probably the difference you're seeing when you compare with Cool Edit. If you remove the *w2 term from that line (and in fact remove w2 from the program altogether) you should be much closer to the results you're looking for. The only remaining problem will be that your test signal is tapered, and to overcome that you'll need to (a) pad the signal at both ends with half a block of zero samples), (b) use the multi-block overlap-paste technique (with an overlap ratio appropriate for the window function).

Example: for your Hamming window, you'll need the blocks to overlap each other by 50%, i.e. each block starts halfway through the previous one. Hamming-window each block identically, do the FFT, multiply by k1, and IFFT it, then mix-paste that block into the output stream at the same relative position as in the input stream. If you then chop off the half-block padding from the beginning and end of the reconstituted signal, it'll be correctly aligned to the original but with the frequency response described by k1.

NB: since the Hamming window has a mean of 0.54, and the overlap factor is 2, the reconstructed signal will have an overall amplitude 8% higher than the original. To match the results in Cool Edit, you'll need to divide the output samples by 1.08 to match levels. The Hann window requires no such relevelling for an overlap factor of 2 because its mean is exactly 0.5.

Overlap and amplitude requirements for perfect block rejoining vary with more complex windowing functions. Let me know if you're interested in using some other window, but I'd suggest sticking to Hann or Hamming for now just to prove the concept successfuly.

Hope that helps.

P.S. I've done some theoretical work recently that suggests that for an amplitude-weighting filter like this (i.e. no phase shifts), windowing can be left for the reconstruction stage. If you ever get the window-overlap-paste algorithm together, I'd be interested to see what happens if you move the window multiplication from before the forward FFT to after the IFFT (i.e. just before paste). If I'm right, the results should be the same.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top