Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Windowing a signal in frequency space

  1. Jun 26, 2012 #1
    I'm not sure if this is the right place to post this, but I'm trying to write a python script that takes a noisy multi frequency signal, transforms it to frequency space, windows it there with a gaussian, then transforms it back to time space. Here is what I wrote:

    Code (Text):
    Fs=1000     #sampling frequency
    fo=120      #center of gaussian  
    sigma=0.01  #inverse width of gaussian
    L=2**10     #number of samples
    t=arange(0,L)*T #time vector
    f=fftfreq(L,T)    #frequency vector
    x=0.7*sin(2*pi*50*t) + sin(2*pi*120*t)+randn(t.size)/sqrt(t.size)   #signal
    W=exp(-square(2*pi*sigma*(f-fo)))   #gaussian window
    y=ifft(W*x_fft)                      #windowed signal
    The problem I'm running into is the windowed signal y has non negligible imaginary parts. They're about the same order as the real parts. Does anyone know why I might be getting this?
  2. jcsd
  3. Jul 4, 2012 #2
    MATLAB fft returns the signal spectrum both for positive and negative frequencies. Of course in your case the signal is real so its spectrum is symmetric under conjugation.
    When you multiplied by a window, you eliminated the negative frequencies of the signal, thus transforming it to a complex signal (its spectrum is no longer symmetric).
    For a L-point DFT (suppose L is even), the indices 1:L/2 in the vector correspond to the frequencies [0,pi), and the indices (L/2+1):L correspond to the frequencies [-pi,0) (in the same order).
    I'll leave it up to you to figure out how to correctly filter the signal with the Gaussian window.
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook