Week 6: 2D Arrays And Spectrograms

Chris Tralie

Real DFT Recap

Up to this point, we've seen the definition of the real discrete fourier transform (DFT). For a signal x with N samples, we take K = floor(N/2)+1 frequencies, starting at a frequency that goes through 0 cycles, all the way up to a frequency that goes through K-1 cycles over the interval of N samples. Let k be the number of cycles that a frequency goes through over this interval. Then we measure the cosine component of this frequency with the following dot product:

\[ c_k = \sum_{n = 0}^{N-1} x[n] \cos(2 \pi k n / N) \]

And we measure the sine component of this frequency with the following dot product:

\[ s_k = \sum_{n = 0}^{N-1} x[n] \sin(2 \pi k n / N) \]

2D Arrays: DFT

A 2D array A in numpy can be indexed as

We can also assign slices. For instance, if A is an M x N array, and we have an N-length 1D array x, we can assign x to a row i of A with

Create an array C where every row is a different cosine k and an array S where every row is a different sine. Then

2D Arrays: Shoft-Time Fourier Transform

For a signal x with N samples, choose a window length w and a hop length h. Create a 2D array where each column j is the DFT of the jth window of x. The array should have win/2 rows and floor((N-win)/hop)+1 columns.