% Random linear combinations of harmonic functions

a = (0:(pi/100):(2*pi));
x = zeros(1,length(a)); for i = 1:10 x = x+((rand-.5)/i^2)*cos(i*a)+((rand-.5)/i^2)*sin(i*a); end, plot(x)

% Combining sine and cosine creates a cosine shifted in phase.

plot(cos(a)+sin(a))
plot(.5*cos(a)+sin(a))

% Another example

A = []; for i = 1:2:21  A = [A;sum(sin(i*a).*x)*sin(i*a)];  end
for i = 1:11 plot(A(i,:)); axis([0 201 -100 100]); keyboard; end
dbcont
plot(sum(A))


s = [zeros(1,100), ones(1,100)];
plot(s)
I = s + .25*randn(1,200);
plot(I);

plot(I(2:200) - I(1:199))
sig = 2.5; a = -100:1:99; G = exp( (- a.^2)/ (2*sig*sig))/(sig*(sqrt(2*pi)));
plot(G)
GI = conv(G,I);
GI = GI(150:250);
plot(GI)
plot(GI(3:100) - GI(1:98))
% Why is subtracting GI shifted from GI the same as filtering GI with 
% [-1 0 1]?

% Filtering is associative.

GD = G(3:200) - G(1:198);
plot(GD)
GDI = conv(GD,I);
plot(GDI(150:250))
figure
plot(GI(3:100) - GI(1:98))
