def AddConstellation(self, evt): pos = self.GetPositionTuple() pos = (pos[0]+50, pos[1]+400) self.constellation = constellation(parent=self, pos=pos) self.constellation.Show(True)
def simulate(M=4, num_syms=10, sps=8, pulse_type='square'): samp_rate = 1 bps = log2(M) const = c.constellation(M, 'qam'); #pulse = f.gen(2500, sps, 0.35, 10*11*sps, pulse_type) rolloff = 0.1 pulse = gr.firdes.low_pass(1, 1, 1.0/sps, rolloff) print pulse ############################# # Logs ############################# N0 = int(len(pulse)-1) print "#############################" print "Pulse Len:", len(pulse) print "N0:", N0 print "#############################" ############################# # Transmitter ############################# # Create Symbol Chunks tx_chunks = array([r.choice(range(M)) for i in range(num_syms)]) # Create Symbols tx_syms = const.vec[tx_chunks] # Upsampling tx_upsamp = zeros(num_syms*sps - (sps-1), dtype=complex) tx_upsamp[::sps] = tx_syms # Filtering with pulse shape tx_sig = convolve(tx_upsamp, pulse) #tx_sig = tx_sig[0:num_syms*sps] ############################# # Channel ############################# rx_sig = tx_sig ############################# # Receiver ############################# # Flip Left-Right pulse = pulse[::-1] # Qual a diferenca de descontar N0 antes da convolucao de depois? rx_filtered = convolve(rx_sig, pulse) rx_sym = rx_filtered[N0:N0+num_syms*sps:sps] #rx_filtered = rx_sig #rx_sym = rx_filtered[:-1:sps] ############################# # Plots ############################# syms_to_plot = 400 sig_to_plot = syms_to_plot*sps plot_upsampling = False plot_syms = True plot_sig = False plot_pulse = True p.figure() p.subplot(211) vec = convolve(pulse, pulse) p.stem(range(len(vec)), vec) p.subplot(212) p.plot(abs(fftshift(fft(vec)))) if plot_upsampling: p.figure() p.plot(real(tx_upsamp[0:sig_to_plot]), '-o') p.plot(imag(tx_upsamp[0:sig_to_plot]), '-o') p.xlabel("Upsampled Symbols") if plot_pulse: p.figure() p.subplot(211) p.stem(range(len(pulse)), pulse) p.subplot(212) p.plot(abs(fftshift(fft(pulse)))) p.xlabel("Pulse Shape") if plot_sig: p.figure() p.subplot(211) p.plot(real(tx_sig[:sig_to_plot]), '-o') p.plot(imag(tx_sig[:sig_to_plot]), '-o') p.xlabel("Transmitted Signal") p.subplot(212) p.plot(real(rx_filtered[:sig_to_plot]), '-o') p.plot(imag(rx_filtered[:sig_to_plot]), '-o') p.xlabel("Matched Filtered Signal") if plot_syms: p.figure() p.subplot(211) #p.stem(range(syms_to_plot), real(stream_sym[0:syms_to_plot]), markerfmt='bo') #p.stem(range(syms_to_plot), imag(stream_sym[0:syms_to_plot]), markerfmt='ro')a p.plot(real(tx_syms[0:syms_to_plot]), '-o') p.plot(imag(tx_syms[0:syms_to_plot]), '-o') p.xlabel("Transmitted Symbols") p.subplot(212) #p.stem(range(syms_to_plot), real(rx_sym[0:syms_to_plot]), markerfmt='bo') #p.stem(range(syms_to_plot), imag(rx_sym[0:syms_to_plot]), markerfmt='ro') p.plot(real(rx_sym[0:syms_to_plot]), '-o') p.plot(imag(rx_sym[0:syms_to_plot]), '-o') p.xlabel("Received Symbols") p.show()
# -*- coding: utf-8 -*- """ Created on Tue May 27 13:06:42 2014 @author: dk122 """ import numpy as np import pylab as plt from scipy.io import wavfile from constellation import constellation, analyze_bite import matplotlib.animation as animation fs, data = wavfile.read('daisy16.wav') T = np.arange(len(data)) / fs peaks, cwtmatr = constellation(data, fs) peaks = (np.array([]), np.array([])) for i_norm in range(0, cwtmatr.shape[1]): s = sum(cwtmatr[:, i_norm]) cwtmatr[:, i_norm] /= s for i_start in range(0, 120000, 1000): p, cwt = analyze_bite(i_start, 5000, data, fs) peaks = (np.hstack([peaks[0], p[0]]), np.hstack([peaks[1], p[1]])) fig, ax = plt.subplots(2, 1, sharex=True) fig.set_size_inches(20, 15, forward=True) ax[0].plot(np.arange(cwtmatr.shape[1]) * 1.0 / fs, data) ax[1].imshow(-cwtmatr,
def simulate(M=4, num_syms=10, sps=8, pulse_type='square'): samp_rate = 1 bps = log2(M) const = c.constellation(M, 'qam') #pulse = f.gen(2500, sps, 0.35, 10*11*sps, pulse_type) rolloff = 0.1 pulse = gr.firdes.low_pass(1, 1, 1.0 / sps, rolloff) print pulse ############################# # Logs ############################# N0 = int(len(pulse) - 1) print "#############################" print "Pulse Len:", len(pulse) print "N0:", N0 print "#############################" ############################# # Transmitter ############################# # Create Symbol Chunks tx_chunks = array([r.choice(range(M)) for i in range(num_syms)]) # Create Symbols tx_syms = const.vec[tx_chunks] # Upsampling tx_upsamp = zeros(num_syms * sps - (sps - 1), dtype=complex) tx_upsamp[::sps] = tx_syms # Filtering with pulse shape tx_sig = convolve(tx_upsamp, pulse) #tx_sig = tx_sig[0:num_syms*sps] ############################# # Channel ############################# rx_sig = tx_sig ############################# # Receiver ############################# # Flip Left-Right pulse = pulse[::-1] # Qual a diferenca de descontar N0 antes da convolucao de depois? rx_filtered = convolve(rx_sig, pulse) rx_sym = rx_filtered[N0:N0 + num_syms * sps:sps] #rx_filtered = rx_sig #rx_sym = rx_filtered[:-1:sps] ############################# # Plots ############################# syms_to_plot = 400 sig_to_plot = syms_to_plot * sps plot_upsampling = False plot_syms = True plot_sig = False plot_pulse = True p.figure() p.subplot(211) vec = convolve(pulse, pulse) p.stem(range(len(vec)), vec) p.subplot(212) p.plot(abs(fftshift(fft(vec)))) if plot_upsampling: p.figure() p.plot(real(tx_upsamp[0:sig_to_plot]), '-o') p.plot(imag(tx_upsamp[0:sig_to_plot]), '-o') p.xlabel("Upsampled Symbols") if plot_pulse: p.figure() p.subplot(211) p.stem(range(len(pulse)), pulse) p.subplot(212) p.plot(abs(fftshift(fft(pulse)))) p.xlabel("Pulse Shape") if plot_sig: p.figure() p.subplot(211) p.plot(real(tx_sig[:sig_to_plot]), '-o') p.plot(imag(tx_sig[:sig_to_plot]), '-o') p.xlabel("Transmitted Signal") p.subplot(212) p.plot(real(rx_filtered[:sig_to_plot]), '-o') p.plot(imag(rx_filtered[:sig_to_plot]), '-o') p.xlabel("Matched Filtered Signal") if plot_syms: p.figure() p.subplot(211) #p.stem(range(syms_to_plot), real(stream_sym[0:syms_to_plot]), markerfmt='bo') #p.stem(range(syms_to_plot), imag(stream_sym[0:syms_to_plot]), markerfmt='ro')a p.plot(real(tx_syms[0:syms_to_plot]), '-o') p.plot(imag(tx_syms[0:syms_to_plot]), '-o') p.xlabel("Transmitted Symbols") p.subplot(212) #p.stem(range(syms_to_plot), real(rx_sym[0:syms_to_plot]), markerfmt='bo') #p.stem(range(syms_to_plot), imag(rx_sym[0:syms_to_plot]), markerfmt='ro') p.plot(real(rx_sym[0:syms_to_plot]), '-o') p.plot(imag(rx_sym[0:syms_to_plot]), '-o') p.xlabel("Received Symbols") p.show()