plot(sin(linspace(0, 2 * pi, 100)));
x = linspace(0, 2 * pi, 100)
f = piecewise(x, [x < pi, x >= pi], [1, -1]) # square wave
axis([0, 2 * pi, -1.5, 1.5])
plot(x, f);
num_coeffs = 4
fs = sum((4 / pi) * array([sin((2 * n + 1) * x) / (2 * n + 1) for n in range(num_coeffs)]), 0) # fourier series
plot(x, fs);
num_samples = 6
taps = rand(num_samples * 2) * 2 - 1 # x0, y0, x1, y1, ...
taps = append(taps, [-1 * a for a in taps]) # append mirrored vectors
axis([-1.5, 1.5, -1.5, 1.5])
scatter(taps[0::2], taps[1::2], 40, 'bgrcmybgrcmy');
if 1: # show rotation
def rot(x, y, a):
cs = cos(a)
sn = sin(a)
px = x * cs - y * sn
py = x * sn + y * cs
return px, py
res = 32
for f in range(res):
x, y = rot(taps[0::2], taps[1::2], (f+1)*2*pi/res)
scatter(x, y, 40, 'bgrcmybgrcmy');
import matplotlib.image as mpimg
l0 = mpimg.imread('c:/llama.jpg')
l1 = mpimg.imread('c:/llama2.jpg')
imshow(l0-l1);