Ejemplo n.º 1
0
def plotWavAnalysisDeep():
    """
    Read .WAV files, then plot a full analysis of the signal as in:
    https://matplotlib.org/gallery/lines_bars_and_markers/spectrum_demo.html#sphx-glr-gallery-lines-bars-and-markers-spectrum-demo-py

    Plot 1:
    """
    # Cut to the last ~30 seconds of the song since it had the most interesting
    # spectrogram.
    rate, data = wavfile.read('./Give_Love_A_Try.wav')
    f, t, Sxx = signal.spectrogram(data,rate)

    myfft = sf.sfft2(f)
    Interval = t[t.size-1] - t[0]
    Fs = len(myfft)                     # no. of samples
    s = np.abs(myfft)[:len(myfft)//2]   # Real signal symmetry only requires half the samples


    # plot time signal:
    plt.subplot(3,2,1)
    plt.title("Signal")
    plt.plot(s , color='C0')
    plt.xlabel("Time")
    plt.ylabel("Amplitude")

    # plot different spectrum types:
    plt.subplot(3,2,3)
    plt.title("Magnitude Spectrum")
    plt.magnitude_spectrum(s, Fs=Fs, color='C1')


    plt.subplot(3,2,4)
    plt.title("Logarithmic Magnitude Spectrum")
    plt.magnitude_spectrum(s, Fs=Fs, scale='dB', color='C1')


    plt.subplot(3,2,5)
    plt.title("Phase Spectrum")
    plt.phase_spectrum(s, Fs=Fs, color='C2')


    plt.subplot(3,2,6)
    plt.title("Anlge Spectrum")
    plt.angle_spectrum(s, Fs=Fs, color='C2')
    plt.tight_layout()
    plt.show()
Ejemplo n.º 2
0
import numpy as np

np.random.seed(0)

dt = 0.01
Fs = 1 / dt
t = np.arange(0, 10, dt)
nse = np.random.randn(len(t))
r = np.exp(-t / 0.05)

cnse = np.convolve(nse, r) * dt
cnse = cnse[:len(t)]
s = 0.1 * np.sin(2 * np.pi * t) + cnse

plt.subplot(3, 2, 1)
plt.plot(t, s)

plt.subplot(3, 2, 3)
plt.magnitude_spectrum(s, Fs=Fs)

plt.subplot(3, 2, 4)
plt.magnitude_spectrum(s, Fs=Fs, scale='dB')

plt.subplot(3, 2, 5)
plt.angle_spectrum(s, Fs=Fs)

plt.subplot(3, 2, 6)
plt.phase_spectrum(s, Fs=Fs)

plt.show()
Ejemplo n.º 3
0
def angle_spectrum(*args, **kwargs):
    r"""starkplot wrapper for angle_spectrum"""
    return _pyplot.angle_spectrum(*args, **kwargs)
Ejemplo n.º 4
0
cnse = np.convolve(nse, r) * dt
cnse = cnse[:len(t)]
s = 0.1 * np.sin(2 * np.pi * t) + cnse

plt.subplot(3, 2, 1)
plt.plot(t, s)

plt.subplot(3, 2, 3)
plt.magnitude_spectrum(s, Fs=Fs)

plt.subplot(3, 2, 4)
plt.magnitude_spectrum(s, Fs=Fs, scale='dB')

plt.subplot(3, 2, 5)
plt.angle_spectrum(s, Fs=Fs)

plt.subplot(3, 2, 6)
plt.phase_spectrum(s, Fs=Fs)

plt.show()

print("Test04-----------Start------------------")

x = np.array([0, 1, 2, 3, 4])
y = np.array([-1, 0.2, 0.9, 2.1, 1.2])
A = np.vstack([x, np.ones(len(x))]).T
m, c = np.linalg.lstsq(A, y)[0]
plt.plot(x, y, 'o', label='Original data', markersize=10)
plt.plot(x, m * x + c, 'r', label='Fitted line')
plt.legend()
Ejemplo n.º 5
0
    #plt.grid(True)

    plt.show()


#exemplo_8()
'''
mode : [ 'default' | 'psd' | 'magnitude' | 'angle' | 'phase' ]
    What sort of spectrum to use.  Default is 'psd', which takes
    the power spectral density.  'complex' returns the complex-valued
    frequency spectrum.  'magnitude' returns the magnitude spectrum.
    'angle' returns the phase spectrum without unwrapping.  'phase'
    returns the phase spectrum with unwrapping.
'''
'''
# Parametros de entrada (pode alterar)    
Fs = 250.0 # Hz    
Ts = 1/Fs  
t0 = 0.0
t1 = 6.0
time = np.arange(t0, t1+Ts, Ts)

print time.shape

f1 = 40
print 'Curva cosseno com frequencia:', f1, 'Hz'
x = np.cos(time * 2 * np.pi * f1)

print '\n'
#plt.specgram(x, NFFT=128, noverlap=64, Fs=250, cmap='rainbow', mode='angle')# mode='phase')