MCPcopy
hub / github.com/LCAV/pyroomacoustics / compare_plot

Function compare_plot

pyroomacoustics/utilities.py:373–454  ·  view source on GitHub ↗
(
    signal1,
    signal2,
    Fs,
    fft_size=512,
    norm=False,
    equal=False,
    title1=None,
    title2=None,
)

Source from the content-addressed store, hash-verified

371
372
373def compare_plot(
374 signal1,
375 signal2,
376 Fs,
377 fft_size=512,
378 norm=False,
379 equal=False,
380 title1=None,
381 title2=None,
382):
383 try:
384 import matplotlib.pyplot as plt
385 except ImportError:
386 import warnings
387
388 warnings.warn("Matplotlib is required for plotting")
389 return
390
391 td_amp = np.maximum(np.abs(signal1).max(), np.abs(signal2).max())
392
393 if norm:
394 if equal:
395 signal1 /= np.abs(signal1).max()
396 signal2 /= np.abs(signal2).max()
397 else:
398 signal1 /= td_amp
399 signal2 /= td_amp
400 td_amp = 1.0
401
402 plt.subplot(2, 2, 1)
403 plt.plot(np.arange(len(signal1)) / float(Fs), signal1)
404 plt.axis("tight")
405 plt.ylim(-td_amp, td_amp)
406 if title1 is not None:
407 plt.title(title1)
408
409 plt.subplot(2, 2, 2)
410 plt.plot(np.arange(len(signal2)) / float(Fs), signal2)
411 plt.axis("tight")
412 plt.ylim(-td_amp, td_amp)
413 if title2 is not None:
414 plt.title(title2)
415
416 from .stft import spectroplot, stft
417 from .windows import hann
418
419 F1 = stft.stft(signal1, fft_size, fft_size / 2, win=windows.hann(fft_size))
420 F2 = stft.stft(signal2, fft_size, fft_size / 2, win=windows.hann(fft_size))
421
422 # try a fancy way to set the scale to avoid having the spectrum
423 # dominated by a few outliers
424 p_min = 1
425 p_max = 99.5
426 all_vals = np.concatenate((dB(F1 + eps), dB(F2 + eps))).flatten()
427 vmin, vmax = np.percentile(all_vals, [p_min, p_max])
428
429 cmap = "jet"
430 interpolation = "sinc"

Callers

nothing calls this directly

Calls 3

dBFunction · 0.85
flattenMethod · 0.80
plotMethod · 0.45

Tested by

no test coverage detected