% this is an example of compression using the DFT

% I start with function sampled using 1000 points 
N=1000;
t=(0:(N-1))/N; 
y=exp(-4*t).*sin(16*pi*t);

% compress to 2M points by doing a DFT, keeping only
% the low frequency part, and transforming back
M = 10; 
a=fft(y);                    
a2=[a(1:M) a((1001-M):1000)]; 
y2=(2*M/N)*real(ifft(a2));      % note normalization factor

% plot original signal and the compressed sample
t2=(0:(2*M-1))/(2*M); 
plot(t,y,'r',t2,y2,'b.')