Skip to content

Commit

Permalink
improved some plots
Browse files Browse the repository at this point in the history
  • Loading branch information
xserra committed Jan 17, 2024
1 parent 6accab6 commit f31aa51
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions lectures/03-Fourier-properties/plots-code/linearity.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,41 +13,41 @@

plt.figure(1, figsize=(9.5, 7))
plt.subplot(321)
plt.title('real(x1) (amp=.5, freq=20)')
plt.title('x1 (amp=.5, #periods=20)')
plt.plot(np.arange(0, N, 1.0), np.real(x1), b, marker='x', ms=4, lw=1.5)
plt.axis([0, N, -1, 1])

plt.subplot(322)
plt.title('real(x2) (amp=1, freq=25)')
plt.title('x2 (amp=1, #periods=25)')
plt.plot(np.arange(0, N, 1.0), np.real(x2), b, marker='x', ms=4, lw=1.5)
plt.axis([0, N, -1, 1])
X1 = fft(x1)
mX1 = abs(X1)/N
mX1 = abs(X1[0:N//2-1])/N

plt.subplot(323)
plt.title('mX1 (amp=.5, freq=20)')
plt.plot(np.arange(0, N, 1.0), mX1, 'r-x', ms=4, lw=1.5)
plt.axis([0,N,0,1])
plt.title('abs(X1)')
plt.plot(np.arange(0, (N//2)-1, 1.0), mX1, 'r-x', ms=4, lw=1.5)
plt.axis([0,(N//2)-1,0,1])
X2 = fft(x2)
mX2 = abs(X2)/N
mX2 = abs(X2[0:N//2-1])/N

plt.subplot(324)
plt.title('mX2 (amp=1, freq=25)')
plt.plot(np.arange(0, N, 1.0), mX2, 'r-x', ms=4, lw=1.5)
plt.axis([0,N,0,1])
plt.title('abs(X2)')
plt.plot(np.arange(0, N//2-1, 1.0), mX2, 'r-x', ms=4, lw=1.5)
plt.axis([0,N//2-1,0,1])
x = x1 + x2

plt.subplot(325)
plt.title('mX1+mX2')
plt.plot(np.arange(0, N, 1.0), mX1+mX2, 'r-x', ms=4, lw=1.5)
plt.axis([0, N, 0, 1])
plt.title('abs(X1+X2)')
plt.plot(np.arange(0, N//2-1, 1.0), mX1+mX2, 'r-x', ms=4, lw=1.5)
plt.axis([0, N//2-1, 0, 1])
X = fft(x)
mX= abs(X)/N
mX= abs(X[0:N//2-1])/N

plt.subplot(326)
plt.title('DFT(x1+x2)')
plt.plot(np.arange(0, N, 1.0), mX, 'r-x', ms=4, lw=1.5)
plt.axis([0,N,0,1])
plt.title('abs(DFT(x1+x2))')
plt.plot(np.arange(0, N/2-1, 1.0), mX, 'r-x', ms=4, lw=1.5)
plt.axis([0,N/2-1,0,1])

plt.tight_layout()
plt.savefig('linearity.png')
Expand Down

0 comments on commit f31aa51

Please sign in to comment.