Esempio n. 1
0
def showSTFT(x, samp_rate=16000):
    print(x)
#    plt.plot(range(len(x)), x)
#    plt.show()
    print (x.shape)
    print (type(x))
    y, p = STFT.stft(x, 1024, 128)

    # ordinary plot
    print(y)
#    plt.imshow(y, interpolation='nearest', aspect='auto')
    plt.imshow(y, aspect='auto')
    plt.show()

    print(p)
#    plt.imshow(p, interpolation='nearest', aspect='auto')
    plt.imshow(p, aspect='auto')
    plt.show()

    # more sophisticated plot
    time = np.asarray( range(y.shape[0]), dtype="float64") * 128. / samp_rate,
    freq = np.asarray( range(y.shape[1]), dtype="float64") / 512. * samp_rate / 2.
    print(time)
    print(freq)
    ext = [0, y.shape[0] * 128. / samp_rate,
           0, y.shape[1] / 512. * samp_rate / 2.]
    print(y)

    fig = plt.figure()  # create a figure object
    ax = fig.add_subplot(1, 1, 1)  # create an axes object in the figure
#    ax.imshow(y.T ** 0.6, aspect='auto', extent=ext, origin="lower", cmap="hot")
    ax.imshow(y.T ** 0.2, aspect='auto', extent=ext, origin="lower", cmap="hot")
    ax.set_xlabel("time [s]")
    ax.set_ylabel("frequency [Hz]")
    plt.show()

    print(p)
    fig = plt.figure()  # create a figure object
    ax = fig.add_subplot(1, 1, 1)  # create an axes object in the figure
    ax.imshow(p.T, aspect='auto', extent=ext, origin="lower", cmap="hot")
    ax.set_xlabel("time [s]")
    ax.set_ylabel("frequency [Hz]")
    plt.show()
Esempio n. 2
0
import matplotlib.pyplot as plot
import WAV as wav
import STFT as stft
from Oscillator import *

# Load sample input...
# x, sr = wav.read("wav/tomsawyer.wav")

# or produce cos wave
# sr = 44100.0
# osc = Oscillator(sr, 440.0)
# x = 0.5 * osc.getBuffer(123456)

# Set STFT parameters
winSize = 1024 * 2  # in samples
hopSize = winSize / 4  # in samples

# Build output signal
frames = stft.stft(x, winSize, hopSize)
y = stft.istft(frames, winSize, hopSize)

# Plot x-y difference
n = min(len(x), len(y))
diff = abs(x[0:n] - y[0:n])
plot.figure()
plot.plot(diff, "b")
plot.show()

# Write out results
wav.write(x, sr, "wav/stft_input.wav")
wav.write(y, sr, "wav/stft_output.wav")
Esempio n. 3
0
import matplotlib.pyplot as plot
import WAV as wav
import STFT as stft
from Oscillator import *

# Load sample input...
# x, sr = wav.read("wav/tomsawyer.wav")

# or produce cos wave
# sr = 44100.0
# osc = Oscillator(sr, 440.0)
# x = 0.5 * osc.getBuffer(123456)

# Set STFT parameters
winSize = 1024*2      # in samples
hopSize = winSize/4   # in samples

# Build output signal
frames = stft.stft(x, winSize, hopSize)
y = stft.istft(frames, winSize, hopSize)

# Plot x-y difference
n = min(len(x), len(y))
diff = abs(x[0:n] - y[0:n])
plot.figure()
plot.plot(diff, "b")
plot.show()

# Write out results
wav.write(x, sr, "wav/stft_input.wav")
wav.write(y, sr, "wav/stft_output.wav")
Esempio n. 4
0
###############
# HR analysis #
###############
The_z, The_alpha = hr.analyse(s, Fs, D, L, rank, n, l, rmax)

#####################
# plot sepctrogram  #
#####################
nfft = 4096
hopSize = 512
winSize = 3000  # 68 ms at 44100 Hz

plt.subplot(2, 1, 1)
plt.title('spectrogram')
Xs, f, t = STFT.spectrogram(s, winSize, hopSize, nfft, Fs, plot=True)
# plt.show()

##################
# plot HRogramme #
##################
d = loadmat('colors.mat')  # load Roland Badeau's colormap

plt.subplot(2, 1, 2)
hr.HRogram(int(N * D / 8), Fs, The_z, The_alpha, n, d['colors'])
plt.title('HRogram')
plt.tight_layout()

#######################################
# re-synthesize the sinusoidal signal #
#######################################
Esempio n. 5
0
#==============================================================================

#==============================================================================
# Input signal
t = arange(0, 1, 1.0 / SR)
f = 1000
x = sin(2 * pi * f * t)
for i in range(2, 6):
    x += sin(2 * pi * (f * i) * t)
x = x[0:signalSize]
#==============================================================================

#x, SR = wav.read("wav/la.wav")
#x = x[2000:5000]

phasogram = stft.stft(x, windowSize, 1)

phasogram = angle(phasogram)
#phasogram = log(abs(phasogram))
phasogram = fft.irfft(phasogram)

# Frequency bin of the input signal
k = len(phasogram) * f / (SR / 2)

#==============================================================================
#plot.figure()
#r=range(0, len(phasogram)) # display range
#plot.subplot(211)
#plot.title('Signalabschnitt')
#plot.ylabel('[-1,1]')
#plot.plot(r, x[r])
Esempio n. 6
0
signalSize = windowSize*2
#==============================================================================

#==============================================================================
# Input signal
t = arange(0, 1, 1.0/SR)
f = 1000
x = sin(2*pi*f*t)
for i in range(2,6): x += sin(2*pi*(f*i)*t)
x = x[0:signalSize]
#==============================================================================

#x, SR = wav.read("wav/la.wav")
#x = x[2000:5000]

phasogram = stft.stft(x, windowSize, 1)

phasogram = angle(phasogram)
#phasogram = log(abs(phasogram))
phasogram = fft.irfft(phasogram)

# Frequency bin of the input signal
k = len(phasogram) * f / (SR/2)

#==============================================================================
#plot.figure()
#r=range(0, len(phasogram)) # display range
#plot.subplot(211)
#plot.title('Signalabschnitt')
#plot.ylabel('[-1,1]')
#plot.plot(r, x[r])