I have computed a scipy.signal.spectrogram. Now i want to filter and not show some unwanted frequencies on the y axis.
I want to remove the freqs between 47 - 53 and 97 - 103 completely. This cannot be done only by manipulating the plot since the freqs still distorts the color intensity of the plot.
I have tried different things with zero result.
Fs = 500 # Define the sampling frequency,
interval = int(Fs/6) # ... the interval size,
overlap = int(interval * 0.99) # ... and the overlap intervals
import matplotlib
import pylab
import matplotlib.colors as colors
from scipy.stats import lognorm
amp = 2 * np.sqrt(2)
f, t, Sxx = signal.spectrogram(np.array(sze), fs=Fs, nperseg=interval, noverlap=overlap, mode='psd', scaling='density', nfft=1000, window='hann')
plt.figure(figsize=(7,7))
Sxx = 10*np.log10(Sxx)
# Sxx = np.concatenate((Sxx[(t < 47)], Sxx[(t > 53)]), axis=0)
# f = np.concatenate((f[(f < 47)], f[(f > 53)]), axis=0)
#normalize_color= colors.LogNorm(vmin=np.amin(Sxx), vmax=np.amax(Sxx))
plt.pcolormesh(t, f, Sxx, cmap='jet')# Plot the result
plt.colorbar()
plt.title("Spectrogram: Sample Rate 500 Hz ")
plt.ylabel("Freq")
plt.xlabel("Time (sec)")
The code i have commented out did not work.
Here's my plot:
The output of the signal.spectrogram is two np.arrays: Sxx.shape = (501, 1918) and f is (501,). I expect that red line at 50 Hz is removed and the label on y isn't showing. also that the other frequency color changes.