www.gusucode.com > signal 案例源码程序 matlab代码 > signal/EnergyStoredInDCTCoefficientsExample.m
%% Energy Stored in DCT Coefficients % Find how many DCT coefficients represent 99% of the energy in a sequence. % Copyright 2015 The MathWorks, Inc. %% x = (1:100) + 50*cos((1:100)*2*pi/40); X = dct(x); [XX,ind] = sort(abs(X),'descend'); i = 1; while norm(X(ind(1:i)))/norm(X)<0.99 i = i + 1; end Needed = i; %% % Reconstruct the signal and compare to the original. X(ind(Needed+1:end)) = 0; xx = idct(X); plot([x;xx]') legend('Original',['Reconstructed, N = ' int2str(Needed)], ... 'Location','SouthEast')