Η παρουσίαση φορτώνεται. Παρακαλείστε να περιμένετε

Η παρουσίαση φορτώνεται. Παρακαλείστε να περιμένετε

Ψηφιακή Επεξεργασία Σήματος FIR Filter Design Methods

Παρόμοιες παρουσιάσεις


Παρουσίαση με θέμα: "Ψηφιακή Επεξεργασία Σήματος FIR Filter Design Methods"— Μεταγράφημα παρουσίασης:

1 Ψηφιακή Επεξεργασία Σήματος FIR Filter Design Methods
Αν. Καθηγητής Γεώργιος Ευθύμογλου November 16, 2018 Module Title

2 Εισαγωγή Προδιαγραφές ψηφιακών φίλτρων FIR φίλτρα με γραμμική φάση
Κρουστική απόκριση φίλτρου FIR φίλτρα με γραμμική φάση Zero locations for linear phase FIR filters FIR design methods Window method Frequency sampling Module Title

3 Filter Specifications
Σχέση αναλογικής συχνότητας με ψηφιακή συχνότητα Nyquist frequency = Fs/2

4 Filter Specifications for low-pass
Low-Pass frequency response

5 Filter Specifications for low-pass
Filter specification parameters - passband edge frequency - stopband edge frequency - peak ripple value in the passband - peak ripple value in the stopband

6 Filter Specifications for high-pass
High-Pass frequency response

7 Filter Specifications for band-pass
Pass-band frequency response

8 Filter Specifications for band-stop
Stop-band frequency response

9 Digital Filter Specifications for lowpass
Σχέση αναλογικής συχνότητας με ψηφιακή γωνιακή συχνότητα

10 Filter specifications for low-pass
In the passband we require that with a deviation n the stopband we require that

11 Filter Specifications for low-pass
Passband [0, wp] the band of frequency components that are allowed to pass, δp indicates the magnitude of the passband ripple, which equals the maximum deviation from the unity. passband ripple (1+δp) the maximum amount by which attenuation in the passband may deviate from nominal gain Stopband [ws,π] the band of frequency components that are suppressed, stopband attenuation δs is the corresponding tolerance (or ripple) δs indicates the magnitude response of the stopband ripple, which equals the maximum deviation from zero. Transition band [wp, ws], there are no restrictions of the magnitude respponse in this band.

12 Filter Specifications for low-pass (1st method)
Practical specifications are often given in terms of absolute power (in dB) Peak passband ripple dB or Minimum stopband attenuation

13 Filter Specifications for low-pass (1st method)
The gain usually changes gradually through the transition band from 1 (0 dB) in the passband to 0 (−∞ dB) in the stopband. You can measure the passband ripple and stopband ripple in decibels, as shown in the following equations: passband ripple Rp = 20log10(1+δp) or - 20log10(1-δp) stopband ripple As = −20log10(δs) Based on the two equations above, you can convert the passband ripple to or from the decibel representation. For example, if passband ripple equals 0.01 dB, that is, 0.01 = 20log10(1+δp), then δp = 10^(0.01/20) – 1 = Similarly, if stopband ripple equals 60 dB, that is 60 = −20log10(δs), then δs =

14 Filter Specifications for low-pass (2nd method)
Practical specifications are often given in terms of relative power specifications in dB Peak passband ripple dB Minimum stopband attenuation

15 Filter Specifications for low-pass (2nd method)
For example, if δp = 0.01 the passband ripple in dB equals Similarly, if δs = 0.001

16 Analog frequency to digital frequency conversion
In practice, passband edge frequency and stopband edge frequency are specified in Hz For digital filter design, normalized band-edge frequencies need to be computed from specifications in Hz using the SAMPLING frequency

17 Analog frequency to digital frequency conversion
Example - Let kHz, kHz, and kHz Then

18 Ideal Digital Filter Specifications

19 Linear phase FIR filters
For phase linearity the FIR transfer function must have zeros outside the unit circle. The transfer function is given by Which has (M-1) poles at the origin z=0 (trivial poles) and (M-1) zeros located anywhere in the z-plane. The frequency response is

20 Linear phase FIR filters
We impose the linear-phase constraint where β = 0 or α is a constant phase delay. Indicating a constant group delay of α samples!!! The linear phase condition imposes the following symmetry condition on the impulse response h[n]

21 4 types of linear-phase FIR filters
Έστω h(n) είναι συμμετρική γύρω από το α, το οποίο είναι το σημείο συμμετρίας. Έχουμε 4 types of linear-phase FIR filters όταν συνδυέσουμε τις παραπάνω περιπτώσεις με μονά (odd) and ζυγά (even) M. Type I M odd (α=(M-1)/2, integer). The symmetric impulse response:

22 4 types of linear-phase FIR filters
Type II M even (α=(M-1)/2 is not an integer). The symmetric impulse response:

23 4 types of linear-phase FIR filters
Type III M odd (α=(M-1)/2 is an integer). The anti-symmetric impulse response:

24 4 types of linear-phase FIR filters
Type IV M even (α=(M-1)/2 is not an integer). The anti-symmetric impulse response:

25 Amplitude response of linear phase filters
Η απόκριση συχνότητας για κάθε ένα τύπο φίλτρου έχει συγκεκριμένες εκφράσεις και σχήματα όπου Hr(w) είναι ένα amplitude response function και όχι το magnitude response function. Το amplitude response είναι μία πραγματική συνάρτηση, όμως αντίθετα με το magnitude response το οποίο είναι πάντα θετικό, το amplitude response μπορεί να είναι θετικό ή αρνητικό Το phase response που αντιστοιχεί με το magnitude response είναι μία μη-συνεχής συνάρτηση, ενώ αυτή που αντιστοιχεί με το amplitude response είναι μία γραμμική συνάρτηση (linear function).

26 Example Έστω η κρουστική απόκριση για n=0,1,2. Υπολογίστε την απόκριση συχνότητας. oπότε Όμως επίσης έχουμε:

27 Type I β=0, α=(M-1)/2 είναι ακέραιος, και h(n)=h(M-1-n), 0≤n≤M-1.

28 Type I example Έστω η κρουστική απόκριση Υπολογίστε την απόκριση πλάτους και τη θέση των μηδενικών της Η(z)

29 Type I example Έστω η κρουστική απόκριση Υπολογίστε την απόκριση πλάτους και τη θέση των μηδενικών της Η(z)

30 Type I example function [Hr,w,a,L] = Hr_Type1(h); M=length(h); L=(M-1)/2; a=[h(L+1), 2*h(L:-1:1)]; n=[0:1:L]; w=[0:1:500]'*pi/500; Hr=cos(w*n)*a'; n=0:M-1; amax=max(a)+1; amin=min(a)-1;

31 Type I example subplot(2,2,1); stem(n,h);axis([-1 2*L+1 amin amax]) xlabel('n');ylabel('h(n)');title('Impulse Response') subplot(2,2,3);stem(0:L,a);axis([-1 2*L+1 amin amax]) xlabel('n');ylabel('a(n)');title('a(n) coefficients') subplot(2,2,2);plot(w/pi,Hr);grid xlabel('frequency in pi units'); ylabel('Hr');title('Type-1 Amplitude Response') subplot(2,2,4); zplane(h,1)

32 Type I example Let h(n)={-4,1,-1,-2,5,6,5-2,-1,1,-4}. Determine the amplitude response and the locations of zeros. M=11 odd and symmetric.Type-1. With Matlab: >> h=[-4,1,-1,-2,5,6,5,-2,-1,1,-4]; >> Hr_Type1(h)

33 Type I example

34 Zero locations for FIR linear phase filters
The transfer function of FIR filters has (M-1) poles at the origin z=0 (trivial poles) and (M-1) zeros located anywhere in the z-plane. For linear phase filters, these zeros posses certain symmetries that are due to the symmetry properties of h[n]. It can be proved that if H(z) has a zero at Then for linear phase there must be a zero at For a real-valued filter we also know that if z1 is complex then there must be a conjugate zero at Which implies that there must also be a zero at

35 Zero locations for FIR linear phase filters
Thus a general zero constellation is a quadraqplet of If r=1, the zeros occur in pairs If θ=0 or θ=π, the zeros are on the real line and occur in pairs

36 Zero locations for FIR linear phase filters
In the previous example we have roots(h) ans = i i i i i i 1.2169 0.8218 i i

37 Type II β=0, α=(M-1)/2 δεν είναι ακέραιος, και h(n)=h(M-1-n) 0≤n≤M-1. Στο w=π παίρνουμε: ανεξάρτητα από τα b(n) ή h(n). Επομένως δεν μπορούμε να χρησιμοποιήσουμε αυτό το τύπο φίλτρου για highpass ή bandstop filters.

38 Type II in matlab function [Hr, w, b, L] = Hr_Type2(h) M = length(h); L = M/2; b = [2*h(L:-1:1)]; n=[1:1:L]; w=[0:1:500]'*pi/500; Hr=cos(w*(n - 0.5))*b'; n=0:M-1; bmax=max(b)+1; bmin=min(b)-1; subplot(2,2,1); stem(n,h);axis([-1 2*L+1 bmin bmax]) …

39 Type III β=π/2, α=(M-1)/2 είναι ακέραιος, και h(n)=-h(M-1-n) 0≤n≤M-1 και h((M-1)/2)=0. Στο w=0 και w=π έχουμε Hr(w)=0, ανεξάρτητα από τα c(n) ή h(n). Αυτός ο τύπος φίλτρου δεν είναι κατάλληλος για σχεδιασμό lowpass filter or highpass filter or band-stop filter.

40 Type IV β=π/2, α=(M-1)/2 δεν είναι ακέραιος , and h(n)=h(M-1-n) 0≤n≤M-1. Στο w=0 έχουμε Hr(w)=0, ανεξάρτητα από τα d(n) ή h(n). Αυτός ο τύπος φίλτρου δεν είναι κατάλληλος για σχεδιασμό lowpass filter.

41 FIR filter types Type II, M-1 odd
Therefore H(z) shοuld have a zero at z=-1 (ω=π) Similarly, Type III and IV For Type III only, since M-1 is even Type I is the only filter type with no restrictions

42 FIR Digital Filter Design
Three commonly used approaches to FIR filter design Windowed Fourier series approach Frequency sampling approach (3) Computer-based optimization methods

43 Window method Η ιδανική απόκριση συχνότητας ενός low-pass filter είναι
όπου ωc είναι η συχνότητα αποκοπής (cutoff frequency) και Αυτή όμως δεν είναι αιτιατή κρουστική απόκριση.

44 Window method Η ιδανική απόκριση συχνότητας ενός low-pass filter είναι
όπου ωc είναι η συχνότητα αποκοπής (cutoff frequency) και α είναι η καθυστέρηση σε δείγματα που προκαλεί το φίλτρο

45 Window method This operation is called “windowing” Η χρονική διάρκεια του φίλτρου θα είναι M δείγματα Η χρονική καθυστέρηση όλων των συχνοτήτων θα είναι δείγματα Ποια επίπτωση θα έχει το μήκος της κρουστικής απόκρισης στην απόκριση συχνότητας του φίλτρου?

46 Window method %Ideal Lowpass filter computation function hd = ideal_lp(wc,M) alpha = (M-1)/2; n=[0:1:M-1]; m = n-alpha+eps; hd = sin(wc*m)./(pi*m); function hd = ideal_lp2(wc,M) m=n-alpha; fc =wc/(2*pi); hd = 2*fc*sinc(2*fc*m)

47 Window method Next routine returns the magnitude response in absolute as well as in relative dB scale, the phase response, and the group delay response. function [dB,mag,pha,grd,w]=freqz_m(b,a); [H,w]=freqz(b,a,1000,'whole'); H=(H(1:1:501))'; w=(w(1:1:501))'; mag=abs(H); dB=20*log10((mag+eps)/max(mag)); pha=angle(H); grd=grpdelay(b,a,w);

48 Window method Design a digital FIR lowpass filter with the following specifications: wc=0.25π M=19; Obtain the value of As >> hd=ideal_lp(0.25*pi,19); >> stem(hd) >> xlabel('sample, n') >> ylabel('amplitude')

49 Window method

50 Window method by hand

51 Window method in Matlab
hd=ideal_lp(0.25*pi,19) hd = Columns 1 through Columns 6 through Columns 11 through Columns 16 through

52 Window method

53 Window method [db,mag,pha,grd,w]=freqz_m(hd,1); plot(w/pi,db) title('Magnitude Response in dB') xlabel('w/pi') ylabel('20*log10(|H(e^{jw})|') observe the maximum attenuation of -21 dB at stopband:

54 Επίδραση χρονικού παραθύρου w(n)
Η απευθείας περικοπή του hd(n) σε πεπερασμένο αριθμό δειγμάτων ισοδυναμεί με τον πολλαπλασιασμό της κρουστικής απόκρισης με ένα ορθογώνιο window του τύπου: δηλαδή Στο πεδίο συχνότητας ο παραπάνω πολλαπλασιασμός στο χρονικό πεδίο αντιστοιχεί στη συνέλιξη του HD(ω) με το W(ω), όπου W(ω) είναι ο μετασχηματισμός Fourier της συνάρτησης παραθύρου w(n).

55 Επίδραση χρονικού παραθύρου w(n)
Επειδή το W(ω) έχει το κλασσικό sin(x)/x σχήμα, δημιουργείται μία ζώνη μετάβασης (transition width), το εύρος της οποίας εξαρτάται από τον αριθμό Μ αφού η συνάρτηση sinc έχει το 1ο μηδενικό στη συχνότητα 2π/Μ. Το αποτέλεσμα της συνέλιξης στο πεδίο συχνοτήτων φαίνεται στο παρακάτω σχήμα.

56 Επίδραση χρονικού παραθύρου w(n)
For rectangular window Using

57 Επίδραση χρονικού παραθύρου w(n)
For rectangular window The running integral of the window amplitude response is necessary in the accurate analysis of the transition bandwidth and the stop-band attenuation.

58 Επίδραση χρονικού παραθύρου w(n)
Transition width is determined by the main lobe of the frequency response of signal w(n) The main lobe width depends on the length of the filter Stop-band ripples (attenuation) are determined by the side lobes of the frequency response of signal w(n) For rectangular window w(n) these two parameters are given by Exact transition width = 1.8π/Μ As = 21 dB Question: how can we increase the stopband attenuation?

59 Επίδραση χρονικού παραθύρου w(n)
Use a different w(n)

60 Επίδραση χρονικού παραθύρου w(n)

61 Επίδραση χρονικού παραθύρου w(n)
Bartlett window Bartlett suggested a more gradual transition in the form of a triangular window, which is given by: Hanning window This is a raised cosine window function given by:

62 Επίδραση χρονικού παραθύρου w(n)
Hamming window This window is similar to the Hanning window except that it has a small amount of discontinuity and is given by: Blackman window This window is also similar to the previous two but contains a second harmonic term and is given by:

63 Επίδραση χρονικού παραθύρου w(n)
Kaiser window This is one of the most useful and optimum windows. It is optimum in the sense of providing a large main lobe width for the given stopband attenuation, which implies the sharpest transition width. The window function is due to J. F. Kaiser: I0 = modified zero-order Bessel function β = parameter that depends on M and that can be chosen to yield various transition widths and near-optimum stopband attenuation.

64 Επίδραση χρονικού παραθύρου w(n)
Kaiser window properties This window can provide different transition widths for the same M, which is something other windows lack. β Transition width (Δω) Min. stop attn dB 2.12 3π/M 30 4.54 5.8π/M 50 5.66 7.7π/Μ 60 6.76 8.6π/M 70 8.96 11.4π/M 90

65 Design equations for Kaiser window
Given Normalized transition width Filter order Parameter

66 Επίδραση χρονικού παραθύρου w(n)
Το εύρος μετάβασης (transition width) του φίλτρου καθορίζεται από το εύρος του κύριου λοβού του window, που τώρα είναι μεγαλύτερο από ότι με το ορθογώνιο παράθυρο. Όμως, οι πλαϊνοί λοβοί είναι υπεύθυνοι για τους κυματισμούς στη passband και στη stopband περιοχή, και τώρα έχουν μειωθεί σε σχέση με το ορθογώνιο παράθυρο. Window Method Specify the desired frequency response Select a window function based on the As filter specification and estimate the number of filter coefficients, N Obtain the ideal impulse response hd(n) (truncated to N values) Obtain N coefficients of the window function, w(n) Obtain the FIR filter coefficients as h(n) = hd(n) x w(n)

67 Επίδραση χρονικού παραθύρου w(n)

68 Επίδραση χρονικού παραθύρου w(n)
Design a digital FIR lowpass filter with the following specifications: Wp=0.2π Ws=0.3π Rp=0.25 dB As=50 dB Choose an appropriate window function and determine the impulse response and provide a plot of the frequency response of the designed filter.

69 Επίδραση χρονικού παραθύρου w(n)
clear wp=0.2*pi; ws=0.3*pi; tr_width = ws - wp; M = ceil(6.6*pi/tr_width) + 1 n=[0:1:M-1]; wc = (ws+wp)/2; % Ideal LPF cutoff frequency hd = ideal_lp(wc,M) w_ham = hamming(M)' h = hd .* w_ham;

70 Επίδραση χρονικού παραθύρου w(n)
[db,mag,pha,grd,w]=freqz_m(h,1); plot(w/pi,db) title('Magnitude Response in dB') xlabel('w/pi') ylabel('20*log10(|H(e^{jw})|') delta_w=2*pi/1000; Rp=-(min(db(1:1:wp/delta_w+1))) As=-round(max(db(ws/delta_w+1:1:501)))

71 Επίδραση χρονικού παραθύρου w(n)
Rp = As = 52

72 Επίδραση χρονικού παραθύρου w(n)
plot(w/pi,db) title('Magnitude Response in dB') xlabel('w/pi') ylabel('20*log10(|H(e^{jw})|')

73 Other filter responses: High Pass
The high-pass frequency response can be obtained as the complementary of the low-pass, that is

74 Other filter responses: Band-Pass
The band-pass frequency response can be obtained from a combination of 2 low-pass filters, that is LP(wc2) – LP(wc1)

75 Other filter responses: Band-Stop
The band-stop frequency response can be obtained from a combination of 2 filters, that is LP(wc1) + HP(wc2)

76 FIR filter design example using fir1
Παράδειγμα 1 Σχεδιάστε με τη μέθοδο Window ένα ψηφιακό FIR Lowpass με τις εξής προδιαγραφές Passband edge frequency 1 KHz Stopband edge frequency 4.3 KHz Fs 10 KHz Use Hamming window.

77 FIR filter design example using fir1
The fir1 function in matlab is used to design FIR filters using the window method. The basic command h = fir1(N-1, Fc) assumes a Hamming window and low-pass filter with cuttoff Fc Fc should be normalized to the Nyquist frequency Fs/2 The syntax can be extended to different filter types and window functions, as follows: h = fir1(N-1, Fc, ‘filter-type’) % filter type = high or stop % for both bandpass and bandstop filters Fc is a vector of 2 cutoff frequencies h = fir1(N-1,Fc, window) % window = boxcar(N), blackman(N)… hamming (N), hanning(N), kaiser(N,beta) h = fir1(N-1, Fc, ‘filter-type’, window)

78 FIR filter design example using fir1
Δf = (4.3 – 1)/10 =0.33 (normalized digital transition band) Δf = 3.3/Ν → N = 3.3/0.33 = 10  N=11 (Type I) Επίσης cutoff frequency παίρνουμε στο μέσο της transition band Fc = 1+(4.3 – 1)/2 = 2.65 KHz Kανονικοποιημένη ως προς την συχνότητα Nyquist (Fs/2): Fc (normalized λόγω matlab function fir1) = 2.65/5 = 0.53 fc = 0.53; N=11; hd=fir1(N-1,fc,boxcar(N)); % boxcar for rectangular window wn=hamming(N); hn=fir1(N-1,fc,wn);

79 FIR filter design example 1
hd' ans = 0.0529 0.0273 0.2955 0.4942 hn' ans = 0.0045 0.0049 0.2875 0.5272 n=[0:10]; plot(n,hn,'bx-',n,hd,'ro-') xlabel('sample index') ylabel('impulse response') legend('hamming', 'rectangular')

80 FIR filter design example 1
Fs=10000; [H,f]=freqz(hn,1,256, Fs); % freq response data stored in H mag=20*log10(abs(H)); plot(f,mag), grid on xlabel('Frequency (Hz)') ylabel('Magnitude Response (dB)') hold on [Hd,f]=freqz(hd,1,256, Fs); magd=20*log10(abs(Hd)); plot(f,magd,'r') legend('Hamming', 'Rectangular')

81 FIR filter design example 2
Σχεδιάστε ένα ψηφιακό FIR lowpass filter με τις παρακάτω προδιαγραφές Επιλέξτε κατάλληλη συνάρτηση παραθύρου. Υπολογίστε την κρουστική απόκριση και δώστε την απόκριση συχνότητας του φίλτρου. Απάντηση Τα παράθυρα Hamming και Blackman δίνουν εξασθένιση (attenuation) περισσότερο από 50 dB. Ας επιλέξουμε το Hamming παράθυρο.

82 FIR filter design example 2
clear; wp=0.2*pi; ws=0.3*pi; tr_width = ws - wp; M = ceil(6.6*pi/tr_width) + 1 % M = 67 n=[0:1:M-1]; wc = (ws+wp)/2; % ideal LowPass cutoff frequency hd = ideal_lp(wc, M); w_ham = (hamming(M))'; h = hd .* w_ham;

83 FIR filter design example 2
[H, w] = freqz(h, 1, 500); % obtain frequency response in % 500 frequencies from 0 -pi delta_w = pi/500; H_dB = 20*log10(abs(H)); Rp = -min(H_dB(1:1:wp/delta_w+1)) % Actual Passband Ripple As = -round(max(H_dB(ws/delta_w+1:1:500))) %Minimum Stopband Attenuation M = 67 Rp = As = 52

84 FIR filter design example 2
figure(1) stem(n,h) xlabel('n') ylabel('impulse response… h(n)')

85 FIR filter design example 2
figure(2) plot(w/pi, H_dB) xlabel('frequency … in pi units') ylabel('20*log10(abs(H))')

86 FIR filter design example 3
Σχεδιάστε ένα ψηφιακό FIR bandpass filter με τις παρακάτω προδιαγραφές Lower stopband edge Lower passband edge Upper passband edge Upper stopband edge Επιλέξτε κατάλληλη συνάρτηση παραθύρου. Υπολογίστε την κρουστική απόκριση και δώστε την απόκριση συχνότητας του φίλτρου. Απάντηση Στο φίλτρο αυτό υπάρχουν δύο ζώνες μετάβασης και οι οποίες πρέπει να είναι ίδιες για τη σχεδίαση με τη μέθοδο Window. Για την προδιαγραφή εξασθένισης στη περιοχή αποκοπής (stopband) μπορούμε να έχουμε παράθυρα Kaiser ή Blackman. Επιλέγουμε Blackman παράθυρο.

87 FIR filter design example 3
clear; ws1=0.2*pi; wp1=0.35*pi; wp2=0.65*pi; ws2=0.8*pi; tr_width = min ((wp1 - ws1), (ws2-wp2)); M = ceil(11*pi/tr_width) + 1 n=[0:1:M-1]; wc1 = (ws1+wp1)/2; wc2 = (wp2+ws2)/2; hd = ideal_lp(wc2, M) - ideal_lp(wc1, M); w_bla = (blackman(M))'; h = hd .* w_bla;

88 FIR filter design example 3
[H, w] = freqz(h, 1, 500); % obtain frequency response in % 500 frequencies from 0 -pi delta_w = pi/500; H_dB = 20*log10(abs(H)); Rp = -min(H_dB(wp1/delta_w+1:1:wp2/delta_w+1)) % Actual Passband Ripple As = -round(max(H_dB(ws2/delta_w+1:1:500))) %Minimum Stopband Attenuation M = 75 Rp = As = 75

89 FIR filter design example 3
figure(1) stem(n,h) xlabel('n') ylabel('impulse … response h(n)')

90 FIR filter design example 3
figure(2) plot(w/pi, H_dB) xlabel('frequency in pi units') ylabel('20*log10(abs(H))')

91 FIR filter design example 4
Σχεδιάστε με τη μέθοδο Window ένα ψηφιακό FIR bandpass με τις εξής προδιαγραφές Passband 150 – 250 Hz Transition width 50 Hz Passband ripple 0.1 dB Stopband attenuation 60 dB Sampling frequency 1KHz Using Kaiser window.

92 FIR filter design example 4
Για Kaiser έχουμε οπότε N = 73 The ripple parameter is Οι ιδανικές cutoff συχνότητες λαμβάνονται στο μέσο της ζώνης μετάβασης

93 FIR filter design example 4
clear; Fs = 1000; Fn = Fs/2; N = 73; beta = 5.65; fc1 = 125/Fn; %normalized for Matlab function fir1 fc2 = 275/Fn; %normalized for Matlab function fir1 FC = [fc1, fc2] % vector with 2 cutoffs hn = fir1(N-1, FC, kaiser(N, beta)); [H,f]=freqz(hn,1,256, Fs); mag=20*log10(abs(H)); figure(2) plot(f,mag), grid on xlabel('Frequency (Hz)'); ylabel('Magnitude Response (dB)'); legend('Kaiser')

94 FIR filter design example 4

95 FIR filter design example 5: High pass
Σχεδιάστε το ιδανικό ψηφιακό FIR highpass filter με τις παρακάτω προδιαγραφές % Ideal highpass filter computation function hd = ideal_hp(wc, M) alpha = (M-1)/2; n=[0:1:M-1]; m = n-alpha+eps; hd = - sin(wc*m)./(pi*m); hd(alpha+1)=1-wc/pi;

96 FIR filter design example 5: High pass
hd=ideal_hp(0.5*pi,19); [H,w]=freqz(hd,1,200); plot(w/pi, 20*log10(abs(H))) xlabel('w/pi') ylabel('20*log10(abs(H))')

97 Μέθοδος δειγματοληψίας συχνότητας
Ας υποθέσουμε πως επιθυμούμε να αποκτήσουμε FIR συντελεστές του φίλτρου, του οποίου η συχνότητα απόκρισης απεικονίζεται στο διπλανό Σχήμα. Μπορούμε να αρχίσουμε παίρνοντας Ν δείγματα από την απόκριση συχνότητας σε συχνότητες f(k) = k Fs / N, k = 0, 1,…, Ν-1.

98 Frequency sampling method (1/6)
Οι συντελεστές φίλτρου h(n) μπορούν να αποκτηθούν από τον αντίστροφο DFT (IDFT) των δειγμάτων συχνότητας: όπου H(k), k = 0,1…, N-1, είναι τα δείγματα της ιδανικής απόκρισης συχνότητας για ψηφιακές γωνιακές συχνότητες Από το Σχήμα 1b παρατηρούμε ότι γνωρίζουμε μόνο τα πλάτη της απόκρισης συχνότητας αλλά όχι την φάση, ώστε να χρησιμοποιήσουμε τον IDFT για να βρούμε την κρουστική απόκριση h(n).

99 Frequency sampling method (2/6)
Γενικά λόγω της συμμετρίας ή αντισυμμετρίας που παρουσιάζουν τα FIR τόσο για άρτιο όσο και για περιττό μήκος Ν της κρουστικής τους απόκρισης, παίρνουμε 4 είδη FIR με γραμμική φάση. Η απόκριση συχνότητας για όλα τα FIR μπορεί να γραφεί από τη σχέση όπου είναι η απόκριση πλάτους του φίλτρου και η γραμμική φάση είναι . Η φάση της απόκρισης συχνότητας για FIR φίλτρα είναι γνωστή και για τα 4 είδη (Types) FIR που υπάρχουν.

100 Frequency sampling method (3/6)
Επομένως στην μέθοδο δειγματοληψίας συχνότητας, η απόκριση συχνότητας δίνεται από όπου υπολογίζουμε την απόκριση πλάτους στις ψηφιακές γωνιακές συχνότητες , όπου λόγω συμμετρίας της απόκρισης πλάτους γύρω από το ω=π.

101 Frequency sampling method (4/6)
Η προϋπόθεση ότι h(n) θα έχει πραγματικές τιμές απαιτεί ότι η απόκριση συχνότητας θα είναι συζυγής συμμετρική (conjugate symmetric). Θεωρήστε Ν άρτιο: (1) Επειδή ο Discrete Fourier Transform είναι περιοδικός, έχουμε (2) Επομένως από την (1) και (2) έχουμε:

102 Frequency sampling method (5/6)
Η φάση προκύπτει με δειγματοληψία της στις και δίνεται από:

103 Frequency sampling method (6/6)
Η επιθυμητή κρουστική απόκριση υπολογίζεται από τη σχέση

104 Frequency sampling method using fir2
The fir2 command is used to design FIR filters with arbitrary frequency response characteristics h = fir2(N-1, F, H) calculates a N-length FIR filter the vector F specifies the normalized frequency points in the range 0 to 1 (with frequency values normalized to half the sampling frequency, as before) the vector H specifies the desired magnitude response at the frequency points specified by F.

105 Frequency sampling method using fir2
Υπολογίστε τους συντελεστές ενός φίλτρου με 15 συντελεστές το οποίο έχει τις παρακάτω τιμές για το μέτρο της απόκρισης συχνότητας clear >> N=15; >> fd=[0 1/7 2/7 3/7 4/7 5/7 6/7 1]; >> Hd=[ ]; >> hn=fir2(N-1, fd, Hd);

106 Frequency sampling method using fir2
>> Fs=2000; >> [H,f]=freqz(hn,1,512,Fs); >> plot(f, abs(H)), grid on >> xlabel('Frequency (Hz)') >> ylabel('Magnitude')

107 Frequency sampling method
με τη μέθοδο δειγματοληψίας συχνότητας. Έστω ότι επιλέγουμε Ν = 20 Τότε Επομένως έχουμε 3 δείγματα απόκρισης συχνότητας στην περιοχή διέλευσης ζώνης (passband) [0≤ω≤ωp] και 7 δείγματα στη περοχή αποκοπής (stopband) [ωs ≤ω≤π]

108 Frequency sampling method
Δηλαδή η ιδανική απόκριση πλάτους είναι : Επίσης, επειδή Ν=20 και πρόκειται για Type-2 FIR , οπότε

109 Frequency sampling method
N = 20; alpha = (N-1)/2; k = 0:N-1; wk = (2*pi/N)*k; Hrs = [1,1,1,zeros(1,15),1,1]; %ideal amplitude response sampled k1 = 0:floor((N-1)/2); k2 = floor((N-1)/2)+1:N-1; angH = [-alpha*(2*pi/N)*k1, alpha*(2*pi/N)*(N-k2)]; %linear phase H = Hrs.*exp(j*angH); % ideal frequecy response h = real(ifft(H, N)); % h is the IDFT of H

110 Frequency sampling method
[H_pr, w] = freqz(h,1,256) [H_pr2, w2] = freqz(h,1,10) % freq response sampled at wk subplot(2,1,1) stem(h, 'o') xlabel('n') ylabel('h(n)') subplot(2,1,2) plot(w/pi,abs(H_pr),w2/pi,abs(H_pr2),'o') xlabel('frequency in pi units') ylabel('Hr(w)')

111 Frequency sampling method

112 Frequency sampling method with optimization
Πρέπει τώρα να εξετάσουμε αν ο παραπάνω σχεδιασμός με τη μέθοδο δειγματοληψίας συχνότητας ικανοποιεί την αρχική προδιαγραφή για τη stopband attenuation As [H, w] = freqz(h, 1, 500); % obtain frequency response in % 500 frequencies from 0 -pi delta_w = pi/500; H_dB = 20*log10(abs(H)); Rp = -min(H_dB(1:1:wp/delta_w+1)) % Actual Passband Ripple % Stopband Attenuation As = -round(max(H_dB(ws/delta_w+1:1:500))) %ws/delta_w+1=151 >> As=15

113 Frequency sampling method with optimization
Για να αυξήσουμε τη stopband attenuation As με τη μέθοδο δειγματοληψίας συχνότητας πρέπει να αυξήσουμε το μήκος Ν να προσδιορίσουμε κάποια ή κάποιες τιμές στην περιοχή μετάβασης ‘Εστω Ν=40, οπότε έχουμε 1 δείγμα στην περιοχή μετάβασης 0.2π<ω<0.3π Επειδή τα δείγματα στην περιοχή μετάβασης είναι στο k=5 και στο k=40-5=35. Έστω η τιμή του δείγματος είναι Τ1

114 Frequency sampling method with optimization
Επειδή Ν=40 T1=0.5; >> As = 30 Τ1=0.39 >>As = 43

115 Frequency sampling method with optimization
Εστω Ν=60, οπότε έχουμε 2 δείγματα στην περιοχή μετάβασης 0.2π<ω<0.3π, με τιμές έστω Τ1 και Τ2 Από πίνακες προκύπτει ότι οι βέλτιστες (optimized) τιμές για τα Τ1 και Τ2 είναι Τ1 = και Τ2= Χρησιμοποιώντας τις παραπάνω τιμές, το Αs βρίσκεται >>As = 63 το οποίο ικανοποιεί την προδιαγραφή για As > 50 dB. Παρατηρήστε ότι το μήκος Ν=60 είναι μικρότερο από αυτό με τη μέθοδο παραθύρου Ν=73.

116 Linear-Phase FIR Filter Design by Optimization
Amplitude response for all 4 types of linear-phase FIR filters can be expressed as where

117 Linear-Phase FIR Filter Design by Optimization
Αφού έχουμε μία κοινή μαθηματική έκφραση για το μπορούμε να ορίσουμε το Chebyshev approximation problem ως εξής: έστω η συνάρτηση σφάλματος επιθυμητής και εφικτής απόκρισης πλάτους: Υπολογίστε τους συντελεστές Ώστε να ελαχιστοποιείται η συνάρτηση σφάλματος στις περιοχές passband και stopband.

118 Weighted function W(ω)
Το W(ω) ορίζεται έτσι ώστε το μέγιστο σφάλμα τόσο στην passband όσο και στη stopband να είναι Επομένως αν πετύχουμε ελαχιστοποίηση του σφάλματος σε σχέση με το ικανοποιούμε αυτόματα και την απαίτηση για το

119 Linear-Phase FIR Filter Design by Optimization
Modified form of weighted error function Where and therefore

120 Linear-Phase FIR Filter Design by Optimization
Optimization Problem - Determine which minimizes the peak absolute value of over the specified frequency bands After has been determined, construct the original and hence h(n)

121 Related problem to min-max
How many local maxima and minima exist in the error function E(ω) for a given M-point filter? The answer is in the expression of P(ω), as a Chebyshev polynomial That is P(ω) is an L-th order polynomial of cos(ω), cos(ω) is a monotonic function in 0 < ω < π P(ω) has at most (L-1) local extrema in the open interval 0 < ω < π If we include the end points ω=0 and ω=π, P(ω) has at most (L+1) local extrema The filter specs have to be met at the edge frequencies, so the error function has at most L+3 extrema in region S.

122 Find coefficients β(n) of P(ω) using trigonometric identities Example: h(n)= [ ]/15. M=7 and h(h) symmetric Type 1

123 w=[0:1:200]. pi/200; >> p=(8/15). cos(w). ^2+(8/15). cos(w)
w=[0:1:200]*pi/200; >> p=(8/15).*cos(w).^2+(8/15).*cos(w).^3; >> plot(w/pi, p) P(w) has L-1 = (M-1)/2 – 1 = 2 extrema in the open interval 0 < ω < π

124 The error function E(w) has L+3 = 6 extrema Based on this, we return to the problem

125 Linear-Phase FIR Filter Design by Optimization
Chebyshev approximation problem: Define S as any closed subset of closed interval [0, π] Determine P(ω) such that Solution: Alternation Theorem In order that P(ω) be the unique min-max approximation to Ηdr(ω) on S, it is necessary and sufficient that E(ω) has at least L+2 “alternations” in S: A solution exists and it is unique, but how do we obtain it?

126 Parks-McClellan algorithm (1/2)
Unknown: filter length M, ωi , a(n), δ Parks and McClellan gave an iterative solution using the Remez exchange algorithm. It assumes that the filter length M, and ratio δs/ δp are known. Then we choose the weighting function If M is chosen correctly, then δ = δs when the solution is found.

127 Parks-McClellan algorithm (2/2)
The Parks-McClellan algorithm begins by guessing (L+2) external frequencies ωi and estimating the maximum error δ at these frequencies. It then fits an L-th order polynomial given by through points Local maximum errors are determined in more frequencies in S and the external frequencies ωi are adjusted to the new external values. The iteration continues until the optimum set of frequencies ωi and the global maximum error δ αre found.

128 Related problem to min-max
The iterative procedure yields polynomial P(ω) From the expression of P(ω) The coefficients β(n) are determined. Finally, the coefficients α(n) as well as the impulse response h(n) are computed. In Matlab: [h] = remez(N, f, m, weights, ftype) filter length M=N+1 f contains band-edge frequencies in units of π, m contains desired magnitude response at frequencies in vector f

129 FIR Digital Filter Order Estimation
Solution is obtained via the Alternation Theorem The optimal solution has equiripple behaviour consistent with the total number of available parameters. Parks and McClellan used the Remez algorithm to develop a procedure for designing linear FIR digital filters. Kaiser’s Formula: that is, M is inversely proportional to transition band width and not on transition band location Both formulae provide only an estimate of the required filter order M. If specifications are not met, increase filter order until they are met.

130 Using Parks-McClellan algorithm
Ας σχεδιάσουμε το προηγούμενο lowpass φίλτρο χρησιμοποιώντας τον αλγόριθμο Parks-McClellan wp=0.2*pi; ws=0.3*pi; Rp = 0.25; As=50; delta1 = (10^(Rp/20)-1)/ (10^(Rp/20)+1) delta2=(1+delta1)*(10^(-As/20)) weights=[delta2/delta1, 1] deltaf=(ws-wp)/(2*pi) M = ceil((-20*log10(sqrt(delta1*delta2))-13)/(14.6*deltaf)+1) >> M=43

131 Using Parks-McClellan algorithm
f = [0 wp/pi ws/pi 1]; m = [ ]; h = remez(M-1, f, m, weights); [H, w] = freqz(h, 1, 500); % obtain frequency response in % 500 frequencies from 0 -pi delta_w = pi/500; H_dB = 20*log10(abs(H)); As = -round(max(H_dB(ws/delta_w+1:1:500))) >> As = M=M+1 … until we find As > 50 …


Κατέβασμα ppt "Ψηφιακή Επεξεργασία Σήματος FIR Filter Design Methods"

Παρόμοιες παρουσιάσεις


Διαφημίσεις Google