Friday, October 18, 2019

stft - Computing narrowband spectrograms using MATLAB



I'm having an assignment of computing narrowband spectrograms using MATLAB. And I totally have no idea about the code. Can someone help me writing the code and explaining what's going on to me. Lots of thanks!!



Followings are the requirement:


B.1. Load the recorded .wav file using the function “wavread”. Let y be the variable storing the signal;


B.2. Perform short-time Fourier transform on y as follows: (i) Divide the signal into many short-time frames. Each frame is 50 msec long. Frame shift is 1 msec;


(ii) Apply 1024-point FFT on each frame;


(iii) Store the power spectrum of each frame in a column vector (note that only the first 512 FFT coefficients are needed).


(iv) Append the power spectrum vectors of all frames to form super matrix S. The size of the matrix will be 512 × no. of frames; (v) Plot the spectrogram using the following MATLAB commands



Answer



No one is going to give you a full working code - the point is that you should learn and understand how to do it. Following guidelines for you:





  1. As given, use the wavread function to load the recording (please mind that in the newest 2014a version this function is deprecated, you should use audioread instead). MATLAB has wonderful help with very good examples, so simply use it.




  2. Having your signal loaded, together with its sampling frequency, you need to split it into chunks (many short-time frames). This can be done in two ways, either you are using a loop construct (for, while - whichever you prefer), or (my favourite) use the MATLAB buffer function (please consider using 'nodelay' option in it, as first frame will have zeros in it up to overlap length). Although you require the Signal Processing Toolbox license (I'm sure your University has it). This function allows you to specify the length of frame, overlapping and other things. In result you will obtain the matrix which columns are your signal frames. Having the sampling frequency from wavread, it is very easy to calculate corresponding length of your frame in samples for given number of miliseconds




  3. Now you can iterate over the columns of your matrix and calculate the FFT for each of them. You might want to use the fft function to get it. In extra parameter you can specify the length of your signal (to apply zero padding eventually). So let's say that now you have FFT for first frame. Now take the magnitude of it (abs), and choose first 512 samples. Store this result into fist column of your super matrix $S$. Optional step: before calculating the FFT, I suggest you to multiply your frame by the window function, i.e. hamming window.




  4. Now you have the matrix $S$, so plotting can be done by using various functions (pcolor, imagesc, and so on - pick whichever you prefer).





I suggest you to compare the final result with MATLAB built-in spectrogram function.


Good luck!


No comments:

Post a Comment

digital communications - Understanding the Matched Filter

I have a question about matched filtering. Does the matched filter maximise the SNR at the moment of decision only? As far as I understand, ...