466 lab4

203 days ago by jay

CES466 Lab 4

Exploring the effectiveness of the Goertzel Algorithm for different frequencies and sampling rates.

Here we first implement the algorithm itself and then make a little wrapper function for simulating it's response.

Notice that k and \omega are defined a bit differently than in the lab reference. This way gives improved SNR and matching to the target frequency.

X = [] data = [] def goertzel(samples, ft = 9250, fs = 30000, Ns = 20): w, k = var('w,k') #k = floor(1/2 + ft/fs*Ns) # this #w = 2*pi*k/Ns k = ft/fs w = 2*pi*k coef = 2*cos(w) Q1 = 0 Q2 = 0 for s in samples: Q0 = N(s + coef*Q1 - Q2) Q2 = Q1 Q1 = Q0 return N(Q2^2 + Q1^2 - coef*Q1*Q2) def goertzel_sim(fg = 9250, ft = 9250, fs = 30000, Ns = 20): global X, data f_real(t) = sin(2*pi*fg*t) start = 0 stop = Ns/fs nw = 0 sw = 1 X = srange(start, stop, (stop-start)/Ns) data = [sw*f_real(x) + nw*random() for x in X] return goertzel(data, ft, fs, Ns) 
       

In this next section we look at how the values given by the Goertzel across a range of frequencies.

T = srange(5000,14000,50) r1 = [goertzel_sim(fg = f, fs = 30000, Ns=20) for f in T] m1 = max(r1) mi1 = r1.index(m1) r2 = [goertzel_sim(fg = f, fs = 30000, Ns=32) for f in T] m2 = max(r2) mi2 = r2.index(m2) html("Frequency response for $F_T = 9250$Hz and $F_S = 30,000$Hz") html("<p>N=20 Max value: $%.4f$, At freq: $%d$Hz"%(m1, T[mi1])) html("<p>N=32 Max value: $%.4f$, At freq: $%d$Hz"%(m2, T[mi2])) l1 = line(zip(T,r1), color=(0,0,1)) l2 = line(zip(T,r2), color=(0,.8,0)) t = line(((9250,0),(9250,m2)), color=(1,0,0)) l1+l2+t 
       
Frequency response for F_T = 9250Hz and F_S = 30,000Hz

N=20 Max value: 96.5112, At freq: 9150Hz

N=32 Max value: 245.5461, At freq: 9300Hz

Frequency response for F_T = 9250Hz and F_S = 30,000Hz

N=20 Max value: 96.5112, At freq: 9150Hz

N=32 Max value: 245.5461, At freq: 9300Hz

Here is some data generated across a range of input frequencies and sampling rates for the target frequency of 9250Hz.

I = srange(5000,14000,250) J = srange(16000,60000,2000) data = [(i, j, goertzel_sim(fg = i, fs = j, Ns = 20)) for i in I for j in J] 
       

And then it is plotted.

And then it is plotted.  As you can see (beneath about 22ksps) there are significant responses for non-target frequencies.  This means that high frequency noise could be an issue even at 30ksps if it is too strong, or the target signal is too weak.

lp = list_plot3d(data, point_list=True, interpolation_type='linear') lp.show(viewer='tachyon')