www.gusucode.com > wavelet 源码程序 matlab案例代码 > wavelet/WaveletPrincipalComponentAnalysisofNoisyMultivariateSignExample.m
%% Wavelet Principal Component Analysis of Noisy Multivariate Signal % Use wavelet multiscale principal component analysis to denoise a multivariate % signal. %% % Load the dataset consisting of 4 signals of length 1024. Plot the original % signals and the signals with additive noise. load ex4mwden; kp = 0; for i = 1:4 subplot(4,2,kp+1), plot(x_orig(:,i)); axis tight; title(['Original signal ',num2str(i)]) subplot(4,2,kp+2), plot(x(:,i)); axis tight; title(['Noisy signal ',num2str(i)]) kp = kp + 2; end %% % Perform the first multiscale wavelet PCA using the Daubechies’ least-asymmetric % wavelet with 4 vanishing moments, |sym4|. Obtain the multiresolution decomposition % down to level 5. Use the heuristic rule to decide how many principal components % to retain. level = 5; wname = 'sym4'; npc = 'heur'; [x_sim, qual, npc] = wmspca(x,level,wname,npc); %% % Plot the result and examine the quality of the approximation. qual kp = 0; for i = 1:4 subplot(4,2,kp+1), plot(x(:,i)); axis tight; title(['Noisy signal ',num2str(i)]) subplot(4,2,kp+2), plot(x_sim(:,i)); axis tight; title(['First PCA ',num2str(i)]) kp = kp + 2; end %% % The quality results are all close to 100%. The |npc| vector gives the % number of principal components retained at each level. %% % Suppress the noise by removing the principal components at levels 1–3. % Perform the multiscale PCA again. npc(1:3) = zeros(1,3); [x_sim, qual, npc] = wmspca(x,level,wname,npc); %% % Plot the result. kp = 0; for i = 1:4 subplot(4,2,kp+1), plot(x(:,i)); axis tight; title(['Noisy signal ',num2str(i)]) subplot(4,2,kp+2), plot(x_sim(:,i)); axis tight; title(['Second PCA ',num2str(i)]) kp = kp + 2; end