Created
October 27, 2022 11:43
-
-
Save dmishin/0e9f7461fe0946c6f045d38f086df6d5 to your computer and use it in GitHub Desktop.
Visualize Fourier transform of the Thue-Morse sequence arranged along the Hilbert curve
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
from matplotlib import pyplot as plt | |
import scipy | |
def ht(n:int)->np.array: | |
"""Generates Thue-Morse sequence, arranged along the Hilbert curve of order N. Result is (2**n, 2**n) matrix""" | |
if n < 0: raise ValueError("Bad order") | |
if n == 0: | |
return np.array([[1]], dtype=np.int8) | |
else: | |
h = ht(n-1) | |
return np.block( [[np.rot90(h,k=1), np.rot90(h,k=-1)], | |
[-h, -h]]) | |
if __name__=="__main__": | |
order = 13 | |
original = ht(order) | |
f = np.log(np.abs(np.fft.fft2(original))+1e-6) | |
f = scipy.ndimage.median_filter(f, size=3) | |
f = scipy.ndimage.zoom(f, 0.25) | |
plt.matshow(-f) | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment