Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """`stuff` from https://github.com/OverLordGoldDragon/stuff"""
- import numpy as np
- import matplotlib.pyplot as plt
- from numpy.fft import fft, fftshift
- from stuff import plot, scat, cos_f
- def show_basis(k, odd=False):
- if odd:
- scat(cos_f([k], Ne), show=1, title=f"cos, k={k}, N={Ne}")
- scat(cos_f([k], No), show=1, title=f"cos, k={k}, N={No}")
- kwr = dict(show=1, dx1=1)
- kwc = dict(show=1, dx1=1, complex=1, c_annot=1)
- #%%
- N = 6
- Ne = 2 * N # odd symmetry len
- No = 2 * N - 1 # even symmetry len
- s = np.array([.4, -.4, -.2, .1, -.9, .2])
- #%%# Symmetric ###############################################################
- xe = np.hstack([s, s[::-1]])
- xo = np.hstack([s, s[::-1][1:]])
- plot(xe, title="Symmetric even-len x -- [s, s[::-1]]", **kwr)
- plot(xo, title="Symmetric odd-len x -- [s, s[::-1][1:]]", **kwr)
- #%%
- xef = fft(xe)
- xof = fft(xo)
- plot(xef, title="DFT(x_even)", **kwc)
- plot(xof, title="DFT(x_odd)", **kwc)
- #%%# DFT-symmetric ###########################################################
- xde = np.hstack([s, s[::-1][1:-1]])
- xdo = np.hstack([s, s[::-1][:-1] ])
- plot(xde, title="DFT-symmetric even-len x -- [s, s[::-1][1:-1]]", **kwr)
- plot(xdo, title="DFT-symmetric odd-len x -- [s, s[::-1][:-1]]", **kwr)
- #%%
- xdef = fft(xde)
- xdof = fft(xdo)
- plot(xdef, title="DFT(xd_even)", **kwc)
- plot(xdof, title="DFT(xd_odd)", **kwc)
- #%%# Cosine basis, even vs odd ##############################################
- show_basis(1, odd=1)
- #%%# Even case for higher k #################################################
- show_basis(2)
- show_basis(3)
- #%%# Pretend left-most sample isn't there
- scat(cos_f([1], Ne), show=0, title=f"cos, k=1, N={Ne}")
- plt.axvline(Ne / 2, color='tab:red'); plt.show()
- scat(cos_f([1], No), show=0, title=f"cos, k=1, N={No}")
- plt.axvline(No / 2, color='tab:red'); plt.show()
- #%%# n=0 case ###############################################################
- plot(xde, title="DFT-symmetric even-len x", **kwr)
- plot(fftshift(xde), title="DFT-symmetric even-len x, centered about n=0", **kwr)
- plot(xdo, title="DFT-symmetric odd-len x", **kwr)
- plot(fftshift(xdo), title="DFT-symmetric odd-len x, centered about n=0", **kwr)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement