%%%%Problem 1

B = ones(8,1)

B =

     1
     1
     1
     1
     1
     1
     1
     1

A = zeros(8,8);

for i=1:8 A(i,i)=2; end
for i=1:7 A(i,i+1)=1; A(i+1,i)=1; end
A

A =

     2     1     0     0     0     0     0     0
     1     2     1     0     0     0     0     0
     0     1     2     1     0     0     0     0
     0     0     1     2     1     0     0     0
     0     0     0     1     2     1     0     0
     0     0     0     0     1     2     1     0
     0     0     0     0     0     1     2     1
     0     0     0     0     0     0     1     2

X = inv(A)*B

X =

    0.4444
    0.1111
    0.3333
    0.2222
    0.2222
    0.3333
    0.1111
    0.4444

% an alternative

A = 2*diag(ones(8,1),0)+diag(ones(7,1),1)+diag(ones(7,1),-1)

A =

     2     1     0     0     0     0     0     0
     1     2     1     0     0     0     0     0
     0     1     2     1     0     0     0     0
     0     0     1     2     1     0     0     0
     0     0     0     1     2     1     0     0
     0     0     0     0     1     2     1     0
     0     0     0     0     0     1     2     1
     0     0     0     0     0     0     1     2

X = A\B

X =

    0.4444
    0.1111
    0.3333
    0.2222
    0.2222
    0.3333
    0.1111
    0.4444


%%%%Problem 2 
A = 2*diag(ones(8,1),0)+diag(ones(7,1),1)+diag(ones(7,1),-1)

A =

     2     1     0     0     0     0     0     0
     1     2     1     0     0     0     0     0
     0     1     2     1     0     0     0     0
     0     0     1     2     1     0     0     0
     0     0     0     1     2     1     0     0
     0     0     0     0     1     2     1     0
     0     0     0     0     0     1     2     1
     0     0     0     0     0     0     1     2

A'*A

ans =

     5     4     1     0     0     0     0     0
     4     6     4     1     0     0     0     0
     1     4     6     4     1     0     0     0
     0     1     4     6     4     1     0     0
     0     0     1     4     6     4     1     0
     0     0     0     1     4     6     4     1
     0     0     0     0     1     4     6     4
     0     0     0     0     0     1     4     5

% If columns have at least 2 columns between them, then they are orthogonal.

%%%%% Problem 3
% Since A is symmetric a similar statement is true for the rows.


%%%Problem 4
C = Ncossinmat(10)

C =

  Columns 1 through 5 

    1.0000    1.0000    1.0000    1.0000    1.0000
    1.0000    0.8090    0.3090   -0.3090   -0.8090
    1.0000    0.3090   -0.8090   -0.8090    0.3090
    1.0000   -0.3090   -0.8090    0.8090    0.3090
    1.0000   -0.8090    0.3090    0.3090   -0.8090
    1.0000   -1.0000    1.0000   -1.0000    1.0000
    1.0000   -0.8090    0.3090    0.3090   -0.8090
    1.0000   -0.3090   -0.8090    0.8090    0.3090
    1.0000    0.3090   -0.8090   -0.8090    0.3090
    1.0000    0.8090    0.3090   -0.3090   -0.8090

  Columns 6 through 10 

    1.0000         0         0         0         0
   -1.0000    0.5878    0.9511    0.9511    0.5878
    1.0000    0.9511    0.5878   -0.5878   -0.9511
   -1.0000    0.9511   -0.5878   -0.5878    0.9511
    1.0000    0.5878   -0.9511    0.9511   -0.5878
   -1.0000    0.0000   -0.0000    0.0000   -0.0000
    1.0000   -0.5878    0.9511   -0.9511    0.5878
   -1.0000   -0.9511    0.5878    0.5878   -0.9511
    1.0000   -0.9511   -0.5878    0.5878    0.9511
   -1.0000   -0.5878   -0.9511   -0.9511   -0.5878

C'*C

ans =

  Columns 1 through 5 

   10.0000   -0.0000   -0.0000   -0.0000         0
   -0.0000    5.0000   -0.0000   -0.0000   -0.0000
   -0.0000   -0.0000    5.0000   -0.0000   -0.0000
   -0.0000   -0.0000   -0.0000    5.0000    0.0000
         0   -0.0000   -0.0000    0.0000    5.0000
         0         0    0.0000    0.0000    0.0000
         0   -0.0000    0.0000    0.0000    0.0000
    0.0000         0    0.0000    0.0000    0.0000
    0.0000    0.0000    0.0000    0.0000    0.0000
    0.0000    0.0000    0.0000    0.0000    0.0000

  Columns 6 through 10 

         0         0    0.0000    0.0000    0.0000
         0   -0.0000         0    0.0000    0.0000
    0.0000    0.0000    0.0000    0.0000    0.0000
    0.0000    0.0000    0.0000    0.0000    0.0000
    0.0000    0.0000    0.0000    0.0000    0.0000
   10.0000    0.0000    0.0000    0.0000   -0.0000
    0.0000    5.0000         0    0.0000    0.0000
    0.0000         0    5.0000   -0.0000   -0.0000
    0.0000    0.0000   -0.0000    5.0000   -0.0000
   -0.0000    0.0000   -0.0000   -0.0000    5.0000

% round to make entries easier to see

round(C'*C)

ans =

    10     0     0     0     0     0     0     0     0     0
     0     5     0     0     0     0     0     0     0     0
     0     0     5     0     0     0     0     0     0     0
     0     0     0     5     0     0     0     0     0     0
     0     0     0     0     5     0     0     0     0     0
     0     0     0     0     0    10     0     0     0     0
     0     0     0     0     0     0     5     0     0     0
     0     0     0     0     0     0     0     5     0     0
     0     0     0     0     0     0     0     0     5     0
     0     0     0     0     0     0     0     0     0     5

%disticnt columns are orthogonal

round(C*C')

ans =

     6     0     1     0     1     0     1     0     1     0
     0     6     0     1     0     1     0     1     0     1
     1     0     6     0     1     0     1     0     1     0
     0     1     0     6     0     1     0     1     0     1
     1     0     1     0     6     0     1     0     1     0
     0     1     0     1     0     6     0     1     0     1
     1     0     1     0     1     0     6     0     1     0
     0     1     0     1     0     1     0     6     0     1
     1     0     1     0     1     0     1     0     6     0
     0     1     0     1     0     1     0     1     0     6

% if the sum of the row indices is odd then the rows are orthogonal

%%%%% Problems 5 and 6

diary off
T = (0:127)/128;
plot(sin(5*2*pi*T))
% the apparent frequency is 5 (number of peaks) 
T = (0:127)/128; k=24; plot(sin(k*2*pi*T))
% the apparent frequency is 24 (number of peaks)
T = (0:127)/128; k=69; plot(sin(k*2*pi*T))
% there is a beat phenomenon with an envelope frequency of 6
% and a fast oscilation frequency of 59  (total number of peaks)
T = (0:127)/128; k=102; plot(sin(k*2*pi*T))
% the apparent frequency is 5 (number of peaks)
T = (0:127)/128; k=300; plot(sin(k*2*pi*T))
% there is a beat phenomenon with an envelope frequency of 4
% and a fast oscilation frequency of 44
T = (0:31)/32; k=5; plot(sin(k*2*pi*T))
% the apparent frequency is 5 (number of peaks)
T = (0:31)/32; k=8; plot(sin(k*2*pi*T))
% the apparent frequency is 8 (number of peaks)
T = (0:31)/32; k=24; plot(sin(k*2*pi*T))
% the apparent frequency is 8 (number of peaks)
T = (0:31)/32; k=60; plot(sin(k*2*pi*T))
% the apparent frequency is 4 (number of peaks)
T = (0:31)/32; k=1000; plot(sin(k*2*pi*T))
% the apparent frequency is 8 (number of peaks)

%%%%% Problem 7
See the notes for the discussion of aliasing

%%%%%%% Problem 8 and 9

Here is a script to create the noisy signal, play it, and then compute the distortion.

N =  8192
T = (1/N)*(0:(N-1));
X = cos(2*pi*500*T)+0.5*sin(2*pi*550*T)+0.5*sin(2*pi*900*T)+ 3*cos(2*pi*2000*T) ;
U = 2*(rand(size(X))-0.5);
M = max(abs(X))
e = .1
sound(X+e*M*U);

D = e^2*(U*U')/(X*X')

noise disappeared for D < .006