Exemplo n.º 1
0
def task_5(sequence_length, phase_filtering, low, high):
    polyharmonic_sequence = generate_polyharmonic_sequence(sequence_length)
    direct_transformer = DirectFourierTransformer(polyharmonic_sequence)
    amplitude_spectrum = direct_transformer.get_amplitude_spectrum()
    phase_spectrum = [
        x if amplitude_spectrum[i] > phase_filtering else 0
        for i, x in enumerate(direct_transformer.get_phase_spectrum())
    ]
    filtered = filter_spectrum(Spectrum(amplitude_spectrum, phase_spectrum),
                               low, high)
    restored = InverseFourierTransformer(
        filtered.amplitude, filtered.phase).restore_polyharmonic()

    drawer = GraphDrawer()
    drawer.add_plot(
        Graph(range(sequence_length), polyharmonic_sequence,
              "Original sequence"))
    drawer.add_stem(
        Graph(range(sequence_length), amplitude_spectrum,
              "Amplitude spectrum"))
    drawer.add_stem(
        Graph(range(sequence_length), phase_spectrum, "Phase spectrum"))
    drawer.add_stem(
        Graph(range(sequence_length), filtered.amplitude,
              "Filtered amplitude"))
    drawer.add_stem(
        Graph(range(sequence_length), filtered.phase, "Filtered phase"))
    drawer.add_plot(
        Graph(range(sequence_length), restored, "Restored filtered"))
    drawer.draw()
    drawer.show()
Exemplo n.º 2
0
def task_4(sequence_length, phase_filtering):
    polyharmonic_sequence = generate_polyharmonic_sequence(sequence_length)
    fast_transformer = FastFourierTransformer(polyharmonic_sequence)
    amplitude_spectrum = fast_transformer.get_amplitude_spectrum()
    phase_spectrum = [
        x if amplitude_spectrum[i] > phase_filtering else 0
        for i, x in enumerate(fast_transformer.get_phase_spectrum())
    ]
    restored_sequence = InverseFourierTransformer(
        amplitude_spectrum, phase_spectrum).restore_polyharmonic(True)

    drawer = GraphDrawer()
    drawer.add_plot(
        Graph(range(sequence_length), polyharmonic_sequence,
              "Original sequence"))
    drawer.add_stem(
        Graph(range(sequence_length), amplitude_spectrum,
              "Amplitude spectrum"))
    drawer.add_stem(
        Graph(range(sequence_length), phase_spectrum, "Phase spectrum"))
    drawer.add_plot(
        Graph(range(sequence_length), restored_sequence, "Restored sequence"))
    drawer.draw()
    drawer.show()
Exemplo n.º 3
0
def task_5(sequence_length, phase_filtering):
    parser = argparse.ArgumentParser()
    parser.add_argument('--low',
                        action='store',
                        required=False,
                        help='lower bound of filtering',
                        dest='low',
                        type=int,
                        default=None)
    parser.add_argument('--high',
                        action='store',
                        required=False,
                        help='higher bound of filtering',
                        dest='high',
                        type=int,
                        default=None)
    args = parser.parse_known_args()[0]

    polyharmonic_sequence = generate_polyharmonic_sequence(sequence_length)
    direct_transformer = DirectFourierTransformer(polyharmonic_sequence)
    amplitude_spectrum = direct_transformer.get_amplitude_spectrum()
    phase_spectrum = [
        x if amplitude_spectrum[i] > phase_filtering else 0
        for i, x in enumerate(direct_transformer.get_phase_spectrum())
    ]
    filtered = filter_spectrum(Spectrum(amplitude_spectrum, phase_spectrum),
                               args.low, args.high)
    restored = InverseFourierTransformer(
        filtered.amplitude, filtered.phase).restore_polyharmonic()

    drawer = GraphDrawer()
    drawer.add_plot(
        Graph(range(sequence_length), polyharmonic_sequence,
              "Original sequence"))
    drawer.add_stem(
        Graph(range(sequence_length), amplitude_spectrum,
              "Amplitude spectrum"))
    drawer.add_stem(
        Graph(range(sequence_length), phase_spectrum, "Phase spectrum"))
    drawer.add_stem(
        Graph(range(sequence_length), filtered.amplitude,
              "Filtered amplitude"))
    drawer.add_stem(
        Graph(range(sequence_length), filtered.phase, "Filtered phase"))
    drawer.add_plot(
        Graph(range(sequence_length), restored, "Restored filtered"))
    drawer.draw()
    drawer.show()