def plot():
    plt.clf()
    f = 500e9
    omega = 2 * np.pi * f
    n = 1
    c = scipy.constants.speed_of_light / n
    lambda_ = c / f
    k = 2 * np.pi / lambda_
    phi = 0
    x = np.linspace(0, 1e-3, 1000)
    ts = np.linspace(0, 1 / f / 2, 5)
    legends = []
    for i, t in enumerate(ts):
        y = np.cos(omega * t - k * x + phi)
        j = len(ts) - 1 - i
        col = j / (j + 1)
        plt.plot(x * 1000, y, color=(col, col, col))
        plt.ylim([-1.1, 1.1])
        plt.xlabel(style.latexT("Position $z$ [\\si{\\milli\\meter}]"))
        plt.ylabel(style.latexT("Amplitude $e(z, t)$ [\\si{\\volt\\per\\meter}]"))
        legend = style.latexM("t=\\SI{%04.2f}{\\pico\\second}" % (t * 1e12))
        legends.append(legend)
    plt.legend(legends, loc="lower right")
    if USE_PDF:
        plt.savefig("plane_wave_propagation.pdf", bbox_inches='tight')
    else:
        plt.show()
Esempio n. 2
0
def plot():
    nb_points = 4001
    f_range = 64e9
    f_start = 500e9
    f_stop = f_start + f_range
    fs = np.linspace(f_start, f_stop, nb_points)
    observable = fs <= 504e9
    b0s = np.zeros(nb_points, dtype=complex)
    b5s = np.zeros(nb_points, dtype=complex)
    for i, f in enumerate(fs):
        b0s[i], b5s[i] = setup(f)
    y0s = np.abs(b0s) ** 2
    y5s = np.abs(b5s) ** 2
    # Direct.
    plt.plot(fs[observable] / 1.e9, y0s[observable], color=style.COLORS_STD[1])
    plt.plot(fs[observable] / 1.e9, y5s[observable], color=style.COLORS_STD[2])
    plt.xlabel(style.latexT("Frequency [\\si{\\giga\\hertz}]"))
    plt.ylabel(style.latexT("Power coupling [1]"))
    plt.ylim((-.1, 1.1))
    if USE_PDF:
        plt.savefig("simple_cavity_direct.pdf", bbox_inches='tight')
    else:
        plt.show()
    # FFT.
    L = .5
    prediction = scipy.constants.speed_of_light / (2 * L) / 1.e6
    h = np.hanning(nb_points)
    y0s = np.abs(np.fft.rfft(y0s * h))
    y5s = np.abs(np.fft.rfft(y5s * h))
    cutat = len(y0s)
    p = np.fft.fftfreq(nb_points, f_range / (nb_points))[:cutat]  # In Hz-1.
    p = 1 / p  # In Hz.
    p /= 1.e6  # In MHz.
#     p = p[3:]
#     y0s = y0s[3:]
#     y5s = y5s[3:]
    plt.clf()
#     plt.axvline(prediction / 2, linestyle='-', color='#878686', linewidth=1)
#     plt.axvline(prediction, linestyle='-', color='#878686', linewidth=1)
    plt.plot(p, y0s, '-', color=style.COLORS_STD[1])
    plt.plot(p, y5s, '--', color=style.COLORS_STD[2])
    plt.xlabel(style.latexT("Period [\\si{\\mega\\hertz}]"))
    plt.ylabel(style.latexT("FFT power coupling [arbitrary]"))
    plt.annotate(style.latexM("c/2d"),
                 xy=(prediction, 0),
                 xytext=(prediction, -5),
                 horizontalalignment='center',
                 verticalalignment='center')
    plt.annotate(style.latexM("c/4d"),
                 xy=(prediction / 2, 0),
                 xytext=(prediction / 2, -5),
                 horizontalalignment='center',
                 verticalalignment='center')
    plt.xlim((0, 500))
    plt.ylim((-10, 70))
    if USE_PDF:
        plt.savefig("simple_cavity_fft.pdf", bbox_inches='tight')
    else:
        plt.show()
def plot():
    nb_points = 101
    f_range = 1000e9
    f_start = 0e9
    f_stop = f_start + f_range
    fs = np.linspace(f_start, f_stop, nb_points)
    rAs = np.zeros(nb_points, dtype=complex)
    tAs = np.zeros(nb_points, dtype=complex)
    rBs = np.zeros(nb_points, dtype=complex)
    tBs = np.zeros(nb_points, dtype=complex)
    for i, f in enumerate(fs):
        rAs[i], tAs[i] = setupA(f)
        rBs[i], tBs[i] = setupB(f)
    # P = EH   and   E=ZH   =>   P = E**2 / Z.
    yrAs = np.abs(rAs) ** 2 / Z3
    ytAs = np.abs(tAs) ** 2 / Z3
    yrBs = np.abs(rBs) ** 2 / Z3
    ytBs = np.abs(tBs) ** 2 / Z3
    xs = fs / 1.e9
    plt.subplot(2, 1, 1)
    plt.plot(xs, ytAs, '-', color=style.COLORS_STD[1], label=style.latexT("Thin film model"))
    plt.plot(xs, ytBs, '--', color=style.COLORS_STD[2], label=style.latexT("Interfaces model"))
    plt.ylabel(style.latexT("Power coupling [1]"))
    plt.annotate(style.latexT("Transmitted"), xy=(150, np.mean(ytAs)), verticalalignment='center', size='x-small')
    plt.legend()
    plt.subplot(2, 1, 2)
    plt.plot(xs, yrAs, '-', color=style.COLORS_STD[1], label=style.latexT("Thin film model"))
    plt.plot(xs, yrBs, '--', color=style.COLORS_STD[2], label=style.latexT("Interfaces model"))
    plt.xlabel(style.latexT("Frequency [\\si{\\giga\\hertz}]"))
    plt.ylabel(style.latexT("Power coupling [1]"))
    plt.annotate(style.latexT("Reflected"), xy=(150, np.mean(yrAs)), verticalalignment='center', size='x-small')
    plt.legend(loc='lower right')
    if USE_PDF:
        plt.savefig("thin_film_normal_verification.pdf", bbox_inches='tight')
    else:
        plt.show()
def plot():
    fs_normal = np.linspace(1, 90, 90)
    fs_critical = np.linspace(41.8103, 41.8104, 10)  # High resolution around critical angle.
    fs = np.concatenate((fs_normal, fs_critical))
    fs.sort()
    fs = np.radians(fs)
    nb_points = len(fs)
    rAhs = np.zeros(nb_points, dtype=complex)
    rAvs = np.zeros(nb_points, dtype=complex)
    tAhs = np.zeros(nb_points, dtype=complex)
    tAvs = np.zeros(nb_points, dtype=complex)
    rBhs = np.zeros(nb_points, dtype=complex)
    rBvs = np.zeros(nb_points, dtype=complex)
    tBhs = np.zeros(nb_points, dtype=complex)
    tBvs = np.zeros(nb_points, dtype=complex)

    n1 = 1
    n2 = 1.5
    Z1 = Z0 / n1  # True for dielectrics only.
    Z2 = Z0 / n2  # True for dielectrics only.

    for i, f in enumerate(fs):
        rh, rv, th, tv = setup(n1, n2, f)
        # P = EH   and   E=ZH   =>   P = E**2 / Z.
        rAhs[i] = np.linalg.norm(rh) ** 2 / Z1
        rAvs[i] = np.linalg.norm(rv) ** 2 / Z1
        tAhs[i] = np.linalg.norm(th) ** 2 / Z2
        tAvs[i] = np.linalg.norm(tv) ** 2 / Z2
        #
        rh, rv, th, tv = setup(n2, n1, f)
        rBhs[i] = np.linalg.norm(rh) ** 2 / Z2
        rBvs[i] = np.linalg.norm(rv) ** 2 / Z2
        tBhs[i] = np.linalg.norm(th) ** 2 / Z1
        tBvs[i] = np.linalg.norm(tv) ** 2 / Z1

    crit_b = np.degrees(np.arcsin(n1.real / n2.real))
    brew_a = np.degrees(np.arctan(n2.real / n1.real))
    brew_b = np.degrees(np.arctan(n1.real / n2.real))

    xs = np.degrees(fs)

    plt.subplot(3, 2, 1)
    plt.axvline(brew_a, linestyle=':', color=style.COLORS_STD[0], label=style.latexT("Brewster"))
    plt.plot(xs, tAhs, '-', color=style.COLORS_STD[1], label=style.latexM("T_\perp"))
    plt.plot(xs, tAvs, '-', color=style.COLORS_STD[2], label=style.latexM("T_\parallel"))
    plt.ylabel(style.latexT("Power coupling [1]"))
    plt.title(style.latexM("n_i=1.0, n_t=1.5"), fontsize=10)
    plt.xlim((0, 90))
    plt.ylim((-.1, 1.1))
    plt.legend(loc='center left', prop={"size":6})

    plt.subplot(3, 2, 2)
    plt.axvline(crit_b, linestyle='--', color=style.COLORS_STD[0], label=style.latexT("Critical"))
    plt.axvline(brew_b, linestyle=':', color=style.COLORS_STD[0], label=style.latexT("Brewster"))
    plt.plot(xs, tBhs, '-', color=style.COLORS_STD[1], label=style.latexM("T_\perp"))
    plt.plot(xs, tBvs, '-', color=style.COLORS_STD[2], label=style.latexM("T_\parallel"))
    plt.title(style.latexM("n_i=1.5, n_t=1.0"), fontsize=10)
    plt.xlim((0, 90))
    plt.ylim((-.1, 1.1))
    plt.legend(loc='upper right', prop={"size":6})

    plt.subplot(3, 2, 3)
    plt.axvline(brew_a, linestyle=':', color=style.COLORS_STD[0], label=style.latexT("Brewster"))
    plt.plot(xs, rAhs, '-', color=style.COLORS_STD[1], label=style.latexM("R_\perp"))
    plt.plot(xs, rAvs, '-', color=style.COLORS_STD[2], label=style.latexM("R_\parallel"))
    plt.ylabel(style.latexT("Power coupling [1]"))
    plt.xlim((0, 90))
    plt.ylim((-.1, 1.1))
    plt.legend(loc='upper left', prop={"size":6})

    plt.subplot(3, 2, 4)
    plt.axvline(crit_b, linestyle='--', color=style.COLORS_STD[0], label=style.latexT("Critical"))
    plt.axvline(brew_b, linestyle=':', color=style.COLORS_STD[0], label=style.latexT("Brewster"))
    plt.plot(xs, rBhs, '-', color=style.COLORS_STD[1], label=style.latexM("R_\perp"))
    plt.plot(xs, rBvs, '-', color=style.COLORS_STD[2], label=style.latexM("R_\parallel"))
    plt.xlim((0, 90))
    plt.ylim((-.1, 1.1))
    plt.legend(loc='upper right', prop={"size":6})

    plt.subplot(3, 2, 5)
    plt.plot(xs, tAhs + rAhs, '-', color=style.COLORS_STD[1], label=style.latexT("Sum $\perp$"))
    plt.plot(xs, tAvs + rAvs, '--', color=style.COLORS_STD[2], label=style.latexT("Sum $\parallel$"))
    plt.ylabel(style.latexT("Power coupling [1]"))
    plt.xlabel(style.latexT("Incidence angle [\\si{\\degree}]"))
    plt.xlim((0, 90))
    plt.ylim((-.1, 1.1))
    plt.legend(loc='center left', prop={"size":6})

    plt.subplot(3, 2, 6)
    plt.axvline(crit_b, linestyle='--', color=style.COLORS_STD[0], label=style.latexT("Critical"))
    plt.plot(xs, tBhs + rBhs, '-', color=style.COLORS_STD[1], label=style.latexT("Sum $\perp$"))
    plt.plot(xs, tBvs + rBvs, '--', color=style.COLORS_STD[2], label=style.latexT("Sum $\parallel$"))
    plt.xlabel(style.latexT("Incidence angle [\\si{\\degree}]"))
    plt.xlim((0, 90))
    plt.ylim((-.1, 1.1))
    plt.legend(loc='upper right', prop={"size":6})

    if USE_PDF:
        plt.savefig("interface_oblique_verification.pdf", bbox_inches='tight')
    else:
        plt.show()
def plot():
    nb_points = 11
    f_range = 1000e9
    f_start = 0e9
    f_stop = f_start + f_range
    fs = np.linspace(f_start, f_stop, nb_points)
    rAhs = np.zeros(nb_points, dtype=complex)
    rAvs = np.zeros(nb_points, dtype=complex)
    tAhs = np.zeros(nb_points, dtype=complex)
    tAvs = np.zeros(nb_points, dtype=complex)
    rBhs = np.zeros(nb_points, dtype=complex)
    rBvs = np.zeros(nb_points, dtype=complex)
    tBhs = np.zeros(nb_points, dtype=complex)
    tBvs = np.zeros(nb_points, dtype=complex)
    rDhs = np.zeros(nb_points, dtype=complex)
    rDvs = np.zeros(nb_points, dtype=complex)
    tDhs = np.zeros(nb_points, dtype=complex)
    tDvs = np.zeros(nb_points, dtype=complex)

    for i, f in enumerate(fs):
        # P = EH   and   E=ZH   =>   P = E**2 / Z.
        rah, rav, tah, tav = setupA(f)
        rbh, rbv, tbh, tbv = setupB(f)
        rAhs[i] = np.linalg.norm(rah) ** 2 / Z1
        rAvs[i] = np.linalg.norm(rav) ** 2 / Z1
        tAhs[i] = np.linalg.norm(tah) ** 2 / Z1
        tAvs[i] = np.linalg.norm(tav) ** 2 / Z1
#         rAhs[i] = np.abs(rah[0]) ** 2 / Z1
#         rAvs[i] = np.abs(rav[2]) ** 2 / Z1
#         tAhs[i] = np.abs(tah[0]) ** 2 / Z1
#         tAvs[i] = np.abs(tav[1]) ** 2 / Z1

#         rBhs[i] = np.linalg.norm(rbh) ** 2 / Z1
#         rBvs[i] = np.linalg.norm(rbv) ** 2 / Z1
#         tBhs[i] = np.linalg.norm(tbh) ** 2 / Z1
#         tBvs[i] = np.linalg.norm(tbv) ** 2 / Z1
        rBhs[i] = np.abs(rbh[0]) ** 2 / Z1
        rBvs[i] = np.abs(rbv[2]) ** 2 / Z1
        tBhs[i] = np.abs(tbh[0]) ** 2 / Z1
        tBvs[i] = np.abs(tbv[1]) ** 2 / Z1

        rDhs[i] = np.abs(rbh[0] - rah[0])
        rDvs[i] = np.abs(rbv[2] - rav[2])
        tDhs[i] = np.abs(tbh[0] - tah[0])
        tDvs[i] = np.abs(tbv[0] - tav[0])

    xs = fs / 1.e9

    plt.subplot(3, 2, 1)
    plt.plot(xs, tAhs, '-', color=style.COLORS_STD[1], label=style.latexT("Thin film transmission"))
    plt.plot(xs, tBhs, '--', color=style.COLORS_STD[2], label=style.latexT("Interfaces transmission"))
#     plt.plot(xs, tDhs)
    plt.title(style.latexT("Perpendicular"), fontsize=10)
    plt.ylabel(style.latexT("Power coupling [1]"))
    plt.ylim((.9, 1.1))
    plt.legend(loc='upper left', prop={"size":6})

    plt.subplot(3, 2, 2)
    plt.plot(xs, tAvs, '-', color=style.COLORS_STD[1], label=style.latexT("Thin film transmission"))
    plt.plot(xs, tBvs, '--', color=style.COLORS_STD[2], label=style.latexT("Interfaces transmission"))
    plt.plot(xs, tDvs)
    plt.title(style.latexT("Parallel"), fontsize=10)
    plt.ylim((.99, 1.01))
    plt.legend(loc='upper right', prop={"size":6})

    plt.subplot(3, 2, 3)
    plt.plot(xs, rAhs, '-', color=style.COLORS_STD[1], label=style.latexT("Thin film reflection"))
    plt.plot(xs, rBhs, '--', color=style.COLORS_STD[2], label=style.latexT("Interfaces reflection"))
#     plt.plot(xs, rDhs)
    plt.ylabel(style.latexT("Power coupling [1]"))
    plt.ylim((-.1, .1))
    plt.legend(loc='lower left', prop={"size":6})

    plt.subplot(3, 2, 4)
    plt.plot(xs, rAvs, '-', color=style.COLORS_STD[1], label=style.latexT("Thin film reflection"))
    plt.plot(xs, rBvs, '--', color=style.COLORS_STD[2], label=style.latexT("Interfaces reflection"))
#     plt.plot(xs, rDvs)
    plt.ylim((-.01, .01))
    plt.legend(loc='lower right', prop={"size":6})

    plt.subplot(3, 2, 5)
    plt.plot(xs, rAhs + tAhs, '-', color=style.COLORS_STD[1], label=style.latexT("Thin film sum"))
    plt.plot(xs, rBhs + tBhs, '--', color=style.COLORS_STD[2], label=style.latexT("Interfaces sum"))
    plt.ylim((.99, 1.01))
    plt.xlabel(style.latexT("Frequency [\\si{\\giga\\hertz}]"))
    plt.ylabel(style.latexT("Power coupling [1]"))
    plt.legend(loc='lower left', prop={"size":6})

    plt.subplot(3, 2, 6)
    plt.plot(xs, rAvs + tAvs, '-', color=style.COLORS_STD[1], label=style.latexT("Thin film sum"))
    plt.plot(xs, rBvs + tBvs, '--', color=style.COLORS_STD[2], label=style.latexT("Interfaces sum"))
    plt.ylim((.99, 1.01))
    plt.xlabel(style.latexT("Frequency [\\si{\\giga\\hertz}]"))
    plt.legend(loc='lower right', prop={"size":6})

    if USE_PDF:
        plt.savefig("thin_film_oblique_verification.pdf", bbox_inches='tight')
    else:
        plt.show()
Esempio n. 6
0
#         noises.append(np.std(y[continuum_idx]))
        ax_profile.plot(x, no_baseline)
        ax_peak.plot(x, no_baseline)
        ax_base.plot(x, no_baseline)
    xmin = 1037.00
    xmax = 1037.25
    ticks_nb = 6
    ticks_pos = np.linspace(xmin, xmax, ticks_nb)
    ticks_lbl = ['%07.2f' % tick_pos for tick_pos in ticks_pos]
    ticks_lbl = map(my_style.latexM, ticks_lbl)
    ax_profile.set_autoscalex_on(False)
    ax_profile.set_autoscaley_on(False)
    ax_profile.set_xlim(xmin, xmax)
    ax_profile.set_xticks(ticks_pos, ticks_lbl)
    ax_profile.set_xticklabels(ticks_lbl)
    ax_profile.set_xlabel(my_style.latexT("USB Frequency [GHz]"))
    ax_profile.set_ylabel(my_style.latexT("Flux [K]"))
    x1, x2, y1, y2 = 1037.105, 1037.120, 17.5, 19.5
    ax_peak.set_xlim(x1, x2)
    ax_peak.set_ylim(y1, y2)
    ax_peak.set_xticks([])
    ax_peak.set_yticks([])
    mark_inset(ax_profile, ax_peak, loc1=2, loc2=4, fc="none", ec="0.5")
    x1, x2, y1, y2 = 1037.005, 1037.020, -1.0, 1.0
    ax_base.set_xlim(x1, x2)
    ax_base.set_ylim(y1, y2)
    ax_base.set_xticks([])
    ax_base.set_yticks([])
    mark_inset(ax_profile, ax_base, loc1=2, loc2=3, fc="none", ec="0.5")
#     ax_profile.title(my_style.latexT("Line profile"))
def plot(width, frequencies, b_lo, b_sky):
    # Plot unfolded.
    lsb = frequencies < lo_freq
    usb = frequencies > lo_freq
    xs = frequencies / 1e9

    def power(field):
        return np.abs(field) ** 2 / Z0 / 2

    lo_h_f = b_lo[:, 10 * 3 + 0]
    lo_v_f = b_lo[:, 10 * 3 + 2]
    sky_h_f = b_sky[:, 10 * 3 + 0]
    sky_v_f = b_sky[:, 10 * 3 + 2]

    lo_h = power(lo_h_f)
    lo_v = power(lo_v_f)
    sky_h = power(sky_h_f)
    sky_v = power(sky_v_f)

    with style.latex(width, scipy.constants.golden):
        style.pretty()
        plt.figure(0)
        plt.axvspan(np.max(xs[lsb]),
                    np.min(xs[usb]),
                    facecolor='#aaaaaa',
                    alpha=0.5)
        plt.plot(xs[lsb], lo_h[lsb], '-', label=style.latexT("LO H"), color=style.COLORS_STD[1])
        plt.plot(xs[lsb], lo_v[lsb], '--', label=style.latexT("LO V"), color=style.COLORS_STD[1])
        plt.plot(xs[lsb], sky_h[lsb], '-', label=style.latexT("Sky H"), color=style.COLORS_STD[2])
        plt.plot(xs[lsb], sky_v[lsb], '--', label=style.latexT("Sky V"), color=style.COLORS_STD[2])
        plt.plot(xs[usb], lo_h[usb], '-', color=style.COLORS_STD[1])
        plt.plot(xs[usb], lo_v[usb], '--', color=style.COLORS_STD[1])
        plt.plot(xs[usb], sky_h[usb], '-', color=style.COLORS_STD[2])
        plt.plot(xs[usb], sky_v[usb], '--', color=style.COLORS_STD[2])
        plt.annotate(style.latexT("LSB"),
                     xy=(np.mean(xs[lsb]), 2),
                     horizontalalignment='center', verticalalignment='center')
        plt.annotate(style.latexT("USB"),
                     xy=(np.mean(xs[usb]), 2),
                     horizontalalignment='center', verticalalignment='center')
        plt.legend(loc='center', prop={"size":6})
        plt.xlabel(style.latexT("Frequency [\\si{\giga\hertz}]"))
        plt.ylabel(style.latexT("Flux density  [\\si{\watt\per\meter\squared}]"))
        if USE_PDF:
            plt.savefig("thin_film_beam_splitter_detailed.pdf", bbox_inches='tight')
        else:
            plt.show()

    # Compute folded.
    x_folded = xs[usb] - lo_freq / 1.e9
    y_folded_h = lo_h[lsb] + sky_h[lsb] + lo_h[usb] + sky_h[usb]
    y_folded_v = lo_v[lsb] + sky_v[lsb] + lo_v[usb] + sky_v[usb]

    # Plot folded.

    # With my previous model, I used to see a beat.  The folded signal was not
    # at the same period as the original signal.  I was saying that this was
    # because there were actually two lo-mixer cavities: one using the near
    # side, and one using the far side of the beam splitter.  Each cavity had
    # its own period, and once I was folding it would somehow show drastically.
    # This was, I believe, an error on my part.  Indeed, I was adding the LSB
    # and USB fields, then raising it to a power.  I believe now that this is
    # wrong: there is no reason for the LSB and USB fields to be phase-locked,
    # therefore they do not add coherently. I must raise them to power before
    # adding them.  When doing that, there is no obvious beat.  HOWEVER, when
    # using pathological dimensions for the 'thin film' (like, 20 cm thick) and
    # a broad enough frequency range, you can see this beat.  So my model DOES
    # take into account both sides of the thin film, it's just that it does not
    # show much.  It's almost too bad, it was a neat trick.
    with style.latex(width, 1):
        style.pretty()
        plt.figure(1)
        plt.subplot(2, 1, 1)
        plt.plot(x_folded, y_folded_h, color=style.COLORS_STD[0], label=style.latexT("H"))
        plt.ylim((8.7, 8.9))
        plt.title(style.latexT("LO + sky, folded."), fontsize=10)
        plt.ylabel(style.latexT("Flux density  [\\si{\watt\per\meter\squared}]"))
        plt.legend(prop={"size":6})

        plt.subplot(2, 1, 2)
        plt.plot(x_folded, y_folded_v, color=style.COLORS_STD[0], label=style.latexT("V"))
        plt.ylim((2.6, 2.8))
        plt.xlabel(style.latexT("Intermediate frequency [\\si{\giga\hertz}]"))
        plt.ylabel(style.latexT("Flux density  [\\si{\watt\per\meter\squared}]"))
        plt.legend(prop={"size":6})

        if USE_PDF:
            plt.savefig("thin_film_beam_splitter_folded.pdf", bbox_inches='tight')
        else:
            plt.show()

    # Compute FFT.
    n = len(x_folded)  # Number of samples.
    h = np.hanning(n)
    y_fft_h = np.abs(np.fft.rfft(y_folded_h * h))
    y_fft_v = np.abs(np.fft.rfft(y_folded_v * h))
    w = (np.max(x_folded) - np.min(x_folded)) * 1e9  # Width.
#     n = len(xs[usb])
#     h = np.hanning(n)
#     y_fft_h = np.abs(np.fft.rfft(lo_h[usb]))  # * h))
#     y_fft_v = np.abs(np.fft.rfft(lo_v[usb]))  # * h))
#     w = (np.max(xs[usb]) - np.min(xs[usb])) * 1e9  # Width.
    s = w / n  # Sample spacing.
    x_fft = np.fft.fftfreq(n, s)[:len(y_fft_h)]  # Only positive frequencies.
    x_fft = 1 / x_fft / 1e6  # x scale in SW period.

    # Plot FFT.

    # What would it take to see the 10 micrometer beam splitter?
    # d_0 = 1.9999995  m
    # d_1 = 1.0000005  m
    # T_0 = c / 2d_0  Hz
    # T_1 = c / 2d_1  Hz
    # F_0 = 2d_0 / c  Hz-1  # This is the frequency of the FFT, in Hz-1.
    # F_1 = 2d_1 / c  Hz-1
    # \Delta F = F_1 - F_0 = 2(0.000001)/c  Hz-1
    # \Delta F = 1 / B  # With B the bandwith.
    # 1 / B = 0.000002 / c
    # B = c / 0.000002  =  1.5e14  Hz
    # Well, I will not be having such a bandwidth any time soon so the two peaks
    # due to the two distances will not show.
    # Our B equals 4 GHz.
    # c / B = 0.075 m.
    # 2d = 0.075 ; d = 0.0375
    # With 4 GHz of bandwidth I should expect to resolve differences of 3.7 mm.
    # So if I make the beam splitter 1 cm thick, I should be able to see it on the FFT
    # as a second peak.
    # Well, it does not work.  Even if I use 10 cm.  Even if I remove the Hanning window.
    # The peak does move to the higher periods, but I do not see a second peak.
    # Maybe it is much weaker?  Use semilogy.  Still not.
    # Maybe I should try on the non-folded ?  Still not.
    # Maybe I am wrong to think that I should see two peaks?

    # The thicker the film, the greater the period of the single peak.  This
    # means that the cavity seems shorter.  Is that at least consistent with the
    # fact that the speed of light is smaller in the film?
    # The spacing between the resonant frequencies is proportional to c:
    #     f = N c / 2d, with N an integer.
    # The period is c / 2d: distance between two resonant frequencies.

    # So a slower light should reduce the period, not increase it.  Indeed,
    # reducing the speed is kinda like increasing the distance. Then why does my
    # peak move to higher periods as the thickness of the film increase? Higher
    # periods suggests that the distance is reduced.

    # Well, there is one distance that is reduced when the thickness increases,
    # that is the distance to the near side.  Does it match?  Standard is a 1 m
    # cavity, creating a period of 150 MHz.  If I make it a 90 cm cavity I
    # should get 166.6667 MHz.

    # The film must have a thickness h which, when seen at 45 degrees, appear to
    # be l=10 cm long.  h and l are linked by a cosine and h is smaller than l,
    # so I say h = l cos 45, h = 1/sqrt(2) / 10.

    # Once the model ran, I get a peak at 166.6.  The resolution is not high, but
    # it is high enough to tell me I hit at the right first decimal.

    # So what we mostly see is a reflection on the near side.  What about the
    # far side? How come it has so little effect?  Especially because the film
    # is mostly transparent, so there should be quite a bit of power hitting the
    # far side.  Then a bit of that power comes to the near side and is transmitted.
    # Because the transmissions are close to 1, I'd expect that the power in the near
    # and the far contributions to be very close.

    # SOLVED IT !  My problem was that my film had an absorption coefficient.
    # That small imaginary component to n2 does not matter much for a 10 micrometer
    # film, but it totally killed all transmission in a 10 cm film.  As a result, all
    # I was seeing was the near side, and 10^-14 of the far side.  If I want to see all
    # the cavities, I must make n2 a real number.  Then I see many peaks, not just 2,
    # because each double reflection brings its own cavity length.

    with style.latex(width, 1):
        style.pretty()
        plt.figure(2)
        plt.subplot(2, 1, 1)
        plt.semilogy(x_fft[10:], y_fft_h[10:], color=style.COLORS_STD[0], label=style.latexT("H"))
        plt.title(style.latexT("LO + sky, folded."), fontsize=10)
        plt.ylabel(style.latexT("FFT of flux density  [arbitrary]"))
#         plt.xlim((50, 250))
        plt.legend(prop={"size":6})

        plt.subplot(2, 1, 2)
        plt.semilogy(x_fft[10:], y_fft_v[10:], color=style.COLORS_STD[0], label=style.latexT("V"))
        plt.xlabel(style.latexT("Period [\\si{\mega\hertz}]"))
        plt.ylabel(style.latexT("FFT of flux density  [arbitrary]"))
#         plt.xlim((50, 250))
        plt.legend(prop={"size":6})
        if USE_PDF:
            plt.savefig("thin_film_beam_splitter_folded_fft.pdf", bbox_inches='tight')
        else:
            plt.show()

    # Sideband ratio.
    sbr_lo_h = lo_h[usb] / (lo_h[usb] + lo_h[lsb])
    sbr_lo_v = lo_v[usb] / (lo_v[usb] + lo_v[lsb])
    sbr_sky_h = sky_h[usb] / (sky_h[usb] + sky_h[lsb])
    sbr_sky_v = sky_v[usb] / (sky_v[usb] + sky_v[lsb])
    print "Sky H sbr stddev: %f." % np.std(sbr_sky_h)
    print "Sky V sbr stddev: %f." % np.std(sbr_sky_v)
    with style.latex(width):
        style.pretty()
        plt.figure(3)
        plt.plot(x_folded, sbr_lo_h, '-', label=style.latexT("LO H"), color=style.COLORS_STD[1])
        plt.plot(x_folded, sbr_lo_v, '--', label=style.latexT("LO V"), color=style.COLORS_STD[1])
        plt.plot(x_folded, sbr_sky_h, '-', label=style.latexT("Sky H"), color=style.COLORS_STD[2])
        plt.plot(x_folded, sbr_sky_v, '--', label=style.latexT("Sky V"), color=style.COLORS_STD[2])
        plt.xlabel(style.latexT("Intermediate frequency [\\si{\giga\hertz}]"))
        plt.ylabel(style.latexT("USB / (LSB + USB) [1]"))
        plt.legend(loc="center right", prop={"size":6})
        if USE_PDF:
            plt.savefig("thin_film_beam_splitter_sbr.pdf", bbox_inches='tight')
        else:
            plt.show()