Unformatted text preview:

Handout 5 – Spectrogram modificationSPHSC 503 – Speech Signal Processing UW – Summer 2006 Handout 5 – Spectrogram modification In the previous lab session, we have used Matlab’s spectrogram function to analyze speech signals and plot spectrograms. It is ideally suited for that purpose, but it doesn’t work so well for today’s exercises. Today, we want to modify a signal’s spectrogram, and reconstruct a new signal from the modified spectrogram. However, Matlab does not have an ‘inverse spectrogram’ function that can do that job. We will therefore, in this lab, use a different set of functions that enable us to compute the spectrogram, modify it, and reconstruct a signal. These functions are called stft, istft and plotstft, (written by the instructor, not part of standard Matlab). Modifying a speech signal in the time-frequency domain The stft, istft and plotstft functions are named after the short-time Fourier transform (abbreviated as STFT). The short-time Fourier transform of a signal and the spectrogram of a signal are almost the same thing, but there is a subtle difference. The short-time Fourier transform is the transform that takes short sections of a signal, multiplies them with a window, and computes the short-term frequency spectra of those sections. As such, the short-time Fourier transform of a sequence []xn is a complex-valued, two-dimensional function of time and frequency, . The spectrogram is the (plot of the) magnitude or power of the short-time Fourier transform of a signal. (, )Xnω We will study the use of the stft, istft and plotstft functions in the following exercises. Exercise 5.1: Band-pass filter In this exercise we will apply the same band-pass filter as in Exercise 3.1 to a speech signal, to simulate the frequency response of an old telephone. This time we’ll implement the filter by modifying the short-time Fourier transform of the signal. Part 1: loading the signal and computering the short-time Fourier transform a. Download the files stft.m, istft.m, plotstft.m and 0zk.wav from the class website and save them in the folder C:\Temp\SPHSC503\. Change Matlab’s current directory to that folder. Load the speech signal and its sampling frequency from the file 0zk.wav. b. To get an idea about the speech signal, plot it and listen to it. As before, you can use the plot and soundsc functions for this, but if you just like to get a quick impression, try the following: >> soundview(y,fs) % replace y and fs by the names of your variables c. Not only can the stft function compute the short-time Fourier transform of a signal, it can also plot the spectrogram of the signal. To accomplish that, we must call stft without any output arguments: >> figure, stft(y,256,128,fs) % plot spectrogram of y in new figure >> climdb(80), colorbar % set max dynamic range, add a color bar The second argument of the stft function is specifies the window length. When the window is specified as a length, a sine window of that length is used. The window may also be – 1 –SPHSC 503 – Speech Signal Processing UW – Summer 2006 specified as a window vector, in which case the specified window sequence is used. The third parameter of the stft function is the window overlap, here set to 50%. The fourth parameter, the sampling frequency, is optional. When specified, the units on the spectrogram plot are time in seconds and frequency in Hz. Without it, the units are time in sample index and normalized frequency in radians/sample. d. To be able to modify the short-time Fourier transform of a signal, we need to store the short-time Fourier transform in a Matlab variable. This can be done as follows: >> [Y,T,F] = stft(y,256,128,fs); % compute the STFT, store in Y The short-time Fourier transform of the signal y is stored in the matrix Y. We can check the dimensions of the matrix Y in Matlab’s workspace browser window, or by typing: >> whos Y Name Size Bytes Class Y 129x390 804960 double array (complex) Grand total is 50310 elements using 804960 bytes The first dimension of the matrix, i.e., the rows of the matrix, corresponds to the frequency axis, and the second dimension, i.e. the columns of the matrix, corresponds to the time axis. So the STFT of the speech signal, using the given parameters, has 129 sample points in frequency and 390 sample points in time. The stft function returns two additional outputs, vectors T and F. Those vectors contain the times and frequencies of the time and frequency sampling points of the STFT. They are very useful when we want to modify specific time-frequency regions of the STFT. Part 2: Modifying the short-time Fourier transform e. Recall that the band-pass filter in Exercise 3.1 suppressed frequencies below 400 Hz and above 2000 Hz. To implement the same filter by modifying the short-time Fourier transform, we can do the following: >> Ymod = Y; % make a copy of the STFT >> Ymod(F<400 | F>2000, :) = 0; % set region of STFT to zero The first line in this statement simply makes a copy of the STFT to a new matrix, Ymod. The second line then selects a part of the Ymod matrix and sets it to zero. It uses logical indexing to accomplish this task. The commands in the parenthesis can be explained as follows: • The first index, F<400 | F>2000, selects certain rows from the matrix Ymod  F<400 selects rows for which the frequency sampling vector F is less than 400  F>2000 selects rows for which the frequency sampling vector F is greater than 2000  The vertical bar, |, means “or”, and combines the two selections in a single selection of all the rows that correspond to frequencies less than 400 or greater than 2000. • The second index, :, selects certain columns from the matrix Ymod. When indexing a matrix or a vector, the single colon notation, :, is short-hand for “all rows” or “all columns”. – 2 –SPHSC 503 – Speech Signal Processing UW – Summer 2006 f. Plot the modified short-time Fourier transform using the plotstft function: >> figure, plotstft(Ymod,256,128,fs) % plot modified spectrogram >> climdb(80), colorbar % set dynamic range, add color bar Does it look like a 400 Hz – 2000 Hz band-pass filter has been applied to the STFT? Part 3: reconstructing the signal g. To reconstruct a signal from the modified STFT Ymod, we use the istft function: >> ymod = istft(Ymod,256,128); %


View Full Document

UW SPHSC 503 - Spectrogram Modification

Download Spectrogram Modification
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Spectrogram Modification and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Spectrogram Modification 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?