예제 #1
0
def questao_10():
    # -----------------------------------------------------------
    # Exercício 10
    # -----------------------------------------------------------
    N = 99
    # Resposta ao impulso
    h = [0, 1, 2, 3, 4, 4, 3, 2, 1, 0]

    channel = Filter(h=h)
    bin_gen = BinaryHardLimiter()

    channel_eq = ChannelEqualization(bin_gen,
                                     channel,
                                     N=N,
                                     input_delay=int((len(h) + N + 1) / 2),
                                     noise=GaussianNoise(std=np.sqrt(1e-2)))

    mu_max = 1 / (N + 1)
    E_hist, W_hist = lms(channel_eq,
                         0.006 * mu_max,
                         N + 1,
                         max_runs=50,
                         max_iter=50000)

    b_adap = np.mean(W_hist, axis=0)[-1, :].conj()
    mse = np.mean(np.abs(E_hist)**2, axis=0)

    plt.figure()
    plt.plot(10 * np.log10(mse))
    plt.xlabel('iteração')
    plt.ylabel('MSE, dB')
    # plt.savefig('ex10-mse.pdf', dpi=300, bbox_inches='tight')
    plt.show()

    w_adap, h_adap = signal.freqz(b_adap)
    w_0, h_0 = signal.freqz(h)

    plt.plot(w_0 / np.pi, 20 * np.log10(np.abs(h_0)), label='sistema')
    plt.plot(w_adap / np.pi,
             20 * np.log10(np.abs(h_adap)),
             'r--',
             label='filtro adap.')
    plt.plot(w_0 / np.pi, 20 * np.log10(np.abs(h_0 * h_adap)), label='eq.')
    plt.xlabel('frequência, rad/s')
    plt.ylabel('magnitude, dB')
    plt.legend()
    plt.ylim([-100, 30])
    # plt.savefig('ex10-eq.pdf', dpi=300, bbox_inches='tight')

    plt.plot(
        signal.convolve(np.mean(np.mean(W_hist, axis=0)[2700:], axis=0), h))
    plt.xlabel('amostra')
    plt.ylabel('amplitude')
예제 #2
0
    def __init__(self):

        self.seed = args.seed
        np.random.seed(self.seed)

        # Init gym env and set the env seed
        self.env = gym.make(args.env)
        self.env.seed(self.seed)
        self.state_dim = self.env.observation_space.shape[0]
        self.action_dim = self.env.action_space.shape[0]
        self.max_action = int(self.env.action_space.high[0])

        # Init parameters
        self._init_parameters()

        self.filter = Filter(self.state_dim)
        self.policy = Policy(self.state_dim, self.action_dim, args)
        self.noise = Noise(self.policy.w_policy.size, args)
        self.ddpg = DDPG(self.state_dim, self.action_dim, self.max_action, args)
예제 #3
0
파일: ars.py 프로젝트: marsXyr/GESRL
    def __init__(self):

        self.seed = args.seed
        np.random.seed(self.seed)

        # Init gym env and set the env seed
        self.env = gym.make(args.env)
        self.env.seed(self.seed)
        self.state_dim = self.env.observation_space.shape[0]
        self.action_dim = self.env.action_space.shape[0]

        # Init parameters
        self._init_parameters()

        # Init filter, normalizes the input states by tracking the mean and std of states.
        self.filter = Filter(self.state_dim)
        # Init policy, we use linear policy here
        self.policy = Policy(self.state_dim, self.action_dim, args)
        # Init the noise generator
        self.noise = Noise(self.policy.w_policy.shape)
예제 #4
0
 def __init__(self, filter_obj=None):
     if not filter_obj:
         filter_obj = Filter()
     self.filter_obj = filter_obj
     self.post2freq = {}
     self.resp2freq = {}
예제 #5
0
        data = self.load(coarse_fp)
        self.post2freq, self.resp2freq = self.get_data_frequency(data)
        del data

        worker = Worker(coarse_fp, tgt_fp, self.global_preprocess)
        mp = MultiProcessor(worker, pid_num)
        mp.run()
        print("All Global Processes Done.")
        worker.merge_result(keep_pid_file=keep_pid_file)


if __name__ == '__main__':
    os.system("mkdir -p logging")
    pid_num = 25
    P = Preprocessor()
    filter_obj = Filter(logging_fp="./logging/filter_all.log")
    P = Preprocessor(filter_obj)
    src_fp, tgt_fp = 'test/Weibo_24_35.sample.10000', 'test/weibo_corpus'
    # src_fp, tgt_fp = '/home/xiaohe_li/0_data/Weibo_24_35.raw.out', '/home/xiaohe_li/0_data/weibo_whole.corpus'
    P.run_mp(src_fp, tgt_fp, pid_num, keep_pid_file=False)

    # data = P.load(src_fp)
    # data = P.run(data)
    # P.save('corpus/weibo_corpus', data)

    print("Begin Cut Sentences.")
    cutted_fp = tgt_fp + '.cutted'
    cutter = Cutter(method='pkuseg')
    worker = Worker(tgt_fp, cutted_fp, cutter.cut_data_line)
    mp = MultiProcessor(worker, pid_num)
    mp.run()
예제 #6
0
 def __init__(self):
     with open('data/config.json') as config_file:
         self.config = json.load(config_file)
     self.filters_config = self.config["filters"]
     self.filter = Filter()
예제 #7
0
def questao_25():
    # -----------------------------------------------------------
    # Exercício 25
    # -----------------------------------------------------------
    NFFT = 1024
    N = 19
    SNR = 20
    h = [.34 - .21 * 1j, .87 + .43 * 1j, .34 - .27 * 1j]
    qam = QAM()
    channel = Filter(h, [1.])
    data = ChannelEqualization(qam,
                               channel,
                               N=N,
                               input_delay=int((N + len(h)) / 2),
                               noise=GaussianNoise,
                               SNR=SNR)
    a = qam(100000, )
    A = toeplitz(np.hstack([a[0], np.zeros(N)]), a)
    R = A.dot(A.T.conj()) / 100000
    trR = R.trace()
    mu_max = 1 / trR
    MSE, W = [], []
    for mu in (mu_max / 2, mu_max / 10, mu_max / 50):
        E_hist, W_hist = lms(data,
                             mu,
                             N + 1,
                             max_runs=50,
                             max_iter=5000,
                             dtype='complex128',
                             print_every=-1)

        MSE.append(np.mean(np.abs(E_hist)**2, axis=0))
        W.append(np.mean(W_hist, axis=0))
    plt.figure()
    for mse, name in zip(
            MSE,
        ['$\\mu_{\\max}/2$', '$\\mu_{\\max}/10$', '$\\mu_{\\max}/50$']):
        plt.plot(10 * np.log10(mse), label=name)
    plt.legend()
    plt.xlabel('Iteração')
    plt.ylabel('MSE (em dB)')
    # plt.savefig('ex25-mse-{}.pdf'.format(N+1), dpi=300, bbox_inches='tight')
    plt.show()

    b_adap = np.mean(W_hist, axis=0)[-1, :].conj()
    mse = np.mean(np.abs(E_hist)**2, axis=0)

    plt.figure()
    freqs = np.linspace(-1, 1, NFFT)
    plt.plot(freqs, 20 * np.log10(fft(h, n=NFFT)), label='Canal')
    plt.plot(freqs,
             20 * np.log10(fft(b_adap, n=NFFT)),
             'r--',
             label='Equalizador')
    plt.plot(freqs,
             20 * np.log10(np.abs(fft(np.convolve(b_adap, h), n=NFFT))),
             'y--',
             label='Canal equalizado')
    plt.xlim([-1, 1])
    plt.legend()
    plt.xlabel('Frequência normalizada')
    plt.ylabel('Magnitude (em dB)')
    plt.show()
    # plt.savefig('figs/ex25-freq-{}.pdf'.format(N+1), dpi=300, bbox_inches='tight')

    plt.figure()
    plt.plot(signal.convolve(b_adap, h))
    plt.xlabel('Amostra')
    plt.ylabel('Amplitude')
    plt.show()
    # plt.savefig('ex25-tempo-{}.pdf'.format(N+1), dpi=300, bbox_inches='tight')

    tx = qam(100)
    rx = signal.lfilter(h, [1.], tx)
    noise = GaussianNoise(std=np.sqrt(rx.var() / (2 * SNR)), complex=True)(100)
    rx += noise
    rx_eq = np.convolve(rx, b_adap)

    plt.figure()
    plt.plot(np.real(rx), np.imag(rx), 'o', label='Recebido')
    plt.plot(np.real(rx_eq), np.imag(rx_eq), 'o', label='Equalizado')
    plt.plot(1, 1, 'ro', label='Alvo')
    plt.plot(1, -1, 'ro')
    plt.plot(-1, 1, 'ro')
    plt.plot(-1, -1, 'ro')
    plt.legend()
    plt.xlabel('Real')
    plt.ylabel('Imaginário')
    plt.show()
예제 #8
0
import numpy as np
import cv2 as cv
import matplotlib.pyplot as plt
import matplotlib.animation as animation
from image_processing import processing
from sliding_window import sliding_window
from scipy.optimize import least_squares
from utils.calculate import get_linear_function
from utils.filter import Filter
from utils.low_pass_filter import LowPassFilter
from utils.calculate import get_linear_function

f_cut = 100
freq = 100000

filter_left = Filter(f_cut=f_cut, freq=freq, num_data=3)
filter_right = Filter(f_cut=f_cut, freq=freq, num_data=3)
filter_deg = Filter(f_cut=f_cut, freq=freq, num_data=1)
filter_deg2 = LowPassFilter(0.75)

filter_coef_left = None
filter_coef_right = None

heading_deg = 0


def rint(point):
    return np.rint(point).astype(np.int32)


script_dir = os.path.dirname(__file__)