The fast Fourier transform and fast wavelet transform for patterns on the torus