#b = [1, 0]; a = [1, -0.9] # lossy integr.
#
# ----- P/Z-Plot -----
figure(1)
title('Pole/Zero-Plan')
dsp.zplane(b,a)
# ----- frequency response -----
figure(2)
[W, H] = sig.freqz(b, a, whole=0);
f = W  / (Ts * 2 * pi)
(w,Asig) = sig.freqz(b,a, f1*Ts*2*pi)
H_mx = np.max(abs(H))
H = H / H_mx; Asig = abs(Asig)/H_mx
#
subplot(311)
plot(f,abs(H))
ylabel(r'$|H(e^{j \Omega})| \rightarrow$')
title('Frequency Response')
plt.annotate('Attenuation @ %.1f Hz \n \
 = %1.3f (%3.1f dB)'%(f1,Asig,20*log10(Asig)),\
(f1, Asig),(0.5,0.5),textcoords='axes fraction',\
arrowprops=dict(arrowstyle="->"))
subplot(312)
plot(f, angle(H)/pi)
ylabel(r'$\angle H(e^{j\Omega}) / \pi$ ->')
subplot(313)
tau, w = dsp.grpdelay(b,a, nfft = 2048, Fs = 200, whole=0)
plot(w, tau)
xlabel(r'$f$ / Hz $\rightarrow$')
ylabel(r'$\tau_g(e^{j \Omega})/T_S\rightarrow$')
plt.show()       # draw and show the plots
    # Ohne unwrap wird Phase auf +/- pi umgebrochen
    ax6.set_title(r'Phasengang (normiert auf Vielfache von $\pi$)')
    ax6.set_xlabel(my_x_axis_f)
    ax6.set_ylabel(r'$\phi(f) / \pi \rightarrow $')
    if PLT_AUTOx: dsp.format_ticks('x',f_scale, N_F_str)  
    plt.tight_layout() 
    if DEF_PRINT == True:
        plt.savefig(PRINT_PATH +'phase'+ PRINT_TYPE)

#=========================================
## Groupdelay
#=========================================
if SHOW_GRPDELAY == True:
    fig7 = plt.figure(7)
    ax7 = fig7.add_subplot(111)
    [tau_g, w] = dsp.grpdelay(bb,aa,N_FFT, whole, f_S)
    ax7.plot(w, tau_g); plt.grid('on')
    ax7.axis(f_range + (max(min(tau_g)-0.5,0), max(tau_g) + 0.5))
    ax7.set_title(r'Group Delay $ \tau_g$') # (r: raw string)
    ax7.set_xlabel(my_x_axis_f)
    ax7.set_ylabel(r'$ \tau_g(f)/T_S$')
    if PLT_AUTOx: dsp.format_ticks('x',f_scale, N_F_str)
    plt.tight_layout()
    if DEF_PRINT == True:
        plt.savefig(PRINT_PATH +'grpdelay' + PRINT_TYPE)

#===============================================================
## 3D-Plots
#===============================================================
if OPT_3D_FORCE_ZMAX == True:
    thresh = zmax
    # Ohne unwrap wird Phase auf +/- pi umgebrochen
    ax6.set_title(r'Phasengang (normiert auf Vielfache von $\pi$)')
    ax6.set_xlabel(my_x_axis_f)
    ax6.set_ylabel(r'$\phi(f) / \pi \rightarrow $')
    if PLT_AUTOx: dsp.format_ticks('x', f_scale, N_F_str)
    plt.tight_layout()
    if DEF_PRINT == True:
        plt.savefig(PRINT_PATH + 'phase' + PRINT_TYPE)

#=========================================
## Groupdelay
#=========================================
if SHOW_GRPDELAY == True:
    fig7 = plt.figure(7)
    ax7 = fig7.add_subplot(111)
    [tau_g, w] = dsp.grpdelay(bb, aa, N_FFT, whole, f_S)
    ax7.plot(w, tau_g)
    plt.grid('on')
    ax7.axis(f_range + (max(min(tau_g) - 0.5, 0), max(tau_g) + 0.5))
    ax7.set_title(r'Group Delay $ \tau_g$')  # (r: raw string)
    ax7.set_xlabel(my_x_axis_f)
    ax7.set_ylabel(r'$ \tau_g(f)/T_S$')
    if PLT_AUTOx: dsp.format_ticks('x', f_scale, N_F_str)
    plt.tight_layout()
    if DEF_PRINT == True:
        plt.savefig(PRINT_PATH + 'grpdelay' + PRINT_TYPE)

#===============================================================
## 3D-Plots
#===============================================================
if OPT_3D_FORCE_ZMAX == True:
Beispiel #4
0
    plt.axis([0, f_DB * 1.1, -A_DB*1.1, A_DB * 1.1])
else:
    plot([0, f_DB], [0, 0], 'b--') # obere Spec-Grenze
    plt.axis([0, f_DB * 1.1, -A_DB * 1.1, A_DB * 0.1])
title(r'Betragsfrequenzgang in dB')
#
subplot(212)
plot(f,20 * log10(abs(H)), 'r'); plt.grid('on')
plot([0,  f_DB],[-A_DB, -A_DB],'b--') # untere Grenze DB
if len(a) == 1:
    plot([0,  f_DB], [A_DB, A_DB],'b--') # obere Grenze DB
else:
    plot([0, f_DB], [0, 0], 'b--') # obere Grenze DB
plot([f_SB, f_S/2.], [-A_SB, -A_SB], 'b--') # obere Grenze SB
plot([f_DB, f_DB], [-A_DB, -A_DB-10], 'b--') # @ F_DB
plot([f_SB, f_SB],[1, -A_SB],'b--') # @ F_SB
plt.tight_layout() # pad=1.2, h_pad=None, w_pad=None
#=========================================
## Phasengang
figure(6); grid('on')
plot(f,np.unwrap(np.angle(H))/pi)
# Ohne unwrap wird Phase auf +/- pi umgebrochen
title(r'Phasengang (normiert auf Vielfache von $\pi$)')
## Groupdelay
plt.figure(7)
[tau_g, w] = dsp.grpdelay(b, a, Fs = f_S)
plot(w, tau_g); plt.grid('on')
plt.ylim(max(min(tau_g)-0.5,0), (max(tau_g) + 0.5))
title(r'Group Delay $ \tau_g$') # (r: raw string)

plt.show()
        plt.axhline(y=-3, lw = 1, c = 'k', ls = '-.')
        plt.axvline(x=W_c,  lw = 1, c = 'k', ls = '-.')
    ax31.set_xlabel(r'$\omega\,/ \, \omega_{3dB} \; \rightarrow$')
    ax31.set_ylabel(r'$20\, \log\,|H(j \omega)| \; \rightarrow$')
    ax31.legend(loc='best')
    plt.axis([0.2,20, -60,1])
    fig3.tight_layout()
  
    #===============================================================
    ## Group Delay
    #===============================================================
    fig4 = figure(4)
    ax41 = fig4.add_subplot(111)
    
    tau_g, w_g = dsp.grp_delay_ana(bb, aa, W)
    tau_g2, w_g2 = dsp.grpdelay(bb, aa, analog = True, Fs = max(W))

    l41, = ax41.plot(w_g, tau_g, label = zeta_label)
    l42, = ax41.plot(w_g2, tau_g2)

    
    ax41.set_xlabel(r'$\omega\,/\, \omega_{3dB} \; \rightarrow$')
    ax41.set_ylabel(r'$\tau_g (j \omega)\; \rightarrow$')
    ax41.set_title(r'$\mathrm{Group \, Delay \, of}\, H(j \omega) $')
    plt.xlim(0,2*W_c)
    ax41.legend(loc='best')    
#    ax31.legend((l31),(r'$\tau_g \{H(j \omega)\}$'))
    plt.tight_layout()
    
    #===============================================================
    ## Step Response
Beispiel #6
0
# Parks-McClellan / Remez (= Linphase FIR) - Filter:
L, bands, amps, w = dsp.remezord([F_DB, F_SB], [1, 0], [del_DB, del_SB])
# b = sig.remez(L, [0, F_DB, F_SB, 0.5], [1, 0], [1, 1], Hz = 1)
b = sig.remez(L, bands, amps, w)

# IIR-Filter
[b, a] = sig.iirdesign(F_DB * 2, F_SB * 2, R_DB, R_SB, ftype="ellip")
# [b, a] = sig.iirdesign(F_DB*2, F_SB*2, R_DB, R_SB, ftype='cheby2')
# [b, a] = sig.iirdesign(F_DB*2, F_SB*2, R_DB, R_SB, ftype='butter')
# b = [0.2]; a = [1, -0.8]
#
# ================================================
w, H = sig.freqz(b, a, 2048)
Hmax = max(abs(H))
H = H / Hmax
tau, w = dsp.grpdelay(b, a, 2048)
f = w / (2 * pi)
delay = tau[np.floor(2048 / (2 * OSR))]  # delay at F = 0.5 / (2 * OSR)
dN = np.floor(delay)
print("Delay @ F= %2.3e = %.1f T_S" % ((0.5 / (2 * OSR)), delay))
# ====== Symbol & Noise Generation ===============
# random binary (+/-1) symbol sequence
s = 2 * rnd.randint(0, high=2, size=VEC_SIZE) - 1
s = s.repeat(OSR)  # repeat each symbol OSR times
# linear power of the noise; average signal power = 1:
No = 1.0 / SNR
# random signal with normal distribution and power No
n = sqrt(No / 2) * rnd.randn(VEC_SIZE * OSR)  #
# signal + noise
x = s + n
# x = s
    plot([0, f_DB], [0, 0], 'b--')  # obere Spec-Grenze
    plt.axis([0, f_DB * 1.1, -A_DB * 1.1, A_DB * 0.1])
title(r'Betragsfrequenzgang in dB')
#
subplot(212)
plot(f, 20 * log10(abs(H)), 'r')
plt.grid('on')
plot([0, f_DB], [-A_DB, -A_DB], 'b--')  # untere Grenze DB
if len(a) == 1:
    plot([0, f_DB], [A_DB, A_DB], 'b--')  # obere Grenze DB
else:
    plot([0, f_DB], [0, 0], 'b--')  # obere Grenze DB
plot([f_SB, f_S / 2.], [-A_SB, -A_SB], 'b--')  # obere Grenze SB
plot([f_DB, f_DB], [-A_DB, -A_DB - 10], 'b--')  # @ F_DB
plot([f_SB, f_SB], [1, -A_SB], 'b--')  # @ F_SB
plt.tight_layout()  # pad=1.2, h_pad=None, w_pad=None
#=========================================
## Phasengang
figure(5)
plot(f, np.unwrap(np.angle(H)) / pi)
# Ohne unwrap wird Phase auf +/- pi umgebrochen
title(r'Phasengang (normiert auf Vielfache von $\pi$)')
## Groupdelay
plt.figure(7)
[tau_g, w] = dsp.grpdelay(b, a, Fs=f_S)
plot(w, tau_g)
plt.grid('on')
plt.ylim(max(min(tau_g) - 0.5, 0), (max(tau_g) + 0.5))
title(r'Group Delay $ \tau_g$')  # (r: raw string)

plt.show()
Beispiel #8
0
    # Ohne unwrap wird Phase auf +/- pi umgebrochen
    ax6.set_title(r'Phasengang (normiert auf Vielfache von $\pi$)')
    ax6.set_xlabel(my_x_axis_f)
    ax6.set_ylabel(r'$\phi(f) / \pi \rightarrow $')
    if PLT_AUTOx: dsp.format_ticks('x',f_scale, N_F_str)
    plt.tight_layout()
    if DEF_PRINT == True:
        plt.savefig(PRINT_PATH +'phase'+ PRINT_TYPE)

#=========================================
## Groupdelay
#=========================================
if SHOW_GRPDELAY == True:
    fig7 = plt.figure(7)
    ax7 = fig7.add_subplot(111)
    [tau_g, w] = dsp.grpdelay(bb,aa,N_FFT, Fs = f_S)
    ax7.plot(w, tau_g); plt.grid('on')
    ax7.axis(f_range + (max(min(tau_g)-0.5,0), max(tau_g) + 0.5))
    ax7.set_title(r'Group Delay $ \tau_g$') # (r: raw string)
    ax7.set_xlabel(my_x_axis_f)
    ax7.set_ylabel(r'$ \tau_g(f)/T_S$')
    if PLT_AUTOx: dsp.format_ticks('x',f_scale, N_F_str)
    plt.tight_layout()
    if DEF_PRINT == True:
        plt.savefig(PRINT_PATH +'grpdelay' + PRINT_TYPE)

#===============================================================
## 3D-Plots
#===============================================================
if OPT_3D_FORCE_ZMAX == True:
    thresh = zmax
#b = [1, 0]; a = [1, -0.9] # lossy integr.
#
# ----- P/Z-Plot -----
figure(1)
title('Pole/Zero-Plan')
dsp.zplane(b,a)
# ----- frequency response -----
figure(2)
[W, H] = sig.freqz(b, a, whole=0);
f = W  / (Ts * 2 * pi)
(w,Asig) = sig.freqz(b,a, f1*Ts*2*pi)
H_mx = np.max(abs(H))
H = H / H_mx; Asig = abs(Asig)/H_mx
#
subplot(311)
plot(f,abs(H))
ylabel(r'$|H(e^{j \Omega})| \rightarrow$')
title('Frequency Response')
plt.annotate('Attenuation @ %.1f Hz \n \
 = %1.3f (%3.1f dB)'%(f1,Asig,20*log10(Asig)),\
(f1, Asig),(0.5,0.5),textcoords='axes fraction',\
arrowprops=dict(arrowstyle="->"))
subplot(312)
plot(f, angle(H)/pi)
ylabel(r'$\angle H(e^{j\Omega}) / \pi$ ->')
subplot(313)
tau, w = dsp.grpdelay(b,a, nfft = 2048, Fs = 200, whole=0)
plot(w, tau)
xlabel(r'$f$ / Hz $\rightarrow$')
ylabel(r'$\tau_g(e^{j \Omega})/T_S\rightarrow$')
plt.show()       # draw and show the plots
    # Ohne unwrap wird Phase auf +/- pi umgebrochen
    ax6.set_title(r'Phasengang (normiert auf Vielfache von $\pi$)')
    ax6.set_xlabel(my_x_axis_f)
    ax6.set_ylabel(r'$\phi(f) / \pi \rightarrow $')
    if PLT_AUTOx: dsp.format_ticks('x', f_scale, N_F_str)
    plt.tight_layout()
    if DEF_PRINT == True:
        plt.savefig(PRINT_PATH + 'phase' + PRINT_TYPE)

#=========================================
## Groupdelay
#=========================================
if SHOW_GRPDELAY == True:
    fig7 = plt.figure(7)
    ax7 = fig7.add_subplot(111)
    [tau_g, w] = dsp.grpdelay(bb, aa, N_FFT, Fs=f_S)
    ax7.plot(w, tau_g)
    plt.grid('on')
    ax7.axis(f_range + (max(min(tau_g) - 0.5, 0), max(tau_g) + 0.5))
    ax7.set_title(r'Group Delay $ \tau_g$')  # (r: raw string)
    ax7.set_xlabel(my_x_axis_f)
    ax7.set_ylabel(r'$ \tau_g(f)/T_S$')
    if PLT_AUTOx: dsp.format_ticks('x', f_scale, N_F_str)
    plt.tight_layout()
    if DEF_PRINT == True:
        plt.savefig(PRINT_PATH + 'grpdelay' + PRINT_TYPE)

#===============================================================
## 3D-Plots
#===============================================================
if OPT_3D_FORCE_ZMAX == True:
Beispiel #11
0
        plt.axhline(y=-3, lw=1, c='k', ls='-.')
        plt.axvline(x=W_c, lw=1, c='k', ls='-.')
    ax31.set_xlabel(r'$\omega\,/ \, \omega_{3dB} \; \rightarrow$')
    ax31.set_ylabel(r'$20\, \log\,|H(j \omega)| \; \rightarrow$')
    ax31.legend(loc='best')
    plt.axis([0.2, 20, -60, 1])
    fig3.tight_layout()

    #===============================================================
    ## Group Delay
    #===============================================================
    fig4 = figure(4)
    ax41 = fig4.add_subplot(111)

    tau_g, w_g = dsp.grp_delay_ana(bb, aa, W)
    tau_g2, w_g2 = dsp.grpdelay(bb, aa, analog=True, Fs=max(W))

    l41, = ax41.plot(w_g, tau_g, label=zeta_label)
    l42, = ax41.plot(w_g2, tau_g2)

    ax41.set_xlabel(r'$\omega\,/\, \omega_{3dB} \; \rightarrow$')
    ax41.set_ylabel(r'$\tau_g (j \omega)\; \rightarrow$')
    ax41.set_title(r'$\mathrm{Group \, Delay \, of}\, H(j \omega) $')
    plt.xlim(0, 2 * W_c)
    ax41.legend(loc='best')
    #    ax31.legend((l31),(r'$\tau_g \{H(j \omega)\}$'))
    plt.tight_layout()

    #===============================================================
    ## Step Response
    #===============================================================
Beispiel #12
0
# Parks-McClellan / Remez (= Linphase FIR) - Filter:
L, bands, amps, w = dsp.remezord([F_DB, F_SB], [1, 0], [del_DB, del_SB])
#b = sig.remez(L, [0, F_DB, F_SB, 0.5], [1, 0], [1, 1], Hz = 1)
b = sig.remez(L, bands, amps, w)

# IIR-Filter
[b, a] = sig.iirdesign(F_DB * 2, F_SB * 2, R_DB, R_SB, ftype='ellip')
#[b, a] = sig.iirdesign(F_DB*2, F_SB*2, R_DB, R_SB, ftype='cheby2')
#[b, a] = sig.iirdesign(F_DB*2, F_SB*2, R_DB, R_SB, ftype='butter')
#b = [0.2]; a = [1, -0.8]
#
#================================================
w, H = sig.freqz(b, a, 2048)
Hmax = max(abs(H))
H = H / Hmax
tau, w = dsp.grpdelay(b, a, 2048)
f = w / (2 * pi)
delay = tau[int(np.floor(2048 / (2 * OSR)))]  # delay at F = 0.5 / (2 * OSR)
dN = int(np.floor(delay))
print('Group delay @ F= %2.3e = %.1f T_S' % ((0.5 / (2 * OSR)), delay))
#====== Symbol & Noise Generation ===============
# random binary (+/-1) symbol sequence
s = 2 * rnd.randint(0, high=2, size=VEC_SIZE) - 1
s = s.repeat(OSR)  # repeat each symbol OSR times
# linear power of the noise; average signal power = 1:
No = 1.0 / SNR
# random signal with normal distribution and power No
n = sqrt(No / 2) * rnd.randn(VEC_SIZE * OSR)  #
# signal + noise
x = s + n
#x = s