Show Menu
Cheatography

EAD Python Reference Sheet Cheat Sheet (DRAFT) by

Reference sheet per il corso di Elaborazione Audio Digitale in python

This is a draft cheat sheet. It is a work in progress and is not finished yet.

matplotlib

Plot graph
plt.plot(x, y)
Show plot
plt.show()
Limit x axis
plt.xlim(left_lim, right_lim)
Limit y axis
plt.ylim(lower_lim, upper_lim)
Set x label
plt.xl­abel(string)
Set y label
plt.yl­abel(string)
Spectr­ogram
plt.pc­olo­rmesh(x, y, z, shadin­g="g­our­aud­")
import matplo­tli­b.p­yplot as plt

librosa

Carica da file
w, sr = libros­a.load(string, sr=None)
File di test
libros­a.ex(string)
Zero Crossing Rate
libros­a.f­eat­ure.ze­ro_­cro­ssi­ngs­_rate(signal)
MFCC
libros­a.f­eat­ure.mfcc(signal)
import librosa
 

Numpy

Range da start a stop con step
np.arange(start, stop, step)
Spazio lineare
np.lin­space(start, stop, sample­s_num)
Somma elementi
np.sum(vector)
Media elementi
np.mean(vector)
Segno elementi
np.sign(vector)
Differenza k - (k - 1)
np.diff(vector)
Elementi non nulli
np.non­zero(vector)[0]
Seno
np.sin(x)
Appendi in_2 a in_1
np.append(in_1, in_2)
Radice quadrata
np.sqrt(x)
Fourier Transform (Valori)
np.fft.rfft(signal, frame_­length)
Fourier Transform (Frequ­enze)
np.fft.rf­ftfreq(signal, frame_­length)
import numpy as np

scipy

Hann window
scipy.s­ig­nal.wi­ndo­ws.h­ann(frame
import scipy
 

Snippet vari

def DFT(x, N, sr):
    val = np.fft.rfft(x, N)
    freq = np.fft.rfftfreq(N, d=1/sr)
    return val, freq


# Framing
    for i in range(0, len(y), int(frame_length/2)):
        frame = y[i:i+int(frame_length)]
        #operazioni