%This illustrates how taking differences of a piecewise-linear signal
%yields a piecewise-constant signal, and then taking differences of
%the piecewise-constant signal yields a sparse signal, as in Section 7-6A.

%Construct piecewise-linear signal,then take differences,then take differences of that.
clear;X(1:5)=[-2:2];X(6:13)=[3:-0.5:-0.5];X(14:23)=[-1:0.2:0.8];X(24:32)=[1:-0.3:-1.4];
subplot(511),stem(X),axis([0 35 -2 4]),title('Piecewise linear signal x[n]')
W1(1:31)=X(2:32)-X(1:31);W2(1:30)=W1(2:31)-W1(1:30);
subplot(513),stem(W1),axis([0 35 -0.5 1]),title('w_1[n]=x[n+1]-x[n]')
subplot(515),stem(W2),axis([0 30 -2 1]),title('w_2[n]=w_1[n+1]-w_1[n]')
