Windowing a signal in frequency space

AI Thread Summary
The discussion revolves around a Python script designed to process a noisy multi-frequency signal by transforming it to frequency space, applying a Gaussian window, and then transforming it back to time space. The user encounters an issue where the resulting windowed signal contains significant imaginary components, which are comparable to the real parts. This complexity arises from the application of the Gaussian window, which inadvertently cancels out negative frequency components during the transformation. The user realizes that this cancellation leads to the unexpected complex output when transforming back to time space, as they were anticipating a real sinusoidal signal instead of a complex one. The conversation highlights the importance of understanding the effects of windowing in frequency space on the resultant signal characteristics.
mdornfe1
Messages
3
Reaction score
0
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:
Fs=1000     #sampling frequency
fo=120      #center of gaussian   
sigma=0.01  #inverse width of gaussian
T=1./Fs
L=2**10     #number of samples
t=arange(0,L)*T #time vector
f=Fs*linspace(0,1,L)    #frequency vector
x=0.7*sin(2*pi*50*t) + sin(2*pi*120*t)+randn(t.size)/sqrt(t.size)   #signal
x_fft=fft(x)
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?
 
Technology news on Phys.org
Any chance you are getting a complex vector when you were expecting a,b as in a*cos(n*t)+b*sin(n*t)?

Or are you perhaps thinking you want the magnitude at each frequency and not the phase information?
 
I just realized what was happening. When I multiplied the transformed signal by the gaussian, I canceled out the negative frequency components. So of course when I transformed back the signal would be complex. I was expecting it to be a real sinusoid not a complex one.
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I have a quick questions. I am going through a book on C programming on my own. Afterwards, I plan to go through something call data structures and algorithms on my own also in C. I also need to learn C++, Matlab and for personal interest Haskell. For the two topic of data structures and algorithms, I understand there are standard ones across all programming languages. After learning it through C, what would be the biggest issue when trying to implement the same data...

Similar threads

Replies
1
Views
2K
Replies
5
Views
3K
Replies
1
Views
2K
Replies
8
Views
2K
Replies
10
Views
3K
Replies
1
Views
360
Replies
3
Views
1K
Back
Top