www.gusucode.com > wavelet 源码程序 matlab案例代码 > wavelet/MatchingPursuitofElectricityConsumptionDataExample.m

    %% Matching Pursuit of Electricity Consumption Data  
% Obtain a matching pursuit of electricity consumption measured every minute
% over a 24-hour period.   

%% 
% Load and plot data. The data shows electricity consumption sampled every
% minute over a 24-hour period. Because the data is centered, the actual
% usage values are not interpretable. 
load elec35_nor;
y = signals(32,:);
plot(y); xlabel('Minutes'); ylabel('Usage');
set(gca,'xlim',[1 1440]);  

%% 
% Construct a dictionary for matching pursuit consisting of the Daubechies'
% extremal-phase wavelet with 2 vanishing moments at level 2, the 
% Daubechies' least-asymmetric wavelet with 4 vanishing moments at levels 
% 1 and 4, the discrete cosine transform-II basis, and the sine basis. 
dictionary = {{'db4',2},'dct','sin',{'sym4',1},{'sym4',4}};
[mpdict,nbvect] = wmpdictionary(length(y),'lstcpt',dictionary);  

%% 
% Implement orthogonal matching pursuit to obtain a signal approximation
% in the dictionary. Use 35 iterations. Plot the result. 
[yfit,r,coef,iopt,qual] = wmpalg('OMP',y,mpdict,'itermax',35);
plot(y); hold on;
plot(yfit,'r'); xlabel('Minutes'); ylabel('Usage');
legend('Original Signal','OMP','Location','NorthEast');
set(gca,'xlim',[1 1440]);  

%% 
% Using the expansion coefficients in |coef| and the atom indices in |iopt|,
% construct the signal approximation, |yhat|, directly from the dictionary.
% Compare |yhat| with |yfit| returned by |wmpalg|. 
[~,I] = sort(iopt);
X = mpdict(:,iopt(I));
yhat = X*coef(I);
max(abs(yfit-yhat))