
Performing the Spectrogram on the DSP Shield EE264 Digital Signal Processing Final Report Christopher Ling Department of Electrical Engineering Stanford University Stanford, CA, US [email protected] Abstract—This report briefly describes the theory and implementation of a spectrogram of an audio file performed by a A. Anticipated Timeline DSP shield that sends the spectrogram data over a serial link to MATLAB. A brief analysis of the different spectrogram data will Week 1: Get input audio and perform one window of the also be discussed. spectrogram to be sent over MATLAB Week 2: Perform full spectrogram with all slices together. I. INTRODUCTION Week 3: Vary parameters like window length/type and sample The Discrete Fourier Transform (DFT) is a great way for a rate for different spectrograms. microprocessor to determine the frequency content of a signal, Week 4: Play audio while spectrogram plays, maybe to some but like most interesting signals that engineers would like to processing like speech or note recognition. analyze vary over time. This means that the frequency content of a signal will change over time. Furthermore, taking the DFT B. Actual Timeline of a very long signal with a lot of samples can be computationally expensive but not very information because Week 1: Get input audio and perform one window of the you do not know when certain bands of frequencies are present spectrogram to be sent over MATLAB at a certain point of time. In previous labs, the DSP shield has Week 2: Get full Input Audio by storing the data onto an SD been used for spectrum analysis for an audio signal that is 512 card. Read the data from the SD card. samples long at a sample rate of 48kHz, meaning the sample is Week 3: Perform full spectrogram and send spectrogram and 10ms. audio to MATLAB To capture the frequency content of a signal as a function Week 4: Vary parameters like window length/type and sample of time as well, I programmed the DSP to perform DFT on a rate for different spectrograms. specific time window of the signal, move the window, and III. CONCEPTS USED perform the DFT again. Then I plot how the frequencies change over how far the window is shifted in time. This process is To perform the spectrogram, we need to first understand known as the spectrogram. the DFT, Windowing, and the Time-Dependent Fourier The goal of this project is to use the DSP shield record and Transform. perform a spectrogram on a 2 seconds long audio file with a A. Discrete Fourier Transform programmable window length, window type and block To get the Fourier transform of a discrete signal, which is the skipping length. This spectrogram will then be sent over the only possible choice of getting a signal as opposed to a digital serial port to a PC computer via MATLAB for visual analysis. signal, we can only perform the Discrete Time Fourier II. TIMELINE Transform, which is defined as: ∞ Before following through with the project, the timeline of 푗푤 −푗휔푛 the project was established to get a good sense of how much 푋(푒 ) = ∑ 푥[푛]푒 (1) time I will need to take for the project. The biggest change I had 푛=−∞ to make was that I was unable to get the real-time spectrogram But because we are sampling our signal, the DFTF will be a to work because the serial port was too slow. I also had to take periodic signal that is a function of the sampling frequency. To some time to develop code that writes and reads audio files to ensure that there is no aliasing of the signal, we assume that the the SD card. sampling frequency is twice the maximum frequency of our sampled signal. However, the DSP cannot directly store the Fourier Transform of a signal in the DSP because it is a continuous Fig. 1. Different Window in Time-Domain signal; therefore, the DFTF needs to be discretized to N-points, meaning, we need to store the DFT, which is defined as: Time Domain of Windows 1 2휋푘 푋[푘] = 푋 (푒 푁 ) (2) 0.9 Rectangular Hann 0.8 Hamming The DSP shield has a built-in Fast Fourier Transform (FFT) Bartlett function that I will use to determine the DFT, and it’s the most 0.7 efficient when the number of points used is a power of 2. 0.6 For an N-point DFT of a sampling frequency of fs, the band 0.5 of frequencies we get range from 0 to fs/2 with N/2 frequencies 0.4 available to use for viewing. This is because the frequencies 0.3 from fs/2 to fs are flipped duplicates of the frequencies from 0 to fs/2 because of the periodic nature of the DFT. This means that 0.2 a longer DFT will give us more frequency resolution of our signal. 0.1 0 B. Windowing 0 100 200 300 400 500 The idea of the spectrogram is to perform the DFT on a specific section of the audio sample, and to do this we need to Fig. 2. Different Windows in Frequency-Domain (Hann and Hamming are get a window of the sample. basically rectangular, it’s hard to determine from the graph) If we were to just simply copy a segment of the signal to be FFT of windows processed by the DFT, we are essentially multiplying the signal in the time domain by a rectangular function, which means we Rectangular Hann are convoluting our signal in the frequency domain by a sinc 0 Hamming function. This greatly distorted our frequency response because Bartlett the sinc function has lower magnitudes in the high frequencies, meaning there will be distortion in the signal. -0.5 Ideally, we want to get a rectangular window of the signal in the frequency domain, so the best way to accomplish this is -1 to multiply the time-signal by a window function who’s frequency response looks more like a rectangle. There are several ways to do this, but the most common way is to use the -1.5 Hann, Hamming, or Bartlett window. The Bartlett window is easiest to compute because it’s simply a linear function. The -2 sinc function could work, but it’s computationally complicated, so the Hann and Hamming windows are better alternatives. 0 50 100 150 200 250 300 350 400 450 500 As seen in Figure 2, the frequency response of the Hann and Hamming windows are very close to rectangular, meaning the frequency response will be less distorted than convoluting with C. Time-Dependent Fourier Tranform the rectangular window (which isn’t rectangular in frequency response) and the Bartlett Window (which has some odd Finally to put everything together, we will now discuss how behavior approaching the edges of the windows). to perform the Time-Dependent Fourier Transform. An overall description is that we simply need to multiply our signal by the window that is time-shifted to the portion of the signal we wish to analyze and then perform the DFT on that section. The overall equation is: 퐿−1 2휋푘 −푗( )푚 [ ] [ ] [ ] 푁 푋 푛, 푘 = ∑ 푥 푛푅 + 푚 푤 푚 푒 (3) 푚=0 The Window w[m] has a length L, n is which block of samples to get, k is the frequency in the DFT, and R is how many samples to skip to get the next window of samples. IV. IMPLEMENTATION The three main functionalities implement were Audio The test MATLAB script I wrote was to get record 2 sample capture, spectrogram computation, and MATLAB seconds of audio, send a window that I design before-hand, get control of DSP. the audio file, and then get the spectrogram data. As mentioned before, all of the data has to be sent in bursts. As a result, the A. Acquired Data MATLAB script has to take into account of how many bursts In the beginning, my first attempt to acquire the audio data of data the DSP needs to send and how many get. was to copy data from the Audio buffers every single a new D. Other Comments buffer is filled, and keep filling them until the required window length is acquired. This was really difficult to implement As mentioned earlier, I had attempted to perform a real-time because depending on how many samples I skip per block and spectrogram of the input audio to the DSP, but the biggest the length of the window, the number of samples to copy from bottleneck I faced was the speed of which the data is sent over the audio buffer complicated and there needed to be a place to to MATLAB that I ended up not implementing this part into the store the other samples. DSP shield. One thing to try in the future is to reduce the Afterwards, I decided that the simplest way was to store the amount of data that is sent over through serial. entire audio file onto an SD card, very much like the recorder lab that was done in the beginning of the quarter. This way, the V. RESULTS audio data will always be available and I only need to parse through the .wav file stored in the SD card. I implemented a I compare the results of my spectrogram between the recording function that get the audio from the DSP input for a spectrogram developed by MATLAB. I will be using the specified amount of time, and then it store the audio file into spectrogram I develop to analyze the audio signals I have while the SD card.
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages6 Page
-
File Size-