Exemplo n.º 1
0
def plot_all(tek_dir, tek_file, comsol_dir, comsol_file, sign):
    plt.figure(figsize=(18.9, 10.3))
    (xs, ys) = tektronix.load_csv_data(tek_dir, tek_file)
    xs = xs[0]
    ys = sign*ys[0] / np.max(sign*ys[0])
    plt.subplot(221)
    plt.xlabel('Time (ms)')
    plt.ylabel('Normalized Amplitude')
    plt.xlim((0, 14))
    plt.ylim((-1.2,1.2))
    plt.plot(xs*1e3, ys)

    dt = xs[1] - xs[0]
    df = 1.0 / dt / len(xs)
    print "".join(("dt: ", str(dt), " s\tdf: ", str(df), " Hz"))
    frequency_spectrum = np.fft.fft(ys)\
      [:round(ys.size/2)]
    spectrum_magnitudes = np.sqrt(np.real(frequency_spectrum)**2 + np.imag(frequency_spectrum)**2)
    frequencies = np.fft.fftfreq(
      frequency_spectrum.size*2, d=dt)\
      [:round(ys.size/2)]
    plt.subplot(222)
    plt.xlabel('Frequency (kHz)')
    plt.ylabel('Normalized Magnitude')
    plt.xlim((0,7))
    plt.ylim((0,1))
    plt.plot(frequencies*1e-3, spectrum_magnitudes / np.max(spectrum_magnitudes))

    #(xs, ys) = comsol.load_csv_data(comsol_dir, comsol_file)
    (xs, ys) = comsol.load_data(comsol_dir, comsol_file, dt=25e-6)
    print np.shape(xs)
    print np.shape(ys)
    #xs = xs[0]
    ys = ys[0,0] / np.max(ys[0,0])
    plt.subplot(223)
    plt.xlabel('Time (ms)')
    plt.ylabel('Normalized Amplitude')
    plt.xlim((0,14))
    plt.ylim((-1.2,1.2))
    plt.plot(xs*1e3, ys)

    dt = xs[1] - xs[0]
    df = 1.0 / dt / len(xs)
    print "".join(("dt: ", str(dt), " s\tdf: ", str(df), " Hz"))
    frequency_spectrum = np.fft.fft(ys)\
      [:round(ys.size/2)]
    spectrum_magnitudes = np.sqrt(np.real(frequency_spectrum)**2 + np.imag(frequency_spectrum)**2)
    frequencies = np.fft.fftfreq(
      frequency_spectrum.size*2, d=dt)\
      [:round(ys.size/2)]
    plt.subplot(224)
    plt.xlabel('Frequency (kHz)')
    plt.ylabel('Normalized Magnitude')
    plt.xlim((0,7))
    plt.ylim((0,1))
    plt.plot(frequencies*1e-3, spectrum_magnitudes / np.max(spectrum_magnitudes))
Exemplo n.º 2
0
    mpl.rcParams['axes.labelsize'] = 26
    mpl.rcParams['font.size'] = 26
    mpl.rcParams['mathtext.default'] = 'regular'
    mpl.rcParams['figure.subplot.left'] = 0.02
    mpl.rcParams['figure.subplot.right'] = 0.98
    mpl.rcParams['figure.subplot.top'] = 0.9
    mpl.rcParams['figure.subplot.bottom'] = 0.1
    mpl.rcParams['figure.subplot.wspace'] = 0.2
    mpl.rcParams['figure.subplot.hspace'] = 0.2


reset_plot_params()

directory = "C:\\Users\\plane\\Desktop\\Data\\Al Cavity\\2015-07-23\\ALL0000\\"
filename = "F0000CH2.CSV"
(xs, ys) = tektronix.load_csv_data(directory, filename)
xs = xs[0]
ys = ys[0]
plt.plot(xs * 1e3, ys)

xs = np.linspace(0, 4.5e-3, 100)
F0 = 1  # N
t0 = 2.3e-3  # s
gamma = 3
_lambda = 1
ys = np.array([
    F0 * math.exp(-gamma / t0 * t) * math.sin(2 * math.pi * _lambda / t0 * t)
    for t in xs
])
plt.xlabel('Time (ms)')
plt.ylabel('Amplitude')