Ejemplo n.º 1
0
def plot_dft_abs_phase(signal: np.array.__class__,
                       frequency_discretization=1,
                       is_in_db=False):
    spectrum = fftshift(fft(signal))

    fft_frequencies = fftshift(
        fftfreq(signal.shape[0], 1 / frequency_discretization))

    abs_values = np.abs(spectrum)
    if is_in_db:
        abs_values = power_samples_in_db(abs_values)

    plt.figure()

    plt.subplot(211)
    plt.plot(fft_frequencies, abs_values, color='b')
    plt.ylabel('Amplitude [dB]', color='b')
    plt.xlabel('Frequency')
    plt.grid()

    plt.subplot(212)
    plt.plot(fft_frequencies, np.angle(spectrum), color='g')
    plt.ylabel('Phase [rad]', color='g')
    plt.xlabel('Frequency')
    plt.grid()

    plt.show()
Ejemplo n.º 2
0
def ktoi(data,axis=-1):
    if (axis == -1):
        ax = fth.arange(0,data.ndim)
    else:
        ax = axis

    return fth.fftshift(ft.ifftn(fth.ifftshift(data,axes=ax),axes=ax),axes=ax)
Ejemplo n.º 3
0
def ktoi(data, axis=-1):
    if (axis == -1):
        ax = fth.arange(0, data.ndim)
    else:
        ax = axis

    return fth.fftshift(ft.ifftn(fth.ifftshift(data, axes=ax), axes=ax),
                        axes=ax)
Ejemplo n.º 4
0
def plot_dft_real_image(signal: np.array.__class__,
                        frequency_discretization=1,
                        is_in_db=False):

    spectrum = fftshift(fft(signal))

    if is_in_db:
        spectrum = power_samples_in_db(
            np.real(spectrum)) + 1j * power_samples_in_db(np.imag(spectrum))

    fft_frequencies = fftshift(
        fftfreq(signal.shape[0], 1 / frequency_discretization))
    plt.subplot(211)
    plt.plot(fft_frequencies, np.real(spectrum))
    plt.subplot(212)
    plt.plot(fft_frequencies, np.imag(spectrum))
    # plt.ion()
    plt.show()
Ejemplo n.º 5
0
def power_spectrum(pref, peak_val=1.0):
    """
    Computes the FFT power spectrum of the orientation preference.
    """
    fft_spectrum = abs(fftshift(fft2(pref-0.5, s=None, axes=(-2,-1))))
    fft_spectrum = 1 - fft_spectrum # Inverted spectrum by convention
    zero_min_spectrum = fft_spectrum - fft_spectrum.min()
    spectrum_range = fft_spectrum.max() - fft_spectrum.min()
    normalized_spectrum = (peak_val * zero_min_spectrum) / spectrum_range
    return normalized_spectrum
Ejemplo n.º 6
0
def power_spectrum(pref, peak_val=1.0):
    """
    Computes the FFT power spectrum of the orientation preference.
    """
    fft_spectrum = abs(fftshift(fft2(pref - 0.5, s=None, axes=(-2, -1))))
    fft_spectrum = 1 - fft_spectrum  # Inverted spectrum by convention
    zero_min_spectrum = fft_spectrum - fft_spectrum.min()
    spectrum_range = fft_spectrum.max() - fft_spectrum.min()
    normalized_spectrum = (peak_val * zero_min_spectrum) / spectrum_range
    return normalized_spectrum
Ejemplo n.º 7
0
    def _process(self, sheetview):
        cr = sheetview.cyclic_range
        data = sheetview.data if cr is None else sheetview.data/cr
        fft_spectrum = abs(fftshift(fft2(data - 0.5, s=None, axes=(-2, -1))))
        fft_spectrum = 1 - fft_spectrum # Inverted spectrum by convention
        zero_min_spectrum = fft_spectrum - fft_spectrum.min()
        spectrum_range = fft_spectrum.max() - fft_spectrum.min()
        normalized_spectrum = (self.p.peak_val * zero_min_spectrum) / spectrum_range

        l, b, r, t = sheetview.bounds.lbrt()
        density = sheetview.xdensity
        bb = BoundingBox(radius=(density/2)/(r-l))

        return [SheetView(normalized_spectrum, bb,
                          metadata=sheetview.metadata,
                          label=sheetview.label+' FFT Power Spectrum')]
Ejemplo n.º 8
0
def OR_power_spectrum(image, toarray=True, peak_val=1.0):
    """ Taken from current topographica code. Applies FFT power
        spectrum to hue channel of OR maps (ie orientation). Accepts
        RGB images or arrays."""

    # Duplicates the line of code in command/pylabplot.py and tkgui.
    # Unfortunately, there is no sensible way to reuse the existing code
    if not toarray: peak_val = 255
    if not image.shape[0] % 2:
        hue = image[:-1, :-1]
    else:
        hue = image
    fft_spectrum = abs(fftshift(fft2(hue - 0.5, s=None, axes=(-2, -1))))
    fft_spectrum = 1 - fft_spectrum  # Inverted spectrum by convention
    zero_min_spectrum = fft_spectrum - fft_spectrum.min()
    spectrum_range = fft_spectrum.max() - fft_spectrum.min()
    normalized_spectrum = (peak_val * zero_min_spectrum) / spectrum_range

    if not toarray:
        return Image.fromarray(normalized_spectrum.astype('uint8'), mode='L')
    return normalized_spectrum
Ejemplo n.º 9
0
 def __call__(self, data, **params):
     p = ParamOverrides(self, params)
     fft_plot = 1 - np.abs(fftshift(fft2(data - 0.5, s=None,
                                         axes=(-2, -1))))
     return super(fftplot, self).__call__(fft_plot, **p)
Ejemplo n.º 10
0
 def __call__(self, data, **params):
     p = ParamOverrides(self, params)
     fft_plot = 1 - np.abs(fftshift(fft2(data - 0.5, s=None, axes=(-2, -1))))
     return super(fftplot, self).__call__(fft_plot, **p)
Ejemplo n.º 11
0
# coding=gbk
# coding£ºutf-8
'''

 @Created on 2018Äê1ÔÂ26ÈÕ ÏÂÎç2:43:08
 @author: Administrator
'''
from myFunc import mfft, mifft
from math import *
from numpy import *
# import numpy as np
from matplotlib import *
import matplotlib.pyplot as plt
from numpy.dual import fft
from numpy.fft.helper import fftshift
from numpy.core.function_base import linspace

x = linspace(-pi, pi, 100)
print(type(x))
print(shape(x))
y = random.random(size=(1, 10))
print(type(y))
print(type(shape(y)))
print(type(shape(y)))
f = sin(x)
F = fftshift(fft(f))
#F = mfft(f)
plt.subplot(121)
plt.plot(abs(F))
plt.show()
Ejemplo n.º 12
0
from numpy.fft.helper import fftfreq, fftshift
from scipy.fftpack import ifft, ifftshift
from scipy.signal.signaltools import convolve

from WiSim.plot_utils import plot_dft_real_image, plot_dft_abs_phase
from WiSim.signal_source import SignalSource
from WiSim.utils import complex_randn, db_to_power

# Construct signal
frequency_discretization = 600 * 10 ** 6

period_discretization = 1 / frequency_discretization

window_length = int(1024/2)

fft_frequencies = fftshift(fftfreq(window_length, period_discretization))

signal_borders = (70 * 10 ** 6, 230 * 10 ** 6)
signal_positions = (fft_frequencies > signal_borders[0]) & (fft_frequencies < signal_borders[1])
n_signal_positions = sum(signal_positions)

random_component = complex_randn((n_signal_positions,))
coefficients = np.arange(1, random_component.shape[0] + 1)
random_component *= coefficients
signal = np.zeros((window_length,), dtype=np.complex128)
signal[signal_positions] = random_component


signal = ifft(ifftshift(signal))

# Adding noise to the signal