Exemple #1
0
def plot_spectrum(f,
                  p,
                  cen=0.0,
                  span=None,
                  dbm=False,
                  filename=None,
                  title='Spectrum'):
    """Plot average power in dBm per Hz"""

    if not span:
        mask = (f != 0) | (f == 0)
    else:
        mask = (f <= span / 2) & (f >= -span / 2)
    if dbm:
        plt.plot(f[mask], IQBase.get_dbm(p[mask]))
    else:
        plt.plot(f[mask], p[mask])
    plt.xlabel("Delta f [Hz] @ {}".format(get_eng_notation(cen, 'Hz')))
    plt.title(title)
    if dbm:
        plt.ylabel('Power Spectral Density [dBm/Hz]')
    else:
        plt.ylabel('Power Spectral Density')

    plt.grid(True)
    if filename is not None:
        plt.savefig(filename + '.png')  # , bbox_inches='tight')
        plt.close()
Exemple #2
0
def plot_spectrogram(xx, yy, zz, cen=0.0, cmap=cm.jet, dpi=300, dbm=False, filename=None, title='Spectrogram'):
    """
    Plot the calculated spectrogram
    :param xx:
    :param yy:
    :param zz:
    :param cen:
    :return:
    """
    delta_f = np.abs(np.abs(xx[0, 1]) - np.abs(xx[0, 0]))
    delta_t = np.abs(np.abs(yy[1, 0]) - np.abs(yy[0, 0]))
    if dbm:
        sp = plt.pcolormesh(xx, yy, IQBase.get_dbm(zz), cmap=cmap)
    else:
        sp = plt.pcolormesh(xx, yy, zz, cmap=cmap)
    cb = plt.colorbar(sp)
    plt.xlabel(
        "Delta f @ {} (resolution = {})".format(get_eng_notation(cen, unit='Hz'), get_eng_notation(delta_f, unit='Hz')))
    plt.ylabel('Time [sec] (resolution = {})'.format(
        get_eng_notation(delta_t, 's')))
    plt.title(title)
    if dbm:
        cb.set_label('Power Spectral Density [dBm/Hz]')
    else:
        cb.set_label('Power Spectral Density')

    if filename is not None:
        plt.savefig(filename + '.png', dpi=dpi, bbox_inches='tight')
        plt.close()
Exemple #3
0
def write_spectrum_to_csv(ff, pp, filename, center=0):
    a = np.concatenate((ff, pp, IQBase.get_dbm(pp)))
    b = np.reshape(a, (3, -1)).T
    np.savetxt(
        filename,
        b,
        header='Delta f [Hz] @ {:.2e} [Hz]|Power [W]|Power [dBm]'.format(
            center),
        delimiter='|')
Exemple #4
0
def plot_frame_power(yy, frame_power):
    """
    Plot frame power, i.e. trapezoid along each time frame
    :param yy:
    :param frame_power:
    :return:
    """
    plt.plot(yy[:, 0], IQBase.get_dbm(frame_power))
    plt.ylabel('Power [dBm]')
    plt.xlabel('Time [sec]')
    plt.title('Frame power')
Exemple #5
0
def plot_frame_power(yy, frame_power):
    """
    Plot frame power, i.e. trapezoid along each time frame
    :param yy:
    :param frame_power:
    :return:
    """
    plt.plot(yy[:, 0], IQBase.get_dbm(frame_power))
    plt.ylabel('Power [dBm]')
    plt.xlabel('Time [sec]')
    plt.title('Frame power')
Exemple #6
0
def plot_dbm_per_hz(f, p, cen=0.0, span=None, filename='', to_file=False):
    """Plot average power in dBm per Hz"""

    if not span:
        mask = (f != 0) | (f == 0)
    else:
        mask = (f <= span / 2) & (f >= -span / 2)

    plt.plot(f[mask], IQBase.get_dbm(p[mask]))
    plt.xlabel("Delta f [Hz] @ {}".format(get_eng_notation(cen, 'Hz')))
    plt.title(filename)
    plt.ylabel("Power Spectral Density [dBm/Hz]")
    plt.grid(True)
    if to_file:
        plt.savefig(filename)
        plt.close()
Exemple #7
0
def plot_dbm_per_hz(f, p, cen=0.0, span=None, filename='', to_file=False):
    """Plot average power in dBm per Hz"""

    if not span:
        mask = (f != 0) | (f == 0)
    else:
        mask = (f <= span / 2) & (f >= -span / 2)

    plt.plot(f[mask], IQBase.get_dbm(p[mask]))
    plt.xlabel("Delta f [Hz] @ {}".format(get_eng_notation(cen, 'Hz')))
    plt.title(filename)
    plt.ylabel("Power Spectral Density [dBm/Hz]")
    plt.grid(True)
    if to_file:
        plt.savefig(filename)
        plt.close()
Exemple #8
0
def plot_spectrogram(xx,
                     yy,
                     zz,
                     cen=0.0,
                     cmap=cm.jet,
                     dpi=300,
                     dbm=False,
                     filename=None,
                     title='Spectrogram'):
    """
    Plot the calculated spectrogram
    :param xx:
    :param yy:
    :param zz:
    :param cen:
    :return:
    """
    delta_f = np.abs(np.abs(xx[0, 1]) - np.abs(xx[0, 0]))
    delta_t = np.abs(np.abs(yy[1, 0]) - np.abs(yy[0, 0]))
    if dbm:
        sp = plt.pcolormesh(xx, yy, IQBase.get_dbm(zz), cmap=cmap)
    else:
        sp = plt.pcolormesh(xx, yy, zz, cmap=cmap)
    cb = plt.colorbar(sp)
    plt.xlabel("Delta f @ {} (resolution = {})".format(
        get_eng_notation(cen, unit='Hz'), get_eng_notation(delta_f,
                                                           unit='Hz')))
    plt.ylabel('Time [sec] (resolution = {})'.format(
        get_eng_notation(delta_t, 's')))
    plt.title(title)
    if dbm:
        cb.set_label('Power Spectral Density [dBm/Hz]')
    else:
        cb.set_label('Power Spectral Density')

    if filename is not None:
        plt.savefig(filename + '.png', dpi=dpi, bbox_inches='tight')
        plt.close()