Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống
1
/ 40 trang
THÔNG TIN TÀI LIỆU
Thông tin cơ bản
Định dạng
Số trang
40
Dung lượng
7,68 MB
Nội dung
Wavelet Analysis 201 F IGURE 7.9 Application of the dyadic wavelet transform to nonlinear filtering. After subband decomposition using an analysis filter bank, a threshold process is applied to the two highest resolution highpass subbands before reconstruction using a synthesis filter bank. Periodic convolution was used so that there is no phase shift between the input and output signals. an = analyze1(x,h0,4); % Decompose signal, analytic % filter bank of level 4 % Set the threshold times to equal the variance of the two higher % resolution highpass subbands. threshold = var(an(N/4:N)); for i = (N/4:N) % Examine the two highest % resolution highpass % subbands if an(i) < threshold an(i) = 0; end end sy = synthesize1(an,h0,4); % Reconstruct original % signal figure(fig2); plot(t,x,’k’,t,sy-5,’k’); % Plot signals axis([ 2 1.2-8 4]); xlabel(’Time(sec)’) TLFeBOOK 202 Chapter 7 The routines for the analysis and synthesis filter banks differ slightly from those used in Example 7.3 in that they use circular convolution. In the analysis filter bank routine ( analysis1 ), the data are first extended using the periodic or wraparound approach: the initial points are added to the end of the original data sequence (see Figure 2.10B). This extension is the same length as the filter. After convolution, these added points and the extra points generated by convolution are removed in a symmetrical fashion: a number of points equal to the filter length are removed from the initial portion of the output and the re- maining extra points are taken off the end. Only the code that is different from that shown in Example 7.3 is shown below. In this code, symmetric elimination of the additional points and downsampling are done in the same instruction. function an = analyze1(x,h0,L) for i = 1:L a_ext = [an an(1:lf)]; % Extend data for “periodic % convolution” lpf = conv(a_ext,h0); % Lowpass FIR filter hpf = conv(a_ext,h1); % Highpass FIR filter lpfd = lpf(lf:2:lf؉lx-1); % Remove extra points. Shift to hpfd = hpf(lf:2:lf؉lx-1); % obtain circular segment; then % downsample an(1:lx) = [lpfd hpfd]; % Lowpass output at beginning of % array, but now occupies only % half the data points as last % pass lx = lx/2; The synthesis filter bank routine is modified in a similar fashion except that the initial portion of the data is extended, also in wraparound fashion (by adding the end points to the beginning). The extended segments are then upsam- pled, convolved with the filters, and added together. The extra points are then removed in the same manner used in the analysis routine. Again, only the modi- fied code is shown below. function y = synthesize1(an,h0,L) for i = 1:L lpx = y(1:lseg); % Get lowpass segment hpx = y(lseg؉1:2*lseg); % Get highpass outputs lpx = [lpx(lseg-lf/2؉1:lseg) lpx]; % Circular extension: % lowpass comp. hpx = [hpx(lseg-lf/2؉1:lseg) hpx]; % and highpass component l_ext = length(lpx); TLFeBOOK Wavelet Analysis 203 up_lpx = zeros(1,2*l_ext); % Initialize vector for % upsampling up_lpx(1:2:2*l_ext) = lpx; % Up sample lowpass (every % odd point) up_hpx = zeros(1,2*l_ext); % Repeat for highpass up_hpx(1:2:2*l_ext) = hpx; syn = conv(up_lpx,g0) ؉ conv(up_hpx,g1); % Filter and % combine y(1:2*lseg) = syn(lf؉1:(2*lseg)؉lf); % Remove extra % points lseg = lseg * 2; % Double segment lengths % for next pass end The original and reconstructed waveforms are shown in Figure 7.9. The filtering produced by thresholding the highpass subbands is evident. Also there is no phase shift between the original and reconstructed signal due to the use of periodic convolution, although a small artifact is seen at the beginning and end of the data set. This is because the data set was not really periodic. Discontinuity Detection Wavelet analysis based on filter bank decomposition is particularly useful for detecting small discontinuities in a waveform. This feature is also useful in image processing. Example 7.5 shows the sensitivity of this method for detect- ing small changes, even when they are in the higher derivatives. Example 7.5 Construct a waveform consisting of 2 sinusoids, then add a small (approximately 1% of the amplitude) offset to this waveform. Create a new waveform by double integrating the waveform so that the offset is in the second derivative of this new signal. Apply a three-level analysis filter bank. Examine the high frequency subband for evidence of the discontinuity. % Example 7.5 and Figures 7.10 and 7.11. Discontinuity detection % Construct a waveform of 2 sinusoids with a discontinuity % in the second derivative % Decompose the waveform into 3 levels to detect the % discontinuity. % Use Daubechies 4-element filter % close all; clear all; fig1 = figure(’Units’,’inches’,’Position’,[0 2.5 3 3.5]); fig2 = figure(’Units’, ’inches’,’Position’,[3 2.5 5 5]); fs = 1000; % Sample frequency TLFeBOOK 204 Chapter 7 F IGURE 7.10 Waveform composed of two sine waves with an offset discontinuity in its second derivative at 0.5 sec. Note that the discontinuity is not apparent in the waveform. N = 1024; % Number of points in % waveform freqsin = [.23 .8 1.8]; % Sinusoidal frequencies ampl = [1.2 1 .7]; % Amplitude of sinusoid incr = .01; % Size of second derivative % discontinuity offset = [zeros(1,N/2) ones(1,N/2)]; h0 = daub(4) % Daubechies 4 % [x1 t] = signal(freqsin,ampl,N); % Construct signal x1 = x1 ؉ offset*incr; % Add discontinuity at % midpoint x = integrate(integrate(x1)); % Double integrate figure(fig1); plot(t,x,’k’,t,offset-2.2,’k’); % Plot new signal axis([0 1-2.5 2.5]); xlabel(’Time (sec)’); TLFeBOOK Wavelet Analysis 205 F IGURE 7.11 Analysis filter bank output of the signal shown in Figure 7.10. Al- though the discontinuity is not visible in the original signal, its presence and loca- tion are clearly identified as a spike in the highpass subbands. TLFeBOOK 206 Chapter 7 figure(fig2); a = analyze(x,h0,3); % Decompose signal, analytic % filter bank of level 3 Figure 7.10 shows the waveform with a discontinuity in its second deriva- tive at 0.5 sec. The lower trace indicates the position of the discontinuity. Note that the discontinuity is not visible in the waveform. The output of the three-level analysis filter bank using the Daubechies 4- element filter is shown in Figure 7.11. The position of the discontinuity is clearly visible as a spike in the highpass subbands. Feature Detection: Wavelet Packets The DWT can also be used to construct useful descriptors of a waveform. Since the DWT is a bilateral transform, all of the information in the original waveform must be contained in the subband signals. These subband signals, or some aspect of the subband signals such as their energy over a given time period, could provide a succinct description of some important aspect of the original signal. In the decompositions described above, only the lowpass filter subband signals were sent on for further decomposition, giving rise to the filter bank structure shown in the upper half of Figure 7.12. This decomposition structure is also known as a logarithmic tree. However, other decomposition structures are valid, including the complete or balanced tree structure shown in the lower half of Figure 7.12. In this decomposition scheme, both highpass and lowpass subbands are further decomposed into highpass and lowpass subbands up till the terminal signals. Other, more general, tree structures are possible where a decision on further decomposition (whether or not to split a subband signal) depends on the activity of a given subband. The scaling functions and wavelets associated with such general tree structures are known as wavelet packets. Example 7.6 Apply balanced tree decomposition to the waveform con- sisting of a mixture of three equal amplitude sinusoids of 1 10 and 100 Hz. The main routine in this example is similar to that used in Examples 7.3 and 7.4 except that it calls the balanced tree decomposition routine, w_packet , and plots out the terminal waveforms. The w_packet routine is shown below and is used in this example to implement a 3-level decomposition, as illustrated in the lower half of Figure 7.12. This will lead to 8 output segments that are stored sequen- tially in the output vector, a . % Example 7.5 and Figure 7.13 % Example of “Balanced Tree Decomposition” % Construct a waveform of 4 sinusoids plus noise % Decompose the waveform in 3 levels, plot outputs at the terminal % level TLFeBOOK Wavelet Analysis 207 F IGURE 7.12 Structure of the analysis filter bank (wavelet tree) used in the DWT in which only the lowpass subbands are further decomposed and a more general structure in which all nonterminal signals are decomposed into highpass and low- pass subbands. % Use a Daubechies 10 element filter % clear all; close all; fig1 = figure(’Units’,’inches’,’Position’,[0 2.5 3 3.5]); fig2 = figure(’Units’, ’inches’,’Position’,[3 2.5 5 4]); fs = 1000; % Sample frequency N = 1024; % Number of points in % waveform levels = 3 % Number of decomposition % levels nu_seg = 2vlevels; % Number of decomposed % segments freqsin = [1 10 100]; % Sinusoid frequencies TLFeBOOK 208 Chapter 7 F IGURE 7.13 Balanced tree decomposition of the waveform shown in Figure 7.8. The signal from the upper left plot has been lowpass filtered 3 times and repre- sents the lowest terminal signal in Figure 7.11. The upper right has been lowpass filtered twice then highpass filtered, and represents the second from the lowest terminal signal in Figure 7.11. The rest of the plots follow sequentially. TLFeBOOK Wavelet Analysis 209 ampl = [1 1 1]; % Amplitude of sinusoid h0 = daub(10); % Get filter coefficients: % Daubechies 10 % [x t] = signal(freqsin,ampl,N); % Construct signal a = w_packet(x,h0,levels); % Decompose signal, Balanced % Tree for i = 1:nu_seg i_s = 1 ؉ (N/nu_seg) * (i-1); % Location for this segment a_p = a(i_s:i_s؉(N/nu_seg)-1); subplot(nu_seg/2,2,i); % Plot decompositions plot((1:N/nu_seg),a_p,’k’); xlabel(’Time (sec)’); end The balanced tree decomposition routine, w_packet , operates similarly to the DWT analysis filter banks, except for the filter structure. At each level, signals from the previous level are isolated, filtered (using standard convolu- tion), downsampled, and both the high- and lowpass signals overwrite the single signal from the previous level. At the first level, the input waveform is replaced by the filtered, downsampled high- and lowpass signals. At the second level, the two high- and lowpass signals are each replaced by filtered, downsampled high- and lowpass signals. After the second level there are now four sequential signals in the original data array, and after the third level there be will be eight. % Function to generate a “balanced tree” filter bank % All arguments are the same as in routine ‘analyze’ %an = w_packet(x,h,L) % where %x= input waveform (must be longer than 2vL ؉ L and power of % two) %h0= filter coefficients (low pass) %L= decomposition level (number of High pass filter in bank) % function an = w_packet(x,h0,L) lf = length(h0); % Filter length lx = length(x); % Data length an = x; % Initialize output % Calculate High pass coefficients from low pass coefficients for i = 0:(lf-1) h1(i؉1) = (-1)vi * h0(lf-i); % Uses Eq. (18) end % Calculate filter outputs for all levels for i = 1:L TLFeBOOK 210 Chapter 7 nu_low = 2v(i-1); % Number of lowpass filters % at this level l_seg = lx/2v(i-1); % Length of each data seg. at % this level for j = 1:nu_low; i_start = 1 ؉ l_seg * (j-1); % Location for current % segment a_seg = an(i_start:i_start؉l_seg-1); lpf = conv(a_seg,h0); % Lowpass filter hpf = conv(a_seg,h1); % Highpass filter lpf = lpf(1:2:l_seg); % Downsample hpf = hpf(1:2:l_seg); an(i_start:i_start؉l_seg-1) = [lpf hpf]; end end The output produced by this decomposition is shown in Figure 7.13. The filter bank outputs emphasize various components of the three-sine mixture. Another example is given in Problem 7 using a chirp signal. One of the most popular applications of the dyadic wavelet transform is in data compression, particularly of images. However, since this application is not so often used in biomedical engineering (although there are some applica- tions regrading the transmission of radiographic images), it will not be covered here. PROBLEMS 1. (A) Plot the frequency characteristics (magnitude and phase) of the Mexi- can hat and Morlet wavelets. (B) The plot of the phase characteristics will be incorrect due to phase wrapping. Phase wrapping is due to the fact that the arctan function can never be greater that ± 2π; hence, once the phase shift exceeds ± 2π (usually minus), it warps around and appears as positive. Replot the phase after correcting for this wrap- around effect. (Hint: Check for discontinuities above a certain amount, and when that amount is exceeded, subtract 2π from the rest of the data array. This is a simple algorithm that is generally satisfactory in linear systems analysis.) 2. Apply the continuous wavelet analysis used in Example 7.1 to analyze a chirp signal running between 2 and 30 Hz over a 2 sec period. Assume a sample rate of 500 Hz as in Example 7.1. Use the Mexican hat wavelet. Show both contour and 3-D plot. 3. Plot the frequency characteristics (magnitude and phase) of the Haar and Daubechies 4-and 10-element filters. Assume a sample frequency of 100 Hz. TLFeBOOK [...]... adaptive filter to eliminate broadband noise from a % narrowband signal % % Generate signal and noise close all; clear all; fs = 1000; % Sampling frequency FIGURE 8.9 Adaptive line enhancer applied to a signal consisting of two sequential sinusoids having different frequencies (10 and 20 Hz) The delay of 5 samples and the convergence gain of 0. 075 were determined by trial and error to give the best results... match in spectral characteristics between the “unknown” process and the matching output produced by the Wiener-Hopf algorithm The transfer functions also closely match as seen by the similarity in impulse response coefficients: h(n)unknown = [0.5 0 .75 1.2]; h(n)match = [0.503 0 .75 7 1.216] ADAPTIVE SIGNAL PROCESSING The area of adaptive signal processing is relatively new yet already has a rich history... coefficients are adjusted and applied in an ongoing basis While the Wiener-Hopf equations (Eqs (6) and (7) ) can be, and have been, adapted for use in an adaptive environment, a simpler and more popular approach is based on gradient optimization This approach is usually called the LMS recursive algorithm As in Wiener filter theory, this algorithm also determines the optimal filter coefficients, and it is also... signal Many of these applications are explored in the next section on MATLAB implementation and/ or in the problems The configuration for ALE and adaptive interference suppression is shown in Figure 8.6 When this configuration is used in adaptive interference suppression, the input consists of a broadband signal, Bb(n), in narrowband noise, Nb(n), such as 60 Hz Since the noise is narrowband compared to the... equation through matrix inversion: RB = rdx and the solution is: b = R−1rdx (7) The application and solution of this equation are given for two different examples in the following section on MATLAB implementation The Wiener-Hopf approach has a number of other applications in addition to standard filtering including systems identification, interference canceling, and inverse modeling or deconvolution For... coefficients were adjusted to approximate a bandpass filter with a small bandwidth and a peak at 10 Hz TLFeBOOK Advanced Signal Processing 219 N = 1024; % Number of points L = 256; % Optimal filter order % % Generate signal and noise data: 10 Hz sin in 8 db noise (SNR = % -8 db) [xn, t, x] = sig_noise(10,-8,N); % xn is signal ؉ noise and % x is noise free (i.e., % desired) signal subplot(3,1,1); plot(t,... the FIR filter and Px is the power in the input signal PX can be approximated by: Px Ϸ 1 N−1 N ∑ x (n) 2 (13) n=1 Note that for a waveform of zero mean, Px equals the variance of x The LMS algorithm given in Eq (11) can easily be implemented in MATLAB, as shown in the next section Adaptive filtering has a number of applications in biosignal processing It can be used to suppress a narrowband noise source... source such as 60 Hz that is corrupting a broadband signal It can also be used in the reverse situation, removing broadband noise from a narrowband signal, a process known as adaptive line TLFeBOOK Advanced Signal Processing 225 FIGURE 8.6 Configuration for Adaptive Line Enhancement (ALE) or Adaptive Interference Suppression The Delay, D, decorrelates the narrowband component allowing the adaptive filter... allowing the adaptive filter to use only this component In ALE the narrowband component is the signal while in Interference suppression it is the noise enhancement (ALE).* It can also be used for some of the same applications as the Wiener filter such as system identification, inverse modeling, and, especially important in biosignal processing, adaptive noise cancellation This last application requires...Wavelet Analysis 211 4 Generate a Daubechies 10-element filter and plot the magnitude spectrum as in Problem 3 Construct the highpass filter using the alternating flip algorithm (Eq (20)) and plot its magnitude spectrum Generate the lowpass and highpass synthesis filter coefficients using the order flip algorithm (Eqs (23) and (24)) and plot their respective frequency characteristics Assume a sampling . three-level analysis filter bank. Examine the high frequency subband for evidence of the discontinuity. % Example 7. 5 and Figures 7. 10 and 7. 11. Discontinuity detection % Construct a waveform of 2 sinusoids. shown in the lower half of Figure 7. 12. In this decomposition scheme, both highpass and lowpass subbands are further decomposed into highpass and lowpass subbands up till the terminal signals sinusoids of 1 10 and 100 Hz. The main routine in this example is similar to that used in Examples 7. 3 and 7. 4 except that it calls the balanced tree decomposition routine, w_packet , and plots out