@@ -238,39 +238,52 @@ def detrend_linear(y):
238238 a = y .mean () - b * x .mean ()
239239 return y - (b * x + a )
240240
241-
242-
243241def psd (x , NFFT = 256 , Fs = 2 , detrend = detrend_none ,
244242 window = window_hanning , noverlap = 0 ):
245243 """
246- The power spectral density by Welches average periodogram method.
247- The vector x is divided into NFFT length segments . Each segment
248- is detrended by function detrend and windowed by function window.
249- noperlap gives the length of the overlap between segments. The
250- absolute(fft(segment ))**2 of each segment are averaged to compute Pxx,
251- with a scaling to correct for power loss due to windowing.
244+ The power spectral density by Welch's average periodogram method.
245+ The vector *x* is divided into * NFFT* length blocks . Each block
246+ is detrended by the function * detrend* and windowed by the function
247+ *window*. *noverlap* gives the length of the overlap between blocks.
248+ The absolute(fft(block ))**2 of each segment are averaged to compute
249+ *Pxx*, with a scaling to correct for power loss due to windowing.
252250
253- Fs is the sampling frequency (samples per time unit). It is used
254- to calculate the Fourier frequencies, freqs, in cycles per time
255- unit.
251+ If len(*x*) < *NFFT*, it will be zero padded to *NFFT*.
252+
253+ *x*
254+ Array or sequence containing the data
256255
257256 *NFFT*
258- The length of the FFT window. Must be even; a power 2 is most efficient.
257+ The number of data points used in each block for the FFT.
258+ Must be even; a power 2 is most efficient. The default value is 256.
259+
260+ *Fs*
261+ The sampling frequency (samples per time unit). It is used
262+ to calculate the Fourier frequencies, freqs, in cycles per time
263+ unit. The default value is 2.
259264
260265 *detrend*
261- is a function, unlike in matlab where it is a vector.
266+ Any callable function (unlike in matlab where it is a vector).
267+ For examples, see :func:`detrend`, :func:`detrend_none`, and
268+ :func:`detrend_mean`. The default is :func:`detrend_none`.
262269
263270 *window*
264- can be a function or a vector of length NFFT. To create window
265- vectors see numpy.blackman, numpy.hamming, numpy.bartlett,
266- scipy.signal, scipy.signal.get_window etc.
271+ A function or a vector of length *NFFT*. To create window
272+ vectors see :func:`window_hanning`, :func:`window_none`,
273+ :func:`numpy.blackman`, :func:`numpy.hamming`,
274+ :func:`numpy.bartlett`, :func:`scipy.signal`,
275+ :func:`scipy.signal.get_window`, etc. The default is
276+ :func:`window_hanning`.
267277
268- If len(*x*) < *NFFT*, it will be zero padded to *NFFT*.
278+ *noverlap*
279+ The number of points of overlap between blocks. The default value
280+ is 0 (no overlap).
269281
270282 Returns the tuple (*Pxx*, *freqs*).
271283
272- Refs: Bendat & Piersol -- Random Data: Analysis and Measurement Procedures, John Wiley & Sons (1986)
273-
284+ Refs:
285+ Bendat & Piersol -- Random Data: Analysis and Measurement
286+ Procedures, John Wiley & Sons (1986)
274287 """
275288 # I think we could remove this condition without hurting anything.
276289 if NFFT % 2 :
@@ -317,26 +330,50 @@ def psd(x, NFFT=256, Fs=2, detrend=detrend_none,
317330def csd (x , y , NFFT = 256 , Fs = 2 , detrend = detrend_none ,
318331 window = window_hanning , noverlap = 0 ):
319332 """
320- The cross spectral density Pxy by Welches average periodogram
333+ The cross power spectral density by Welch's average periodogram
321334 method. The vectors *x* and *y* are divided into *NFFT* length
322- segments. Each segment is detrended by function *detrend* and
323- windowed by function *window*. *noverlap* gives the length of the
324- overlap between segments. The product of the direct FFTs of *x*
325- and *y* are averaged over each segment to compute *Pxy*, with a
326- scaling to correct for power loss due to windowing. *Fs* is the
327- sampling frequency.
335+ blocks. Each block is detrended by the function *detrend* and
336+ windowed by the function *window*. *noverlap* gives the length
337+ of the overlap between blocks. The product of the direct FFTs
338+ of *x* and *y* are averaged over each segment to compute *Pxy*,
339+ with a scaling to correct for power loss due to windowing.
328340
329- *NFFT* must be even; a power of 2 is most efficient
341+ If len(*x*) < *NFFT* or len(*y*) < *NFFT*, they will be zero
342+ padded to *NFFT*.
330343
331- *window* can be a function or a vector of length *NFFT*. To create
332- window vectors see :func:`numpy.blackman`, :func:`numpy.hamming`,
333- :func:`numpy.bartlett`, :func:`scipy.signal`,
334- :func:`scipy.signal.get_window` etc.
344+ *x*, *y*
345+ Array or sequence containing the data
346+
347+ *NFFT*
348+ The number of data points used in each block for the FFT.
349+ Must be even; a power 2 is most efficient. The default value is 256.
350+
351+ *Fs*
352+ The sampling frequency (samples per time unit). It is used
353+ to calculate the Fourier frequencies, freqs, in cycles per time
354+ unit. The default value is 2.
355+
356+ *detrend*
357+ Any callable function (unlike in matlab where it is a vector).
358+ For examples, see :func:`detrend`, :func:`detrend_none`, and
359+ :func:`detrend_mean`. The default is :func:`detrend_none`.
360+
361+ *window*
362+ A function or a vector of length *NFFT*. To create window
363+ vectors see :func:`window_hanning`, :func:`window_none`,
364+ :func:`numpy.blackman`, :func:`numpy.hamming`,
365+ :func:`numpy.bartlett`, :func:`scipy.signal`,
366+ :func:`scipy.signal.get_window`, etc. The default is
367+ :func:`window_hanning`.
368+
369+ *noverlap*
370+ The number of points of overlap between blocks. The default value
371+ is 0 (no overlap).
335372
336- Returns the tuple (*Pxy*, *freqs*)
373+ Returns the tuple (*Pxy*, *freqs*).
337374
338375 Refs:
339- Bendat & Piersol -- Random Data: Analysis and Measurement
376+ Bendat & Piersol -- Random Data: Analysis and Measurement
340377 Procedures, John Wiley & Sons (1986)
341378 """
342379
0 commit comments