[z, p, k] = dsp.zplane(bb, aa) plt.title('Pol/Nullstellenplan') plt.grid('on') # plt.text(-0.95,0.0 ,'(2)') plt.axis([-1.1, 1.1, -1.1, 1.1]) plt.tight_layout() if DEF_PRINT == True: plt.savefig((PRINT_PATH + 'PZ' + PRINT_TYPE)) #========================================= ## Impulsantwort #========================================= if SHOW_IMPZ == True: plt.figure(2) [h, td] = dsp.impz(bb, aa, f_S) #Impulsantwort / Koeffizienten [ml, sl, bl] = plt.stem(td, h) plt.grid('on') plt.setp(ml, 'markerfacecolor', 'r', 'markersize', 8) plt.xlabel(my_x_axis_t) plt.ylabel(r'$h[n] \rightarrow $', fontsize=20) plt.title(r'Impulsantwort $h[n]$') plt.tight_layout() if PLT_AUTOx: dsp.format_ticks('x', f_scale * 1000, "%.3g") if DEF_PRINT == True: plt.savefig((PRINT_PATH + 'impz' + PRINT_TYPE)) #========================================= ## Linear frequency plot #========================================= if SHOW_LIN_H_f == True:
ylabel(r'$\angle H(e^{j\Omega}) / \pi \rightarrow $') plot(f, angle(H)/pi) subplot(313) tau, w = dsp.grpdelay(b,a, nfft = 2048, Fs = 200, whole=0) plot(w, tau) ymin, ymax = ylim(); dy = max(ymax - ymin, 1) * 0.05 ylim(ymin - dy, ymax + dy) # set reasonable range xlabel(r'$f$ / Hz $\rightarrow$') ylabel(r'$\tau_g(e^{j \Omega}) / T_S \rightarrow$') #plt.tight_layout() #------------------------------------------------------- fig3 = figure(3) plt.suptitle('Filtereigenschaften', fontsize=18) # h, t = dsp.impz(b,a) # impulse response ax31 = fig3.add_subplot(311) ax31.stem(range(len(h)),h) ax31.grid('on') ax31.set_ylabel(r'Impulsantwort' '\n' r'$h[n]\, \rightarrow$') ax31.yaxis.set_label_coords(-0.1, 0.5) # yn = np.convolve(xn,h) # Faltung (Convolution) von x und h ax32 = fig3.add_subplot(312) ax32.grid('on') ax32.stem(range(len(yn)),yn) ax32.set_xlabel(r'$n \, \rightarrow$') ax32.set_ylabel(r'Filterausgang' '\n' r'$y[n]\, \rightarrow$') ax32.yaxis.set_label_coords(-0.1, 0.5) # w,h = sig.freqz(h); f = w / (2*pi*Ts)
[z, p, k] = dsp.zplane(bb, aa) plt.title('Pol/Nullstellenplan') plt.grid('on') # plt.text(-0.95,0.0 ,'(2)') plt.axis([-1.1, 1.1, -1.1, 1.1]) plt.tight_layout() if DEF_PRINT == True: plt.savefig((PRINT_PATH +'PZ' + PRINT_TYPE)) #========================================= ## Impulsantwort #========================================= if SHOW_IMPZ == True: plt.figure(2) [h, td]=dsp.impz(bb, aa, f_S) #Impulsantwort / Koeffizienten [ml, sl, bl] = plt.stem(td, h) plt.grid('on') plt.setp(ml, 'markerfacecolor', 'r', 'markersize', 8) plt.xlabel(my_x_axis_t) plt.ylabel(r'$h[n] \rightarrow $', fontsize = 20) plt.title(r'Impulsantwort $h[n]$') plt.tight_layout() if PLT_AUTOx: dsp.format_ticks('x', f_scale*1000, "%.3g") if DEF_PRINT == True: plt.savefig((PRINT_PATH + 'impz' + PRINT_TYPE)) #========================================= ## Linear frequency plot #========================================= if SHOW_LIN_H_f == True:
subplot, title, clf, xlim, ylim) import sys sys.path.append('..') import dsp_fpga_lib as dsp # -- Impulse response (lin / log) --- f1 = 50 Ts = 5e-3 n = arange(0, 50) # sample n t = arange(0, 49., 0.1) # feiner aufgelöst xn = 1.5 + 0.5 * cos(2.0 * pi * f1 * n * Ts) # x[n] b = [0.1, 0] a = [1, -0.9] # Koeffizienten # H(z) = (0.1 z + 0) / (z - 0.9) [h, k] = dsp.impz(b, a, N=30) # -> h[k] figure(1) subplot(211) stem(k, h, 'r') # x[n], red stems ylabel(r'$h[k] \rightarrow$') grid(True) title(r'Impulsantwort $h[n]$') subplot(212) stem(k, 20 * log10(abs(h)), 'r') xlabel(r'$k \rightarrow$') grid(True) ylabel(r'$20 \log\, h[k] \rightarrow$') # ------- Filtered signal ------------- figure(2) yn = sig.lfilter(b, a, xn) #filter xn with h f = intp.interp1d(n, yn, kind='cubic')
from matplotlib.pyplot import (figure, plot, stem, grid, xlabel, ylabel, subplot, title, clf, xlim, ylim) import sys sys.path.append('..') import dsp_fpga_lib as dsp alpha = 0.9; f_S = 1 b = [1, 0] # z + 0 # b = [1 0 0] # z^2 + 0 a = [1, -alpha] # z - 0.9; Add., 1 Verzögerung #a = [1 +alpha] # z + 0.9; Subtr., 1 Verz. #a = [1 0 -alpha] # z^2 - 0.9; Add., 2 Verz. #a = [1 0 +alpha] # z^2 - 0.9; Subtr., 2 Verz. dsp.zplane(b,a)#, plt_ax = ax) # Plotte P/N Diagramm # H(f) entlang der oberen Hälfte des EK: [W,H] = sig.freqz(b,a,1024, f_S) fig2 = figure(2) plot(W/(2*pi),abs(H),linewidth = 2) # H(F) xlabel(r'$F$ bzw. $\Omega / 2 \pi$') ylabel(r'$|H(F)| \; \rightarrow$') # Berechne 20 Werte der Impulsantwort: [himp,t] = dsp.impz(b,a,20,f_S) figure(3) (ml, sl, bl) = stem(t,himp) # Impulsantwort plt.setp(ml,'markerfacecolor','r', 'markersize',8) plt.setp(sl,'linewidth',2) xlabel('$n$'); ylabel(r'$h[n]$') plt.show()
plot(f, angle(H) / pi) subplot(313) tau, w = dsp.grpdelay(b, a, nfft=2048, Fs=200, whole=0) plot(w, tau) ymin, ymax = ylim() dy = max(ymax - ymin, 1) * 0.05 ylim(ymin - dy, ymax + dy) # set reasonable range xlabel(r'$f$ / Hz $\rightarrow$') ylabel(r'$\tau_g(e^{j \Omega}) / T_S \rightarrow$') #plt.tight_layout() #------------------------------------------------------- fig3 = figure(3) plt.suptitle('Filtereigenschaften', fontsize=18) # h, t = dsp.impz(b, a) # impulse response ax31 = fig3.add_subplot(311) ax31.stem(range(len(h)), h) ax31.grid('on') ax31.set_ylabel(r'Impulsantwort' '\n' r'$h[n]\, \rightarrow$') ax31.yaxis.set_label_coords(-0.1, 0.5) # yn = np.convolve(xn, h) # Faltung (Convolution) von x und h ax32 = fig3.add_subplot(312) ax32.grid('on') ax32.stem(range(len(yn)), yn) ax32.set_xlabel(r'$n \, \rightarrow$') ax32.set_ylabel(r'Filterausgang' '\n' r'$y[n]\, \rightarrow$') ax32.yaxis.set_label_coords(-0.1, 0.5) # w, h = sig.freqz(h)
import matplotlib.pyplot as plt from matplotlib.pyplot import (figure, plot, stem, grid, xlabel, ylabel, subplot, title, clf, xlim, ylim) import sys sys.path.append('..') import dsp_fpga_lib as dsp # -- Impulse response (lin / log) --- f1 = 50; Ts = 5e-3 n = arange(0, 50) # sample n t = arange(0, 49., 0.1) # feiner aufgelöst xn = 1.5 + 0.5*cos(2.0*pi*f1*n*Ts) # x[n] b = [0.1, 0]; a = [1, -0.9] # Koeffizienten # H(z) = (0.1 z + 0) / (z - 0.9) [h, k] = dsp.impz(b, a, N = 30) # -> h[k] figure(1) subplot(211) stem(k, h, 'r') # x[n], red stems ylabel(r'$h[k] \rightarrow$'); grid(True) title(r'Impulsantwort $h[n]$') subplot(212) stem(k, 20*log10(abs(h)), 'r') xlabel(r'$k \rightarrow$'); grid(True) ylabel(r'$20 \log\, h[k] \rightarrow$') # ------- Filtered signal ------------- figure(2); yn = sig.lfilter(b,a,xn) #filter xn with h f = intp.interp1d(n, yn, kind = 'cubic') yt = f(t) # y(t), interpolated plot(t, yt, color='#cc0000', linewidth=3)