Biosignal and Biomedical Image Processing phần 6 pptx

44 262 0
Biosignal and Biomedical Image Processing phần 6 pptx

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

Wavelet Analysis 193 theoretically and practically. It is possible, at least in theory, to go between the two approaches to develop the wavelet and scaling function from the filter coefficients and vice versa. In fact, the coefficients c(n) and d(n) in Eqs. (14 ) and (15) are simply scaled versions of the filter coefficients: c(n) = √ 2 h 0 (n); d(n) = √ 2 h 1 (n) (25) With the substitution of c(n) in Eq. (14), the equation for the scaling function (the dilation equation) becomes: φ(t) = ∑ ∞ n=−∞ 2 h 0 (n)φ(2t − n) (26) Since this is an equation with two time scales (t and 2t), it is not easy to solve, but a number of approximation approaches have been worked out (Strang and Nguyen, 1997, pp. 186–204). A number of techniques exist for solving for φ(t) in Eq. (26) given the filter coefficients, h 1 (n). Perhaps the most straightfor- ward method of solving for φ in Eq. (26) is to use the frequency domain repre- sentation. Taking the Fourier transform of both sides of Eq. (26) gives: Φ(ω) = H 0 ͩ ω 2 ͪ Φ ͩ ω 2 ͪ (27) Note that 2t goes to ω/2 in the frequency domain. The second term in Eq. (27) can be broken down into H 0 (ω/4) Φ(ω/4), so it is possible to rewrite the equation as shown below. Φ(ω) = H 0 ͩ ω 2 ͪͫ H 0 ͩ ω 4 ͪ Φ ͩ ω 4 ͪ ͬ (28) = H 0 ͩ ω 2 ͪ H 0 ͩ ω 4 ͪ H 0 ͩ ω 8 ͪ H 0 ͩ ω 2 N ͪ Φ ͩ ω 2 N ͪ (29) In the limit as N →∞, Eq. (29) becomes: Φ(ω) = J ∞ j=1 H 0 ͩ ω 2 j ͪ (30) The relationship between φ(t) and the lowpass filter coefficients can now be obtained by taking the inverse Fourier transform of Eq. (30). Once the scaling function is determined, the wavelet function can be obtained directly from Eq. (16) with 2h 1 (n) substituted for d(n): ψ(t) = ∑ ∞ n=−∞ 2 h 1 (n)φ(2t − n) (31) TLFeBOOK 194 Chapter 7 Eq. (30) also demonstrates another constraint on the lowpass filter coeffi- cients, h 0 (n), not mentioned above. In order for the infinite product to converge (or any infinite product for that matter), H 0 (ω/2 j ) must approach 1 as j →∞. This implies that H 0 (0) = 1, a criterion that is easy to meet with a lowpass filter. While Eq. (31) provides an explicit formula for determining the scaling function from the filter coefficients, an analytical solution is challenging except for very simple filters such as the two-coefficient Haar filter. Solving this equation nu- merically also has problems due to the short data length ( H 0 (ω) would be only 4 points for a 4-element filter). Nonetheless, the equation provides a theoretical link between the filter bank and DWT methodologies. These issues described above, along with some applications of wavelet analysis, are presented in the next section on implementation. MATLAB Implementation The construction of a filter bank in MATLAB can be achieved using either routines from the Signal Processing Toolbox, filter or filtfilt , or simply convolution. All examples below use convolution. Convolution does not con- serve the length of the original waveform: the MATLAB conv produces an output with a length equal to the data length plus the filter length minus one. Thus with a 4-element filter the output of the convolution process would be 3 samples longer than the input. In this example, the extra points are removed by simple truncation. In Example 7.4, circular or periodic convolution is used to eliminate phase shift. Removal of the extraneous points is followed by down- sampling, although these two operations could be done in a single step, as shown in Example 7.4. The main program shown below makes use of 3 important subfunctions. The routine daub is available on the disk and supplies the coefficients of a Daubechies filter using a simple list of coefficients. In this example, a 6-element filter is used, but the routine can also generate coefficients of 4-, 8 -, and 10- element Daubechies filters. The waveform is made up of 4 sine waves of different frequencies with added noise. This waveform is decomposed into 4 subbands using the routine analysis . The subband signals are plotted and then used to reconstruct the original signal in the routine synthesize . Since no operation is performed on the subband signals, the reconstructed signal should match the original except for a phase shift. Example 7.3 Construct an analysis filter bank containing L decomposi- tions; that is, a lowpass filter and L highpass filters. Decompose a signal consist- ing of 4 sinusoids in noise and the recover this signal using an L -level syntheses filter bank. TLFeBOOK Wavelet Analysis 195 % Example 7.3 and Figures 7.7 and 7.8 % Dyadic wavelet transform example % Construct a waveform of 4 sinusoids plus noise % Decompose the waveform in 4 levels, plot each level, then % reconstruct % Use a Daubechies 6-element filter % clear all; close all; % fs = 1000; % Sample frequency N = 1024; % Number of points in % waveform freqsin = [.63 1.1 2.7 5.6]; % Sinusoid frequencies % for mix ampl = [1.2 1 1.2 .75 ]; % Amplitude of sinusoid h0 = daub(6); % Get filter coeffi- % cients: Daubechies 6 F IGURE 7.7 Input (middle) waveform to the four-level analysis and synthesis filter banks used in Example 7.3. The lower waveform is the reconstructed output from the synthesis filters. Note the phase shift due to the causal filters. The upper waveform is the original signal before the noise was added. TLFeBOOK 196 Chapter 7 F IGURE 7.8 Signals generated by the analysis filter bank used in Example 7.3 with the top-most plot showing the outputs of the first set of filters with the finest resolution, the next from the top showing the outputs of the second set of set of filters, etc. Only the lowest (i.e., smoothest) lowpass subband signal is included in the output of the filter bank; the rest are used only in the determination of highpass subbands. The lowest plots show the frequency characteristics of the high- and lowpass filters. % [x t] = signal(freqsin,ampl,N); % Construct signal x1 = x ؉ (.25 * randn(1,N)); % Add noise an = analyze(x1,h0,4); % Decompose signal, % analytic filter bank sy = synthesize(an,h0,4); % Reconstruct original % signal figure(fig1); plot(t,x,’k’,t,x1–4,’k’,t,sy-8,’k’);% Plot signals separated TLFeBOOK Wavelet Analysis 197 This program uses the function signal to generate the mixtures of sinu- soids. This routine is similar to sig_noise except that it generates only mix- tures of sine waves without the noise. The first argument specifies the frequency of the sines and the third argument specifies the number of points in the wave- form just as in sig_noise . The second argument specifies the amplitudes of the sinusoids, not the SNR as in sig_noise . The analysis function shown below implements the analysis filter bank. This routine first generates the highpass filter coefficients, h1 , from the lowpass filter coefficients, h , using the alternating flip algorithm of Eq. (20). These FIR filters are then applied using standard convolution. All of the various subband signals required for reconstruction are placed in a single output array, an . The length of an is the same as the length of the input, N = 1024 in this example. The only lowpass signal needed for reconstruction is the smoothest lowpass subband (i.e., final lowpass signal in the lowpass chain ), and this signal is placed in the first data segment of an taking up the first N /16 data points. This signal is followed by the last stage highpass subband which is of equal length. The next N /8 data points contain the second to last highpass subband followed, in turn, by the other subband signals up to the final, highest resolution highpass subband which takes up all of the second half of an . The remainder of the analyze routine calculates and plots the high- and lowpass filter frequency characteristics. % Function to calculate analyze filter bank %an = analyze(x,h,L) % where %x= input waveform in column form which must be longer than %2vL ؉ L and power of two. %h0= filter coefficients (lowpass) %L= decomposition level (number of highpass filter in bank) % function an = analyze(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); % Alternating flip, Eq. (20) end % % Calculate filter outputs for all levels for i = 1:L a_ext = an; TLFeBOOK 198 Chapter 7 lpf = conv(a_ext,h0); % Lowpass FIR filter hpf = conv(a_ext,h1); % Highpass FIR filter lpf = lpf(1:lx); % Remove extra points hpf = hpf(1:lx); lpfd = lpf(1:2:end); % Downsample hpfd = hpf(1:2:end); an(1:lx) = [lpfd hpfd]; % Low pass output at beginning % of array, but now occupies % only half the data % points as last pass lx = lx/2; subplot(L؉1,2,2*i-1); % Plot both filter outputs plot(an(1:lx)); % Lowpass output if i == 1 title(’Low Pass Outputs’); % Titles end subplot(L؉1,2,2*i); plot(an(lx؉1:2*lx)); % Highpass output if i == 1 title(’High Pass Outputs’) end end % HPF = abs(fft(h1,256)); % Calculate and plot filter LPF = abs(fft(h0,256)); % transfer fun of high- and % lowpass filters freq = (1:128)* 1000/256; % Assume fs = 1000 Hz subplot(L؉1,2,2*i؉1); plot(freq, LPF(1:128)); % Plot from 0 to fs/2 Hz text(1,1.7,’Low Pass Filter’); xlabel(’Frequency (Hz.)’)’ subplot(L؉1,2,2*i؉2); plot(freq, HPF(1:128)); text(1,1.7,’High Pass Filter’); xlabel(’Frequency (Hz.)’)’ The original data are reconstructed from the analyze filter bank signals in the program synthesize . This program first constructs the synthesis lowpass filter, g0 , using order flip applied to the analysis lowpass filter coefficients (Eq. (23)). The analysis highpass filter is constructed using the alternating flip algorithm (Eq. (20)). These coefficients are then used to construct the synthesis highpass filter coefficients through order flip (Eq. (24)). The synthesis filter loop begins with the course signals first, those in the initial data segments of a with the shortest segment lengths. The lowpass and highpass signals are upsam- pled, then filtered using convolution, the additional points removed, and the signals added together. This loop is structured so that on the next pass the TLFeBOOK Wavelet Analysis 199 recently combined segment is itself combined with the next higher resolution highpass signal. This iterative process continues until all of the highpass signals are included in the sum. % Function to calculate synthesize filter bank %y = synthesize(a,h0,L) % where %a= analyze filter bank outputs (produced by analyze) %h= filter coefficients (lowpass) %L= decomposition level (number of highpass filters in bank) % function y = synthesize(a,h0,L) lf = length(h0); % Filter length lx = length(a); % Data length lseg = lx/(2vL); % Length of first low- and % highpass segments y = a; % Initialize output g0 = h0(lf:-1:1); % Lowpass coefficients using % order flip, Eq. (23) % Calculate High pass coefficients, h1(n), from lowpass % coefficients use Alternating flip Eq. (20) for i = 0:(lf-1) h1(i؉1) = (-1)vi * h0(lf-i); end g1 = h1(lf:-1:1); % Highpass filter coeffi- % cients using order % flip, Eq. (24) % Calculate filter outputs for all levels for i = 1:L lpx = y(1:lseg); % Get lowpass segment hpx = y(lseg؉1:2*lseg); % Get highpass outputs up_lpx = zeros(1,2*lseg); % Initialize for upsampling up_lpx(1:2:2*lseg) = lpx; % Upsample lowpass (every % odd point) up_hpx = zeros(1,2*lseg); % Repeat for highpass up_hpx(1:2:2*lseg) = hpx; syn = conv(up_lpx,g0) ؉ conv(up_hpx,g1); % Filter and % combine y(1:2*lseg) = syn(1:(2*lseg)); % Remove extra points from % end lseg = lseg * 2; % Double segment lengths for % next pass end The subband signals are shown in Figure 7.8. Also shown are the fre- quency characteristics of the Daubechies high- and lowpass filters. The input TLFeBOOK 200 Chapter 7 and reconstructed output waveforms are shown in Figure 7.7. The original signal before the noise was added is included. Note that the reconstructed waveform closely matches the input except for the phase lag introduced by the filters. As shown in the next example, this phase lag can be eliminated by using circular or periodic convolution, but this will also introduce some artifact. Denoising Example 7.3 was not particularly practical since the reconstructed signal was the same as the original, except for the phase shift. A more useful application of wavelets is shown in Example 7.4, where some processing is done on the subband signals before reconstruction—in this example, nonlinear filtering. The basic assumption in this application is that the noise is coded into small fluctua- tions in the higher resolution (i.e., more detailed) highpass subbands. This noise can be sele cti ve ly reduced by elim ina ti ng the smaller s am ple values in the higher resolut io n hi gh pas s subbands. In thi s e xam pl e, the two highest resol ution highpass subband s are examined and data points below so me thresh ol d are zeroed out. The thresho ld is set to be equal to the variance of the h ig hpa ss subbands . Example 7.4 Decompose the signal in Example 7.3 using a 4-level filter bank. In this example, use periodic convolution in the analysis and synthesis filters and a 4-element Daubechies filter. Examine the two highest resolution highpass subbands. These subbands will reside in the last N/4 to N samples. Set all values in these segments that are below a given threshold value to zero. Use the net variance of the subbands as the threshold. % Example 7.4 and Figure 7.9 % Application of DWT to nonlinear filtering % Construct the waveform in Example 7.3. % Decompose the waveform in 4 levels, plot each level, then % reconstruct. % Use Daubechies 4-element filter and periodic convolution. % Evaluate the two highest resolution highpass subbands and % zero out those samples below some threshold value. % close all; clear all; fs = 1000; % Sample frequency N = 1024; % Number of points in % waveform % freqsin = [.63 1.1 2.7 5.6]; % Sinusoid frequencies ampl = [1.2 1 1.2 .75 ]; % Amplitude of sinusoids [x t] = signal(freqsin,ampl,N); % Construct signal x = x ؉ (.25 * randn(1,N)); % and add noise h0 = daub(4); figure(fig1); TLFeBOOK 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 [...]... 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 relatively broadband signal, the noise portion of sequential... level are isolated, filtered (using standard convolution), 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... 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 Wavelet Analysis 211 4 Generate a Daubechies 10-element filter and plot the magnitude... should range between 2 and 100 Hz Decompose the waveform into 3 levels and plot the outputs at the terminal level as in Example 7.5 Use a Daubechies 4-element filter Note that each output filter responds to different portions of the chirp signal TLFeBOOK TLFeBOOK 8 Advanced Signal Processing Techniques: Optimal and Adaptive Filters OPTIMAL SIGNAL PROCESSING: WIENER FILTERS The FIR and IIR filters described... 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 = 2 56; % 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,... 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... 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... 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... filter is to enhance a narrowband signal, one with a spectrum composed of a single “line.” †Recall that the width of the autocorrelation function is a measure of the range of samples for which the samples are correlated, and this width is inversely related to the signal bandwidth Hence, broadband signals remain correlated for only a few samples and vice versa TLFeBOOK 2 26 Chapter 8 can have an influence... adaptive line enhancement, the configuration is the same except the roles of signal and noise are reversed: the narrowband component is the signal and the broadband component is the noise In this case, the output is taken from the filter output (Figure 8 .6, lower output) Recall that this filter output is optimized for the narrowband component of the waveform As with the Wiener filter approach, a filter of . Outputs’) end end % HPF = abs(fft(h1,2 56) ); % Calculate and plot filter LPF = abs(fft(h0,2 56) ); % transfer fun of high- and % lowpass filters freq = (1:128)* 1000/2 56; % Assume fs = 1000 Hz subplot(L؉1,2,2*i؉1); plot(freq,. n) ( 26) Since this is an equation with two time scales (t and 2t), it is not easy to solve, but a number of approximation approaches have been worked out (Strang and Nguyen, 1997, pp. 1 86 204) periodic convolution in the analysis and synthesis filters and a 4-element Daubechies filter. Examine the two highest resolution highpass subbands. These subbands will reside in the last N/4 to

Ngày đăng: 06/08/2014, 00:20

Từ khóa liên quan

Tài liệu cùng người dùng

Tài liệu liên quan