Formulas

Euler

IIR Formulas

Code

DFT Python

N = len(signal)
X = np.zeros(N)
for k in range(N):
	for n in range(N):
		X[k] += signal[n] * np.exp(-2j * np.pi * k * (n/N))

IDFT

N = len(signal)
x = np.zeros(N)
for n in range(N):
	for k in range(N):
		x[n] += X[k] * np.exp(2j * np.pi * k * (n/N))
x /= N

Getting a WAV file (assuming 16bit):

input_wav = wavfile.get("file.wav")
signal = input_wav / (2**15)

Making a WAV file (assuming 16 bit):

signal = ...
output_wav = signal * (2**15)

Plotting DB Frequency Pseudocode:

# assuming f_sig is already the dft of a signal
f_sig = X[:N//2] # take only first half of frequency response
f_db = 20 * np.log10( np.abs(f_sig) )
freq_axis = [idx * f_s / N for idx in range(N//2)]
plot(y=f_db,x=freq_axis)

Slicing and Filters:

"""
Your cutoff frequency can be translated into a sample number using
cutoff = int(f_c / f_s * N)
"""
f_s = 10000
N = len(signal)
f_low = 1000
f_high = 3000
 
cutoff_low = int(f_low / f_s * N)
cutoff_high = int(f_high / f_s * N)
 
# Highpass
signal[:cutoff_low] = 0  # Up until cutoff = 0
signal[-cutoff_low:] = 0 # Inverse of line above, just the aliased version
 
# 0 1 2 3 4 5 6 7 8 9 X   <- Initial
#     2 3 4 5 6 7 8 9 X   <- Line 1
#     2 3 4 5 6 7 8       <- Line 2
 
 
# Lowpass
signal[cutoff_high:N//2] = 0
signal[N//2:-cutoff_high] = 0
 
# 0 1 2 3 4 5 6 7 8 9 X <- Initial
# 0 1 2     5 6 7 8 9 X <- Line 1
# 0 1 2           8 9 X <- Line 2
 
# Bandstop
signal[cutoff_low:cutoff_high] = 0
signal[-cutoff_high:-cutoff_low] = 0
 
# 0 1 2 3 4 5 6 7 8 9 X <- Initial
# 0       4 5 6 7 8 9 X <- Line 1
# 0       4 5 6       X <- Line 2
 
# Bandpass is just highpass + lowpass
 
# With bounds around target
bound = 50
cutoff_bound = int(bound / f_s * N)
 
# Lowpass Ex:
signal[:cutoff_low+bound] = 0
signal[-cutoff_low-bound:] =0
 

FIR Knowledge

Where you use either the cutoff frequency, or the bandwidth of the filter

FIRs don’t necessarily perform convolutions as there is a finite range as opposed to the range of convolutions

Calculate frequency response: Sub in for Example:

IIR Knowledge

Poles on S-Plane Right to Left, in groups of 2, to form a chain of second order filters

Higher Damping on Window is Wider Transition from stop to passband. Blackman highest, Hamming better for lower damping

When asked on a transfer like this:

In this example, r affects the stability and notch width and attenuation depth. affects the centre frequency of the notch, and therefore the cutoffs too

DATAFLOW: