20180217a - Testing pulser and ADC

# Basic math
import math
import os
# Signal processing
import numpy as np
import matplotlib.pyplot as plt
from scipy.signal import hilbert, chirp
# Custom lib
import ustk as USTk # Ultrasound toolkit

Preparing the data

Let's unpack what has been acquired by the ADC pHAT.

for filename in os.listdir("./data/"):
    if filename.endswith(".DAT"):
        DATFile = os.path.join("", filename).split(".")[0]
        if not os.path.isfile(DATFile+".npz"):
            print DATFile+".DAT"
            Arf = USTk.CreateUsPack(DATFile+".DAT")
A11-termodule.DAT
A11-termodule.DAT

png

png

Working on a specific file

DATFile = "B33-newmodule"
DATA = np.load(DATFile+".npz") 
DATA.keys()
Image, rawSignal = DATA['arr_1'], DATA['arr_0']
N = 3
plt.figure(figsize=(15,5))
line = rawSignal[N*5000:(N+1)*5000]
F = 12 # acquisition speed in MHz
plt.subplot(1, 2, 1)
plt.title("Raw signal of "+DATFile+".npz on line "+str(N))
ff = [ 2*x*1000.0/(F*len(line)) for x in range(len(line))]

plt.plot(ff,line)
plt.xlabel("Time (us)")

plt.subplot(1, 2, 2)
plt.title("Spectrum "+DATFile+".npz on line "+str(N))
fftline = np.fft.fft(line)
ff = [ 12*2.0*x/(len(line)) for x in range(len(line))]
plt.plot(ff[0:len(line)/2],np.real(fftline)[0:len(line)/2],"g")
plt.plot(ff[0:len(line)/2],np.imag(fftline)[0:len(line)/2],"r")
plt.xlabel("MHz")

plt.tight_layout()
plt.savefig("lines/"+DATFile+"_line"+str(N)+"sample.jpg", bbox_inches='tight')
plt.show()

png

Cleaning the signal around the frequency of the piezo

line2 = fftline
for i in range(len(line2)/2+3):
    if i < 350 or i > 1300:
        line2[i] = 0
        line2[-i] = 10
line3 = np.fft.ifft(line2)
lineU = np.real(line3)
analytic_signal = hilbert(lineU)
amplitude_envelope = np.abs(analytic_signal)

Representation

F = 12 # acquisition speed in MHz
ff = [ 2*x*1000.0/(F*len(line))+7.5 for x in range(len(line))] # 7.5 comes from the 7.5us in Poff

plt.figure(figsize=(15,5)) 
plt.subplot(1, 2, 1)
plt.title("Line "+str(N)+" in "+DATFile+".npz")
plt.plot(ff[0:2600],np.real(line[0:2600]),"y")
plt.plot(ff[0:2600],(analytic_signal[0:2600]),"g")
plt.plot(ff[0:2600],(amplitude_envelope[0:2600]),"b")
plt.xlabel("Time (us)") 

plt.subplot(1, 2, 2)
ST = 700
SP = 950
plt.title("Detail of line "+str(N)+" in "+DATFile+".npz")
plt.plot(ff[ST:SP],(analytic_signal[ST:SP]),"y")
plt.plot(ff[ST:SP],(amplitude_envelope[ST:SP]),"b")
plt.plot(ff[ST:SP],np.real(line[ST:SP]),"g")
plt.xlabel("Time (us)")

plt.tight_layout()
plt.savefig("lines/"+DATFile+"_clean_line"+str(N)+"sample.jpg", bbox_inches='tight')
plt.show()

png

Creating lines for all images

def PlotLine(DATFile):
    DATA = np.load(DATFile+".npz") 
    DATA.keys()
    Image, rawSignal = DATA['arr_1'], DATA['arr_0']

    for i in range(5):
        N = 2*i 
        lineA = rawSignal[N*5000:(N+1)*5000]
        N = 2*i+1 
        lineB = rawSignal[N*5000:(N+1)*5000]

        flineA = np.fft.fft(lineA)
        flineB = np.fft.fft(lineB)
        for m in range(len(lineA)/2+3):
            if m < 350 or m > 1300:
                flineA[m] = 0
                flineA[-m] = 0
                flineB[m] = 0
                flineB[-m] = 0

        CleanA = np.real( np.fft.ifft(flineA) )
        CleanB = np.real( np.fft.ifft(flineB) )

        analytic_signalA = hilbert(CleanA)
        analytic_signalB = hilbert(CleanB)

        if not(i):
            amplitude_envelopeA = np.abs(analytic_signalA)
            amplitude_envelopeB = np.abs(analytic_signalB)
        else:
            print i
            amplitude_envelopeA += np.abs(analytic_signalA)
            amplitude_envelopeB += np.abs(analytic_signalB)





    F = 12 # acquisition speed in MHz
    ff = [ 2*x*1000.0/(F*len(lineA))  + 7.5 for x in range(len(lineA))] # delay from Poff

    plt.figure(figsize=(15,5)) 
    plt.title("Odd lines (green) and even lines (blue) in "+DATFile+".npz") 
    plt.plot(ff[0:4300],(amplitude_envelopeB[0:4300]),"b")
    plt.plot(ff[0:4300],(amplitude_envelopeA[0:4300]),"g") 

    plt.xlabel("Time (us)")

    plt.tight_layout()
    plt.savefig("lines/"+DATFile+"_odd-even.jpg", bbox_inches='tight')
    plt.show()

    print len(amplitude_envelopeB)
for filename in os.listdir("./"):
    if filename.endswith(".npz"):
        DATFile = os.path.join("", filename).split(".")[0] 
        print DATFile+".DAT"
        PlotLine(DATFile)






results matching ""

    No results matching ""