else: yield next(filter_out_o) il_filter_gen = interleaved_filter2(inputv) result = np.fromiter(il_filter_gen, float) plt.figure() plt.plot(inputv, label='Original Waveform') plt.plot(result, label='IL Filtered Waveform') plt.legend() plt.title('IL Filter Output Waveform') plt.figure() plt.subplot(121) # using cusomized fft module imported earlier x, y = fftplot.winfft(inputv, fs=Fs, beta=12) fftplot.plot_spectrum(x, y, ceil=40) plt.title('Orig Output Spectrum (Unfiltered)') plt.subplot(122) # using cusomized fft module imported earlier x, y = fftplot.winfft(result, fs=Fs, beta=12) fftplot.plot_spectrum(x, y, ceil=40) plt.title('IL Filter Output Spectrum (Unfiltered)') plt.show() pass
if __name__ == '__main__': # test NCO, single value FCW fout = 5.03e3 fclk = 10e6 acc_s = 32 fres = fclk / 2 ** acc_s fcw = round(fout / fres) nco_gen = nco(fcw, acc_size=acc_s, nsamp=2 ** 15) # nco_gen is a generator, so cannot use np.array(nco_gen) directly # np.array(list(nco_gen)) also works but is not as memory efficient result = np.fromiter(nco_gen, float) plt.figure() plt.plot(result) plt.title('NCO Output Waveform') # frequency spectrum of NCO plt.figure() # using cusomized fft module imported earlier x, y = fftplot.winfft(result / max(result), fs=fclk, beta=12) fftplot.plot_spectrum(x, y) plt.title('NCO Output Spectrum') plt.show()
plt.title('Filter Frequency Response') # both mag and phase plot # hf.responsePlot(w, h, 'simple moving avg frequency response') # frequency response of simple moving avg w, h = sig.freqz([1 - alpha], [1, -alpha], whole=True, fs=Fs) # plt.figure() db_mag = hf.db(h) plt.plot((w - Fs / 2) / 1e3, fft.fftshift(db_mag), label='exponential MAF') plt.legend() # example spectrum plt.figure() # using cusomized fft module imported earlier x, y = fftplot.winfft(out, fs=Fs, beta=12) fftplot.plot_spectrum(x, y) plt.title('Output Spectrum (Unfiltered)') plt.figure() x, y = fftplot.winfft(filt_out, fs=Fs, beta=12) fftplot.plot_spectrum(x, y) plt.title('Output Spectrum (Filtered Simp Mov Avg)') plt.figure() x, y = fftplot.winfft(filt_out2, fs=Fs, beta=12) fftplot.plot_spectrum(x, y) plt.title('Output Spectrum (Filtered Exp Mov Avg)') plt.figure() filt_model_out = three_tap_moving_avg_list(inputv, 12, coeffs=[1, 1, 1]) plt.plot(filt_model_out)
noise[0:int(nsamps/2)] = np.cos(2 * np.pi * tone2 * t[0:int(nsamps/2)]) # noise = np.cos(2 * np.pi * tone2 * t) noise1 = 1 * randn(nsamps) s = np.cos(2 * np.pi * ftone * t) delayed_noise = sig.lfilter([0, 0, 0, 1], 1, noise) adc_out = s + delayed_noise # using cusomized fft module x, y = fftplot.winfft(adc_out, fs=fs) plt.figure() fftplot.plot_spectrum(x, y) plt.title(f'Output Spectrum - {ftone / 1e6} MHz Tone') plt.figure() plt.plot(t, adc_out) # windowing with kaiser win_len = nsamps beta = 12 win = sig.kaiser(win_len, beta) winscale = np.sum(win) win_data = win * adc_out plt.figure() plt.plot(t, win_data)
ax_rect_fft.stem(xf / 1e3, angle2(np.round(yf, 1)) * 180 / pi, use_line_collection=True) ax_rect_fft.set_xlabel('Frequency [kHz]') ax_rect_fft.set_ylabel('Phase [Deg]') # ax_mag = plt.subplot(3, 2, 4) ax_rect_mag = plt.subplot(3, 2, 4) ax_rect_phase = plt.subplot(3, 2, 6) scope_main = Scope(len(rotating_phasors)) interval = 20 fig.canvas.mpl_connect('key_press_event', onClick) # pass a generator in "sineEmitter" to produce data for the update func ani = animation.FuncAnimation(fig, scope_main.update, sig_emitter, interval=interval, blit=True) plt.figure() # I-j*Q # complex down conversion example, just FFT plotting sum_sig2 = sum([(amp2 * np.cos(2 * pi * f2 * x_t + phi2) + 0.5 * np.cos(2 * pi * f1 * x_t + phi2)) * np.cos(2 * pi * (f2 - f1 / 2) * x_t + phi2), -1j * (amp2 * np.cos(2 * pi * f2 * x_t + phi2) + 0.5 * np.cos(2 * pi * f1 * x_t + phi2)) * np.sin(2 * pi * (f2 - f1 / 2) * x_t + phi2) ]) fftplot.plot_spectrum(*fftplot.winfft(sum_sig2, fs=Fs), drange=120) plt.title('Complex Down Conversion Example') # ax_rect_fft.plot(np.unwrap(np.angle(np.round(yf, 1), deg=True))) plt.show()
freq_step = np.mean(np.gradient(freq)) print('freq_step is {}MHz'.format(freq_step / 1e6)) # need 25MHz freq_step, so 17/10*25 = 42.5 fs = 1 / freq_step print('Fs is {}'.format(fs)) freq_conv = freq / 1e12 freq_step_conv = np.mean(np.gradient(freq_conv)) print('freq_step is {}MHz'.format(freq_step_conv)) # need 25MHz freq_step, so 17/10*25 = 42.5 fs = 1 / freq_step_conv print('Fs is {}'.format(fs)) plt.figure() fftplot.plot_spectrum(*fftplot.winfft(insert_loss, fs=fs), drange=120) interp = 17 deci = 10 insert_loss_zeros_int = np.zeros(len(insert_loss) * interp) insert_loss_zeros_int[::interp] = insert_loss freq_step_post_interp = freq_step / interp freq_interp = np.arange(0.3e6, 8.5e9 + freq_step_post_interp * interp, freq_step_post_interp) freq_step_post_deci = freq_step_post_interp * deci freq_deci = np.arange(0.3e6, 8.5e9 + freq_step_post_deci / deci, freq_step_post_deci) plt.figure()
# To pulse shape the data, first we upsample the sequence by inserting zeros, and then # pass that upsampled signal through the pulse shaping filter. # For demonstration we will use the raised cosine filter, showing the eventual result # after two root-raised cosine filters. tx = np.zeros(len(data) * oversamp, dtype=complex) tx[::oversamp] = symbols # pass data through tx pulse shaping filter: tx_shaped = sig.lfilter(coeff, 1, tx) plt.figure() fftplot.plot_spectrum(*fftplot.winfft(tx_shaped, fs=sym_rate * oversamp), drange=120) plt.title("Spectrum") # plt.grid() # eye diagram num_cycles = 4 # number of symbols to display in eye diagram windows = 200 # a window is one path across display shown # resample data to at least 64x per symbol to emulate continuous waveform resamp = int(np.ceil(64 / oversamp)) tx_resamp = sig.resample(tx_shaped, len(tx_shaped) * resamp)