Created
June 2, 2020 04:30
-
-
Save iphysresearch/ff9d0e9f0f95cb959ce7e4c1af6bfc23 to your computer and use it in GitHub Desktop.
Chapter 2 - Window functions (frequency domain)
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 scipy.signal import triang, tukey | |
import matplotlib.pyplot as plt | |
import seaborn as sns | |
sns.set(context='paper', | |
style='ticks', | |
font_scale=1, | |
rc={'figure.figsize': (8, 5), | |
'figure.dpi': 100, # need fixed | |
'xtick.direction': 'in', | |
'ytick.direction': 'in', | |
'axes.linewidth': '1.3', | |
'axes.labelsize': 12, | |
'xtick.labelsize': 12, | |
'ytick.labelsize': 12, | |
'savefig.dpi': 300, | |
'legend.fontsize': 10, | |
# 'text.usetex':True, | |
}) | |
plt.figure(figsize=(6,5), dpi=100) | |
for window, label, c in zip([np.ones(128), triang(128), tukey(128, alpha=0.25), np.hanning(128), np.blackman(128)], | |
['rectangular', 'triangular', 'Tukey(r=0.25)', 'Hann','Blackman'], | |
['k', 'b', 'g','r','y']): | |
N = 1024 | |
A = np.fft.fft(window, N)/128*2 | |
y = np.abs(A)[:N//2] / np.abs(A)[0] | |
index = (y ==0) | |
y[index] = np.nan | |
plt.plot(np.linspace(0,1,N//2),y, label=label, color=c, alpha=0.9) | |
plt.yscale('log') | |
plt.xscale('log') | |
plt.xlim(1e-3,1e-0) | |
plt.ylim(1e-10,1e-0) | |
plt.legend() | |
plt.ylabel('amplitude of leakage') | |
plt.xlabel('offset from FFT bin center (in units of Nyquist freq)') | |
plt.grid(which='both',axis='both', linestyle=':') | |
plt.grid(which='major',axis='both', linestyle='--',c='k',alpha=0.6) | |
plt.yticks([1e-0,1e-2,1e-4,1e-6,1e-8,1e-10]) | |
plt.xticks([1e-3,1e-2,1e-1,1e-0]) | |
plt.savefig('C2_imags/C2_freq_window.png', dpi=300, bbox_inches='tight') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment