-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path#example_read_write_complex.py#
More file actions
32 lines (23 loc) · 1.05 KB
/
Copy path#example_read_write_complex.py#
File metadata and controls
32 lines (23 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from array import array
import numpy as np
import matplotlib.pyplot as plt
## example write complex buffer to file
buff = np.array([0]*1024, np.complex64)
for i in range(1024):
if i == 1020:
buff[i] = 20+3j
out_file = open("test.data", 'wb')
buff.tofile(out_file)
out_file.close()
## example read complex from file
buff2 = np.fromfile("test.data", np.complex64)
## break out real and imaginary parts
real2 = np.array([0]*1024, np.float32)
imag2 = np.array([0]*1024, np.float32)
for i in range(1024):
real2[i] = buff2[i].real
imag2[i] = buff2[i].imag
t = np.linspace(0,1023,1024)
#plt.plot(t,np.abs(real2), t, np.abs(imag2))
plt.plot(t,np.abs(real2))
plt.show()