matplotlib.mlab.psd: zero padding + detrending

Hello all,

I am using matplotlib.mlab.psd to find power spectra of measured data. Sometimes it happens that I use the automatic zero padding (if the length of my measured data is smaller than nFFT) and detrending (pylab.detrend_mean) at the same time.

I think that the psd-algorithm does the zero padding *first* and *then* uses the detrend function.

For my application this is not good because it introduces low-frequency signals that I can see in the spectrum. So the detrending does not work as good as it does when there is no zero padding.

What is the reason for this order of applying zero padding and detrending? Wouldn't it make sense to change it?

Thanks
Lars

···

--
Dipl.-Ing. Lars Friedrich

Photonic Measurement Technology
Department of Microsystems Engineering -- IMTEK
University of Freiburg
Georges-Köhler-Allee 102
D-79110 Freiburg
Germany

phone: +49-761-203-7531
fax: +49-761-203-7537
room: 01 088
email: lfriedri@...1435...

I wrote this function many years ago and do not remember why I choose
the order pad then detrend, but what you propose makes sense, so let's
let this percolate for a bit and if noone objects I will change it
(and related functions).

JDH

···

On 10/2/07, Lars Friedrich <lfriedri@...1435...> wrote:

Hello all,

I am using matplotlib.mlab.psd to find power spectra of measured data.
Sometimes it happens that I use the automatic zero padding (if the
length of my measured data is smaller than nFFT) and detrending
(pylab.detrend_mean) at the same time.

I think that the psd-algorithm does the zero padding *first* and *then*
uses the detrend function.

For my application this is not good because it introduces low-frequency
signals that I can see in the spectrum. So the detrending does not work
as good as it does when there is no zero padding.

What is the reason for this order of applying zero padding and
detrending? Wouldn't it make sense to change it?

John Hunter wrote:

···

On 10/2/07, Lars Friedrich <lfriedri@...1435...> wrote:

Hello all,

I am using matplotlib.mlab.psd to find power spectra of measured data.
Sometimes it happens that I use the automatic zero padding (if the
length of my measured data is smaller than nFFT) and detrending
(pylab.detrend_mean) at the same time.

I think that the psd-algorithm does the zero padding *first* and *then*
uses the detrend function.

For my application this is not good because it introduces low-frequency
signals that I can see in the spectrum. So the detrending does not work
as good as it does when there is no zero padding.

What is the reason for this order of applying zero padding and
detrending? Wouldn't it make sense to change it?

I wrote this function many years ago and do not remember why I choose
the order pad then detrend, but what you propose makes sense, so let's
let this percolate for a bit and if noone objects I will change it
(and related functions).

The change makes sense to me also.

Eric