Skip to Main Content Skip to Search
Home |   Select Country  Choose Country  |  Contact Us  |  Cart Store 
Create Account | Log In
Products & Services Industries Academia Support User Community Company

 

Newsletters - MATLAB Digest

Filter Design and Spectral Estimation Using MATLAB and the Signal Processing Toolbox

by Anne Mascarin

The following two examples demonstrate the application of MATLAB® to filter design and spectral estimation, two pillars of signal processing technology. These examples involve designing a filter and applying it to a speech signal and analyzing recorded speech data using different spectral analysis methods. In the first example, we use SPTool, the Graphical User Interface of the Signal Processing Toolbox, to view a "clean" (noise-free) signal, add bandlimited noise to it, attempt to re-create the original clean signal by designing and applying another filter to it, and evaluate the resulting (clean) signal. In the second example, we apply several spectral analysis methods to these signals and compare the results.

Example 1 : Filter Design
The Signal Processing Toolbox supports a variety of filter design methods, including impulse response (FIR) and infinite impulse response (IIR) digital filters. These methods support the rapid design and evaluation of lowpass, highpass, bandpass, bandstop, and multiband filters such as Butterworth, Chebyshev, elliptic, Yule-Walker, window-based, least-squares, and Parks-McClellan. SPTOOL, the graphical user interface (GUI) included with Signal Processing Toolbox 4.0 and later, makes experimenting with various filters and their parameters accurate, fast, and intuitive.

Using Fourier analysis, a signal can be described as a summation of frequency components. Typically, a filter is used to enhance a signal by attenuating unwanted frequency components while preserving required frequency components. In this example, we will use both the Signal Processing Toolbox command line functionality and the SPTOOL GUI. We will add bandlimited noise to a particular signal, design a filter to attenuate the noise, add the noise to the clean, original speech signal, apply the filter, and verify that the original signal can be accurately recreated. This type of filtering application is required by some speech processing algorithms as a type of pre-emphasis filter because removing unwanted noise before processing the speech signal yields more accurate results.

We begin by loading a stored speech signal into the MATLAB workspace and then into SPTool. (This speech signal, mtlb.mat, is included in all releases of MATLAB. It is a vector of size 4001 X 1 and sampling frequency 7418 Hz). At the MATLAB command line prompt, type

load mtlb
sptool

to load the speech signal and invoke SPTool. After invoking SPTool, we will load the mtlb signal into the SPTool workspace using the Import command under the File menu (Figure 1) and indicate the data signal and the sampling frequency (Fs = 7418 Hz).

Figure 1. SPTool Main Menu
Click image to enlarge

The File menu will display mtlb, the signal upon which we will operate. You can "browse" it by clicking on View to invoke the Signal Viewer (Figure 2).

Figure 2. The Signal Viewer
Click to enlarge image

The next step in the process is to create the noise signal. To do this, we use a random number generator function from the MATLAB command window to create a vector of the same dimensions as our original signal

noise = randn(4001, 1);

The noise signal can then be imported to SPTool using the same process as before. We will refer to the noise signal as noise.

The Filter Designer of SPTool can be used to create a filter that will bandlimit this noise signal. By applying a particular filter to the signal, we can retain frequencies that are within a particular region of interest and reject all others. We choose to add high-frequency noise to the signal because this is required by some speech processing specifications.

For our application, we choose an equiripple bandpass filter with the passband (range of frequencies to be retained) between 3250 and 3500 Hz (see Figure 3). With the Filter Designer, you can enter parameters into the fields manually or click and drag the mouse directly on the filter GUI itself. If you choose the click-and-drag method, the corresponding characteristics will be displayed.

Figure 3. The Filter Designer
Click to enlarge image

Once you have designed the filter, you can apply it to a signal from the SPTool menu by selecting the desired input signal and the desired filter and clicking on Apply. This creates a new bandlimited noise signal (bl_noise) that can be viewed by the Signal Viewer.

All signals that are created within the SPTool interface are available as structures from the MATLAB command line. To access the data portion of the bl_noise structure, type

noisesig = bl_noise.data;

We can now add the bandlimited noise signal, noisesig, to our original input signal (mtlb.mat) in the MATLAB workspace

totalsig = noisesig + mtlb;

Now that we have our input speech signal with bandlimited noise added to it, we can return to SPTool to create a second filter to remove the added noise and verify results. A low-pass filter that will keep the desired frequency content of all frequencies under 3000 Hz (Figure 4) must be constructed and applied to totalsig.

Figure 4. A Lowpass Equiripple Filter
Click to enlarge image

After applying the filter and creating a cleaned, processed signal (cleansig), we can examine this signal and compare it to the original in the Signal Browser (see Figure 5.). In addition to a visual comparison, we can also use the Play command from the Signal Browser Option menu to hear the differences. The results: although the two signals are very close in magnitude, the blue (processed) signal lags slightly behind the red original input signal. This is to be expected, as the filtering process has introduced some time delay into the processed signal.

Figure 5. mtlb, the Original Signal, Is Blue; cleansig, the Processed Signal, Is Red
Click to enlarge image

Example 2 : Spectral Estimation Methods
Spectral estimation seeks to describe the frequency content (power or energy) of signals that vary randomly, or non-deterministically. The Signal Processing Toolbox provides sophisticated tools for spectral estimation, including the classical methods, the Power Spectral Density and Cross Spectral Density methods, and several contemporary methods, such as the Multitaper, Yule Walker AR, and MUSIC (MUltiple SIgnal Classification) methods.

Spectral estimation methods are either parametric or non-parametric. Parametric modeling techniques find the parameters for a mathematical model describing a signal, system, or process. These techniques use known information about the system to determine the model. Non-parametric techniques"assess" the actual data but do not attempt to fit it to a model of any kind. Welch's method, the MultiTaper Method, and the MUSIC method are the non-parametric spectral analysis methods available in the Signal Processing Toolbox. The parametric Yule-Walker AR method is also available. We will examine both Welch's method and the Yule-Walker method in this example.

We can apply spectral estimation techniques to the mtlb.mat signal discussed in Example 1 using both the MATLAB command window and the Spectrum Viewer of SPTool. Starting once again with the "mtlb.mat" signal, we can define a new vector "vowel_a" that contains only the "a" sound of the spoken word "MATLAB" by storing part of the "mtlb.mat" vector into another vector

vowel_a = mtlb(1000:1500);

We can apply the Yule-Walker autoregressive parametric method to the data with the following commands from the MATLAB command line

  [Pxx, freq] = pyulear(vowel_a, 10, 1024, 7498);
plot(freq, 10*log10(Pxx));

where the parameters for the pyulear command are the input vector (vowel_a), the order of the all-pole filter (10), the size of the FFT (1024), and the sampling frequency of the signal (7498).

The results are shown in Figure 6. Note that the curve is relatively smooth because of the relatively simple underlying all-pole (autoregressive) model.

Figure 6. Yule-Walker AR Spectral Analysis Method Applied to the "a" Vowel in "MATLAB"
Click to enlarge image

For comparison, we can apply Welch's method to the same data, but for purposes of demonstration, we will use SPTool. After invoking SPTool and importing the data, we can create a spectrum by highlighting a particular signal and clicking on Create under the Spectra menu. This will generate a new spectrum (the name of which will be highlighted). To view the spectrum, click on View, which invokes the Spectrum Viewer. By choosing Welch in the Method field and then pressing the Apply button causes the spectrum created using Welch's method to appear. Figure 7 shows Welch's method applied to our input signal.

Figure 7. Welch's Method of Spectral Analysis Method Applied to the Vowel "a" in "MATLAB" Click to enlarge image

Notice that the sinusoid "formant" frequency of the speech is much more evident when we use Welch's non-parametric method.

Contact sales
E-mail this page
Print this page
Subscribe to newsletters