# [SciPy-user] Frequency content of a transient signal

Nils Wagner nwagner@iam.uni-stuttgart...
Tue Jul 22 03:52:31 CDT 2008

```On Tue, 22 Jul 2008 09:59:13 +0200
"Matthieu Brucher" <matthieu.brucher@gmail.com> wrote:
> 2008/7/22 Nils Wagner <nwagner@iam.uni-stuttgart.de>:
>> On Tue, 22 Jul 2008 09:15:11 +0200
>>  "Matthieu Brucher" <matthieu.brucher@gmail.com> wrote:
>>>
>>> Hi !
>>>
>>> I think you can use a sliding DFT on your signal. This
>>>way, you will
>>> get a moving estimation of the spectral information
>>>(it's a basic
>>> time-frequency transform, before you use wavelets ;)).
>>>
>>> Matthieu
>>>
>>  Matthieu,
>>
>> I am not very familiar with signal processing. Please
>>can
>> you provide a short example ?
>> I have attached the data file. The first column
>>corresponds
>> with the time, the second column represents the signal.
>>
>>                      Nils
>
> A wikipedia article states it better than me, so here is
> http://en.wikipedia.org/wiki/Short-time_Fourier_transform
>Feel free to ask any question ;)
>

How do I produce the nice spectrograms

from scipy import *
from pylab import plot, show
#
# Example taken from
http://en.wikipedia.org/wiki/Short-time_Fourier_transform
#
def x(t):
if t < 5:
return cos(2*pi*10*t)
if t >= 5. and t < 10:
return cos(2*pi*25*t)
if t >=10. and t< 15:
return cos(2*pi*50*t)
if t >=15. and t<= 20:
return cos(2*pi*100*t)

t = linspace(0.,20.,8001) # sampled at 400 Hz
x_vec = vectorize(x)
signal = x_vec(t)
plot(t,signal)
#
# How can I obtain the nice spectrograms ?
#
show()
...
to be continued

Nils

> In fact, what you will do is :
>
> my_ffts = []
> fo i in range(n):
>  my_ffts.append(fft(data[i*size:(i+1)*size]))
>
> with size the size of the sliding window you will use.
>This will give
> you non overlapping FFTs, but you can use overlapping
>FFT, such as :
>  my_ffts.append(fft(data[(i-1/2.)*size:(i+3/2.)*size]))
>

```