MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / _spectral_helper

Function _spectral_helper

lib/matplotlib/mlab.py:223–391  ·  view source on GitHub ↗

Private helper implementing the common parts between the psd, csd, spectrogram and complex, magnitude, angle, and phase spectrums.

(x, y=None, NFFT=None, Fs=None, detrend_func=None,
                     window=None, noverlap=None, pad_to=None,
                     sides=None, scale_by_freq=None, mode=None)

Source from the content-addressed store, hash-verified

221
222
223def _spectral_helper(x, y=None, NFFT=None, Fs=None, detrend_func=None,
224 window=None, noverlap=None, pad_to=None,
225 sides=None, scale_by_freq=None, mode=None):
226 """
227 Private helper implementing the common parts between the psd, csd,
228 spectrogram and complex, magnitude, angle, and phase spectrums.
229 """
230 if y is None:
231 # if y is None use x for y
232 same_data = True
233 else:
234 # The checks for if y is x are so that we can use the same function to
235 # implement the core of psd(), csd(), and spectrogram() without doing
236 # extra calculations. We return the unaveraged Pxy, freqs, and t.
237 same_data = y is x
238
239 if Fs is None:
240 Fs = 2
241 if noverlap is None:
242 noverlap = 0
243 if detrend_func is None:
244 detrend_func = detrend_none
245 if window is None:
246 window = window_hanning
247
248 # if NFFT is set to None use the whole signal
249 if NFFT is None:
250 NFFT = 256
251
252 if not (0 <= noverlap < NFFT):
253 raise ValueError('noverlap must be less than NFFT')
254
255 if mode is None or mode == 'default':
256 mode = 'psd'
257 _api.check_in_list(
258 ['default', 'psd', 'complex', 'magnitude', 'angle', 'phase'],
259 mode=mode)
260
261 if not same_data and mode != 'psd':
262 raise ValueError("x and y must be equal if mode is not 'psd'")
263
264 # Make sure we're dealing with a numpy array. If y and x were the same
265 # object to start with, keep them that way
266 x = np.asarray(x)
267 if not same_data:
268 y = np.asarray(y)
269
270 if sides is None or sides == 'default':
271 if np.iscomplexobj(x):
272 sides = 'twosided'
273 else:
274 sides = 'onesided'
275 _api.check_in_list(['default', 'onesided', 'twosided'], sides=sides)
276
277 # zero pad x and y up to NFFT if they are shorter than NFFT
278 if len(x) < NFFT:
279 n = len(x)
280 x = np.resize(x, NFFT)

Callers 3

_single_spectrum_helperFunction · 0.85
csdFunction · 0.85
specgramFunction · 0.85

Calls 3

_stride_windowsFunction · 0.85
detrendFunction · 0.85
resizeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…