Test axes.specgram in magnitude mode.
()
| 5987 | "specgram_magnitude_noise.png", "specgram_magnitude_noise_linear.png"], |
| 5988 | remove_text=True, tol=0.07, style="default") |
| 5989 | def test_specgram_magnitude(): |
| 5990 | """Test axes.specgram in magnitude mode.""" |
| 5991 | |
| 5992 | # use former defaults to match existing baseline image |
| 5993 | matplotlib.rcParams['image.interpolation'] = 'nearest' |
| 5994 | |
| 5995 | n = 1000 |
| 5996 | Fs = 10. |
| 5997 | |
| 5998 | fstims = [[Fs/4, Fs/5, Fs/11], [Fs/4.7, Fs/5.6, Fs/11.9]] |
| 5999 | NFFT_freqs = int(100 * Fs / np.min(fstims)) |
| 6000 | x = np.arange(0, n, 1/Fs) |
| 6001 | y = np.sin(2 * np.pi * np.multiply.outer(fstims, x)).sum(axis=1) |
| 6002 | y[:, -1] = 1 |
| 6003 | y_freqs = np.hstack(y) |
| 6004 | |
| 6005 | NFFT_noise = int(10 * Fs / 11) |
| 6006 | np.random.seed(0) |
| 6007 | y_noise = np.concatenate([np.random.standard_normal(n), np.random.rand(n)]) |
| 6008 | |
| 6009 | all_sides = ["default", "onesided", "twosided"] |
| 6010 | for y, NFFT in [(y_freqs, NFFT_freqs), (y_noise, NFFT_noise)]: |
| 6011 | noverlap = NFFT // 2 |
| 6012 | pad_to = int(2 ** np.ceil(np.log2(NFFT))) |
| 6013 | for ax, sides in zip(plt.figure().subplots(3), all_sides): |
| 6014 | ax.specgram(y, NFFT=NFFT, Fs=Fs, noverlap=noverlap, |
| 6015 | pad_to=pad_to, sides=sides, mode="magnitude") |
| 6016 | for ax, sides in zip(plt.figure().subplots(3), all_sides): |
| 6017 | ax.specgram(y, NFFT=NFFT, Fs=Fs, noverlap=noverlap, |
| 6018 | pad_to=pad_to, sides=sides, mode="magnitude", |
| 6019 | scale="linear", norm=matplotlib.colors.LogNorm()) |
| 6020 | |
| 6021 | |
| 6022 | @image_comparison( |