#!/usr/bin/env python # coding: utf-8 # Číslicový filtr # ================== # # Dokumentace k funkcím: # # * # * # * # In[1]: import scipy.signal as signal import numpy as np x=[1,2,1.4,3.1,1.1,2,1,0,-3.1,-2,-0.9,-2.8,-1.5] n=np.arange(len(x)) title(ur'Vstupní posloupnost vzorků \bf{x(n)}') stem(n,x, linefmt='b', markerfmt='o', basefmt='|',) xlim(-0.5,len(x)-0.5) ylim([-4,4]) xlabel(r'n $\rightarrow$', x=0.9) ylabel('x(n) $\uparrow$', y=0.9, rotation=0) xticks(n) grid() # In[58]: #### Dolní propust ############################################ #h1=signal.firwin(5,0.3) h1=[0.1, 0.2, 0.5, 0.3, ] y1=signal.lfilter(h1, 1, x) figure(figsize=(10,6)) title(ur'Impulzní charakteristika dolní propusti') stem(h1, linefmt='b', markerfmt='o', basefmt='|',) xlim(-0.5,len(n)+.5) ylim([-0.05,0.6]) xlabel(r'n $\rightarrow$', x=0.9) ylabel('h(n) $\uparrow$', y=0.9, rotation=0) xticks(n) #xlim([-0.5,3.5]) #xticks([0,1,2,3,]) grid() figure() title(ur'Výstupní posloupnost vzorků \bf{y(n)} -- \bf{Dolní propust}') stem(n,y1, linefmt='b', markerfmt='o', basefmt='|',) xlim(-0.5,len(x)-0.5) ylim([-4,4]) xlabel(r'n $\rightarrow$', x=0.9) ylabel('y(n) $\uparrow$', y=0.9, rotation=0) xticks(n) grid() h1 y1 # In[3]: ## Horní propust #################################### h2=signal.firwin(5,0.3, pass_zero=False) y2=signal.lfilter(h2, 1, x) figure() title(ur'Impulzní charakteristika horní propusti') stem(h2, linefmt='b', markerfmt='o', basefmt='|',) xlim(-0.5,len(x)-0.5) ylim([-0.5,0.8]) xlabel(r'n $\rightarrow$', x=0.9) ylabel('h(n) $\uparrow$', y=0.9, rotation=0) xticks(n) grid() figure() title(ur'Výstupní posloupnost vzorků \bf{y(n)} -- \bf{Horní propust}') stem(n,y2, linefmt='b', markerfmt='o', basefmt='|',) xlim(-0.5,len(x)-0.5) ylim([-4,4]) xlabel(r'n $\rightarrow$', x=0.9) ylabel('y(n) $\uparrow$', y=0.9, rotation=0) xticks(n) grid() h2 # In[4]: figure(figsize=(10,12)) subplot(311) title(ur'Vstupní posloupnost vzorků \bf{x(n)}') stem(n,x, linefmt='b', markerfmt='o', basefmt='|',) xlim(-0.5,len(x)-0.5) ylim([-4,4]) xlabel(r'n $\rightarrow$', x=0.9) ylabel('x(n) $\uparrow$', y=0.9, rotation=0) xticks(n) grid() subplot(312) title(ur'Výstupní posloupnost vzorků \bf{y(n)} -- \bf{dolní propust}') stem(n,y1, linefmt='b', markerfmt='o', basefmt='|',) xlim(-0.5,len(x)-0.5) ylim([-4,4]) xlabel(r'n $\rightarrow$', x=0.9) ylabel('y(n) $\uparrow$', y=0.9, rotation=0) xticks(n) grid() subplot(313) title(ur'Výstupní posloupnost vzorků \bf{y(n)} -- \bf{horní propust}') stem(n,y2, linefmt='b', markerfmt='o', basefmt='|',) xlim(-0.5,len(x)-0.5) ylim([-4,4]) xlabel(r'n $\rightarrow$', x=0.9) ylabel('y(n) $\uparrow$', y=0.9, rotation=0) xticks(n) grid() tight_layout() # In[5]: ### Jednotkový impulz ########################## d=[0,0,0,1,0,0,0] nn=arange(-3,4) figure(figsize=(10,4)) title(ur'Jednotkový (Diracuv) impulz $\delta(n)$') stem(nn,d, linefmt='b', markerfmt='o', basefmt='|',lw=5) xlim(-3.5,3.5) ylim([-0.1,1.2]) xlabel(r'n $\rightarrow$', x=0.9) ylabel(r'$\delta(n) \uparrow$', y=0.9, rotation=0) xticks(nn) grid() # In[57]: #### Konvoluce ###################################33 # x(n) na=arange(-(len(h)-1),len(x)) xa=concatenate([ zeros(len(h)-1) , x]) ax=subplot(211) stem(na,xa) xlim([-3.5,12.5]) ax.spines['right'].set_color('none') ax.spines['top'].set_color('none') ax.xaxis.set_ticks_position('bottom') ax.spines['bottom'].set_position(('data',0)) ax.yaxis.set_ticks_position('left') ax.spines['left'].set_position(('data',0)) for label in ax.get_xticklabels() + ax.get_yticklabels(): label.set_fontsize(16) label.set_bbox(dict(facecolor='white', edgecolor='None', alpha=0.65 )) ax.set_xticks(na) xlabel(r'n $\rightarrow$', x=1.04) ylabel(r'$\mathrm{x}(n) \uparrow$', y=0.9, rotation=0) grid() ## h(n) krok=5 ha=krok*[0]+h1[::-1]+(len(na)-len(h1)-krok)*[0] ax=subplot(212) stem(na,ha) xlim([-3.5,12.5]) ylim([0,0.6]) ax.spines['right'].set_color('none') ax.spines['top'].set_color('none') ax.xaxis.set_ticks_position('bottom') ax.spines['bottom'].set_position(('data',0)) ax.yaxis.set_ticks_position('left') ax.spines['left'].set_position(('data',0)) for label in ax.get_xticklabels() + ax.get_yticklabels(): label.set_fontsize(16) label.set_bbox(dict(facecolor='white', edgecolor='None', alpha=0.65 )) ax.set_xticks(na) xlabel(r'n $\rightarrow$', x=1.04) ylabel(r'$\mathrm{h}(n) \uparrow$', y=0.9, rotation=0) grid() # In[6]: