EE513 Audio Signals and Systems Wiener Inverse Filter Kevin D. Donohue Electrical and Computer Engineering University of Kentucky Weiner Filters A class of filters, referred to as Wiener filters, exploit correlation information between signal and noise to enhance SNR or reduce distortion. The Wiener filter is the optimal filter for enhancing SNR of a random signal in random noise. Signals and noise are characterized by their PSDs or ACs, and objective metrics are either SNR enhancement or minimization of least-square error. These filters are named after Norbert Weiner: http://en.wikipedia.org/wiki/Norbert_Wiener Wiener Filters and Noise Let s[n] be the original signal and y[n] be the corrupted version. The error signal or noise is given by: [n] y[n] s[n] Minimizing the error in the L2 or mean square error (MSE) sense means minimizing the expected value of: E [n] E y[n] s[n] 2 2 This is equivalent to maximizing the SNR: E [ n] 2 E s[n] 2 E y[n] s[n] 2 E s[n] 2 Signal Power E 2 [ n] Noise Power Wiener Filter Objective Let w[n] be the filter to maximize SNR or equivalently to minimize the MSE: ~ y [ n] y[m]w[n m] s[m] [m]w[n m] m m Express MSE in terms of the above equation: 2 ~ E y[n] s[n ] E s[m] [m]w[n m] s[n ] m where is a delay parameter to relax a causality constraint and 2 typically improve performance. The first equation can be expressed more directly in the frequency domain: ~ˆ ˆ [k ] Wˆ [k ] Y [k ] Sˆ[k ] Wiener Filter and SNR Assuming the signal and noise are uncorrelated, zero-mean stationary processes, it can be shown that the optimal filter for minimizing MSE is: 2 ˆ E S[k ] Wˆ [k ] 2 2 ˆ ˆ E [k ] E S[k ] PSD of Noise PSD of Signal Can also be rewritten as: Wˆ [k ] 1 2 ˆ E [k ] 1 2 E Sˆ[k ] 1 1 1 SNR[ k ] Homework 1 Download mat file (wienerhw1.mat) from: http://www.engr.uky.edu/~donohue/ee513/data/wienerhw1.mat It will contain the signal vectors described below with associated sampling frequency fs. Examples of the signal and noise processes are stored in vectors sig and nos with normalized power. A) Plot the spectral magnitude of the Wiener filter for a signal plus noise process assuming a signal-to-noise ratio of -15 dB, 0 dB, and 15 dB. Describe how the SNR changes the spectral shape of the filter. Describe how this change makes sense for an optimal filter for this type. Hand in commented code and a clearly labeled plot, and the requested descriptions. B) Apply a Wiener filter to the data in vector sigpnos, which is a combination of the signal and noise from the same source as the examples. Note that you do not know the SNR for this case. Since you know the PSD shapes you can try to assess the SNR by examining the PSDs or ACs of combined signal. Also assume that the SNR is between 25 and 0 dB and create a loop to increment through various levels of SNR and listen to or test the result to determine at what level the best performance. Hand in the commented code used to filter and test the signal and determine the best SNR for the filter design. Clearly indicate the SNR you thought was the best. FIR Inverse (Wiener) Filters An inverse filter undoes distortions due to frequency selective channels/systems and restore the original transmitted/driving signal. This type of filtering is sometimes referred to as deconvolution. Let h(n) denote the impulse response of the channel/system. The inverse filter, hI(n), is described by: h(n) * hI (n) (n) Hˆ ( z ) Hˆ ( z ) 1 I FIR Inverse Filters - Polynomial Division Assume that for practical purposes the channel/system can be modeled as an all-pole system, therefore the inverse filter is an all-zero system. A direct way of obtaining the impulse response of the inverse filter, hI(n), is to expand rational polynomial Hˆ ( z ) through long division and truncate the sequence after M+1 coefficients: M 1 k k H I (z) hI (k )z bk z bk z k H ( z ) k 0 k 0 k M 1 The resulting error becomes: E bI2 (n) 2 n M 1 FIR Inverse Filters – Least Squares Another design can be obtained via a least-squares approach: h(n) FIR Filter {b k} - d ( n) ( n) e(n) { bk} Minimize Sum of Squared Errors where d(n) is the desired response and the error of the filter output is e(n). The error and overall squared error E2 are given by: 2 M e(n) d (n) bk h(n k ) k 0 M E d (n) bk h(n k ) n 0 k 1 2 FIR Inverse Weiner Filter After minimizing E2 (take the derivatives with respect to each bk and set the result to zero), it can be shown that the optimal set of {bk}’s are the solution to the M equations given by: M bk rhh (k l ) rdh (l ) k 1 l 0,1,2, M where rhh(.) is the autocorrelation for h(n), and rdh(.) is the cross-correlation between h(n) and d(n): rhh (l ) h(n)h(n l ) n0 rdh (l ) d (n)h(n l ) n0 FIR Inverse Filters – Least Squares For the special case where d(n) = (n): h(0) rdh (l ) 0 for l = 0 otherwise Therefore, the following system of equations can be used to solve for the filter coefficients: rhh (1) rhh ( M ) b0 h(0) rhh (0) r (1) b 0 rhh (0) hh 1 r ( M ) r ( M 1) r (0) b 0 hh M hh hh Matrix is Symmetric and Toeplitz, can use LevensonDurbin algorithm to solve Example Given desired response (original input to the system) d(n) and the actual response of system h(n) up to length N, design an Mth order FIR (Wiener) inverse filter. Create the following vector and matrix: d d (0) d (1) d ( N ) T 0 h( 0 ) h(1) h( 0 ) h( M 1) H h( M ) h( M 1) h( M 2) h( N ) h( N 1) h( N M ) 0 0 0 h( 0 ) h(1) Then compute desired filter coefficients by solving the following matrix equation for b: H T Hb H Td where b b0 b1 bM T Example Then test for stability (was original system minimum phase?), apply h(n) (plus a little noise, less than -3 dB) to the inverse filter. If the result is anomalous (not close to the signal of interest), add a delay to the desired response and repeat (i.e. use): d 0 ....0 d (0) d (1) d ( N 1) T Insert 0’s to delay desired response. This provides the filter with more degrees of freedom to undo the system response at the expense of delaying the output. Increasing filter order can also improve performance.