Académique Documents
Professionnel Documents
Culture Documents
• First-order filters N M
• Ideal filters ak y[n − k] = bk x[n − k]
k=0 k=0
• Practical filters M −jwk
k=0 bk e
• Frequency-selective filter specifications Y (ejω ) = N X(ejω )
a e −jwk
k=0 k
• Ripple versus filter order tradeoff
• Discrete-time filters are divided into two categories
• Application example – Finite impulse response (FIR): h[n] = 0 for some a and b
such that −∞ < a < n < b < +∞
– Infinite impulse response (IIR): not FIR
• Filters that can be described with difference-equations
– FIR: N = 0
– IIR: N > 0
• A simple FIR filter is the moving average filter
• A simple IIR filter is the first-order lowpass filter
Portland State University ECE 223 DT Filters Ver. 1.03 1 Portland State University ECE 223 DT Filters Ver. 1.03 2
Portland State University ECE 223 DT Filters Ver. 1.03 3 Portland State University ECE 223 DT Filters Ver. 1.03 4
Example 1: Ωc versus a Example 1: H(ejω ) for various a
3.5
1
a=0.1
3 a=0.2
|H(e )|
jω
0.5 a=0.3
2.5 a=0.4
ω (rad/sample)
a=0.5
2 a=0.6
0
−3 a=0.7
−2 −1 0 1 2 3
a=0.8
1.5
a=0.9
c
50
∠ H(ejω) (o)
1
0
0.5
−50
0
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
a −3 −2 −1 0 1 2 3
Frequency (rads/sample)
Portland State University ECE 223 DT Filters Ver. 1.03 5 Portland State University ECE 223 DT Filters Ver. 1.03 6
%==============================================================================
32 % Plot the relationship between cutoff frequency and a
%==============================================================================
x[n], y0.1[n], y0.6[n]
a = 0.00001:0.01:1;
30 wc = acos((1-4*a+a.^2)./(-2*a));
figure
28 FigureSet(1,’LTX’);
h = plot(a,wc,’LineWidth’,1.0);
ylabel(’\omega_c (rad/sample)’);
26 xlabel(’a’);
grid on;
box off;
24 AxisSet(8);
print -depsc FOCutoff;
Portland State University ECE 223 DT Filters Ver. 1.03 7 Portland State University ECE 223 DT Filters Ver. 1.03 8
end; for cnt = 2:nd,
y2(cnt) = a*y2(cnt-1) + (1-a)*x(cnt);
figure end;
FigureSet(1,’LTX’);
subplot(2,1,1); figure
h = plot(w,abs(H)); FigureSet(1,’LTX’);
xlim([-pi pi]); h = plot(n,x,’b’,n,y1,’r’,n,y2,’g’);
ylim([0 1.05]); set(h,’LineWidth’,0.6);
legend(’a=0.1’,’a=0.2’,’a=0.3’,’a=0.4’,’a=0.5’,’a=0.6’,’a=0.7’,’a=0.8’,’a=0.9’,2); ylabel(’x[n], y_{0.1}[n], y_{0.6}[n]’);
ylabel(’|H(e^{j\omega})|’); xlabel(’Time (day)’);
grid on;
title(’Intel Closing Daily Price Over 1 Year’);
box off;
xlim([0 nd-1]);
subplot(2,1,2);
ylim([19 36]);
h = plot(w,rem(angle(H)*180/pi,180));
xlim([-pi pi]); box off;
ylim([-70 70]); grid on;
ylabel(’\angle H(e^{j\omega}) (^o)’); AxisSet(8);
xlabel(’Frequency (rads/sample)’); legend(’Raw signal’,sprintf(’Cutoff:%4.2f’,w1),sprintf(’Cutoff:%4.2f’,w2),4);
grid on; print -depsc FOSignalFiltered;
box off;
AxisSet(8);
print -depsc FOTransferFunctions;
%==============================================================================
% Filter & Plot
%==============================================================================
a = 0.58; % cutoff frequency approximately 0.1
w1 = acos((1-4*a+a.^2)./(-2*a));
y1 = zeros(nd,1);
for cnt = 2:nd,
y1(cnt) = a*y1(cnt-1) + (1-a)*x(cnt);
end;
Portland State University ECE 223 DT Filters Ver. 1.03 9 Portland State University ECE 223 DT Filters Ver. 1.03 10
Portland State University ECE 223 DT Filters Ver. 1.03 11 Portland State University ECE 223 DT Filters Ver. 1.03 12
Ripple Tradeoff Example 2: Lowpass Filter Specifications
Design a lowpass filter that meets the following specifications:
Filter Order Passband Stopband
Butterworth Largest Smooth Smooth • The passband ripple is no more than 0.4455 dB
Chebyshev Type I Moderate Ripple Smooth (0.95 ≤ |H(ejω )| ≤ 1)
Chebyshev Type II Moderate Smooth Ripple • The stopband attenuation is at least 26.02 dB (|H(ejω )| ≤ 0.05)
Elliptic Lowest Ripple Ripple
• The passband ranges from 0–0.2π rad/sample
• The four popular filter types differ in how they satisfy the
• The stopband ranges from 0.3π–π rad/sample
specifications
• In the passband and stopband, each filter is either smooth or Plot the magnitude of the resulting transfer function on a linear-linear
contains ripple plot, the impulse response, and the step response. Try the
Butterworth, Chebyshev I, Chebyshev II, and elliptic filters.
• Elliptic filters are also called equiripple filters and Cauer filters
Portland State University ECE 223 DT Filters Ver. 1.03 13 Portland State University ECE 223 DT Filters Ver. 1.03 14
Butterworth Lowpass Filter Transfer Function Order: 10 Butterworth Lowpass Filter Impulse Response Order:10
0.25
1
0.2
0.8
0.15
0.6 0.1
|H(ejω)|
h[n]
0.05
0.4
0
0.2
−0.05
0 −0.1
0 0.5 1 1.5 2 2.5 3 0 10 20 30 40 50 60 70 80 90 100
Frequency (rad/sample) Time (n)
Portland State University ECE 223 DT Filters Ver. 1.03 15 Portland State University ECE 223 DT Filters Ver. 1.03 16
Example 3: Butterworth Lowpass Example 3: Chebyshev-I Lowpass
Butterworth Lowpass Filter Step Response Order:10 Chebyshev−I Lowpass Filter Transfer Function Order: 5
1.4
1
1.2
0.8
1
0.8 0.6
|H(ejω)|
h[n]
0.6
0.4
0.4
0.2
0.2
0 0
0 10 20 30 40 50 60 70 80 90 100 0 0.5 1 1.5 2 2.5 3
Time (n) Frequency (rad/sample)
Portland State University ECE 223 DT Filters Ver. 1.03 17 Portland State University ECE 223 DT Filters Ver. 1.03 18
Chebyshev−I Lowpass Filter Impulse Response Order:5 Chebyshev−I Lowpass Filter Step Response Order:5
0.25 1.4
0.2 1.2
0.15 1
0.1 0.8
h[n]
h[n]
0.05 0.6
0 0.4
−0.05 0.2
−0.1 0
0 10 20 30 40 50 60 70 80 90 100 0 10 20 30 40 50 60 70 80 90 100
Time (n) Time (n)
Portland State University ECE 223 DT Filters Ver. 1.03 19 Portland State University ECE 223 DT Filters Ver. 1.03 20
Example 3: Chebyshev-II Lowpass Example 3: Chebyshev-II Lowpass
Chebyshev−II Lowpass Filter Transfer Function Order: 5 Chebyshev−II Lowpass Filter Impulse Response Order:5
0.25
1
0.2
0.8
0.15
0.6 0.1
|H(ejω)|
h[n]
0.05
0.4
0
0.2
−0.05
0 −0.1
0 0.5 1 1.5 2 2.5 3 0 10 20 30 40 50 60 70 80 90 100
Frequency (rad/sample) Time (n)
Portland State University ECE 223 DT Filters Ver. 1.03 21 Portland State University ECE 223 DT Filters Ver. 1.03 22
Chebyshev−II Lowpass Filter Step Response Order:5 Elliptic Lowpass Filter Transfer Function Order: 4
1.4
1
1.2
0.8
1
0.8 0.6
|H(ejω)|
h[n]
0.6
0.4
0.4
0.2
0.2
0 0
0 10 20 30 40 50 60 70 80 90 100 0 0.5 1 1.5 2 2.5 3
Time (n) Frequency (rad/sample)
Portland State University ECE 223 DT Filters Ver. 1.03 23 Portland State University ECE 223 DT Filters Ver. 1.03 24
Example 3: Elliptic Lowpass Example 3: Elliptic Lowpass
Elliptic Lowpass Filter Impulse Response Order:4 Elliptic Lowpass Filter Step Response Order:4
0.25 1.4
0.2 1.2
0.15 1
0.1 0.8
h[n]
h[n]
0.05 0.6
0 0.4
−0.05 0.2
−0.1 0
0 10 20 30 40 50 60 70 80 90 100 0 10 20 30 40 50 60 70 80 90 100
Time (n) Time (n)
Portland State University ECE 223 DT Filters Ver. 1.03 25 Portland State University ECE 223 DT Filters Ver. 1.03 26
Portland State University ECE 223 DT Filters Ver. 1.03 27 Portland State University ECE 223 DT Filters Ver. 1.03 28
FigureSet(1,’LTX’);
end;
n = 0:100;
[x,t] = impulse(sys,n);
h = stem(t,x,’b’);
set(h(1),’MarkerFaceColor’,’b’);
set(h(1),’MarkerSize’,2);
ylabel(’h[n]’);
xlabel(’Time (n)’);
title(sprintf(’%s Lowpass Filter Impulse Response Order:%d’,stFilter,od));
box off;
hold on;
h = plot(xlim,[0 0],’k:’);
hold off;
AxisSet(8);
st = sprintf(’print -depsc Lowpass%sImpulse’,stFilter);
eval(st);
%==============================================================================
% Step Response
%==============================================================================
figure;
FigureSet(1,’LTX’);
n = 0:100;
[x,t] = step(sys,n);
h = stem(t,x,’b’);
set(h(1),’MarkerFaceColor’,’b’);
set(h(1),’MarkerSize’,2);
ylabel(’h[n]’);
xlabel(’Time (n)’);
title(sprintf(’%s Lowpass Filter Step Response Order:%d’,stFilter,od));
box off;
hold on;
h = plot(xlim,[1 1],’k:’);
hold off;
AxisSet(8);
st = sprintf(’print -depsc Lowpass%sStep’,stFilter);
eval(st);
Portland State University ECE 223 DT Filters Ver. 1.03 29 Portland State University ECE 223 DT Filters Ver. 1.03 30
Portland State University ECE 223 DT Filters Ver. 1.03 31 Portland State University ECE 223 DT Filters Ver. 1.03 32
Application Example 1: Frequency-Selective Filters Application Example 1: Frequency-Selective Filters
50
Microelectrode Recording
40
0.8
FT Magnitude
30
0.6 20
10
0.4
0
0 500 1000 1500 2000
0.2
500
0
400
FT Magnitude
−0.2 300
200
−0.4
100
−0.6 0
0 50 100 150 200 250 300
1 1.2 1.4 1.6 1.8 2 2.2 2.4 2.6 2.8
Time (sec)
Portland State University ECE 223 DT Filters Ver. 1.03 33 Portland State University ECE 223 DT Filters Ver. 1.03 34
FT Magnitude
0.5 30
20
0
10
−0.5 0
0 500 1000 1500 2000
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2
Time (sec) 50
FT Magnitude Filtered
40
0.5 30
20
0
10
−0.5 0
0 500 1000 1500 2000
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2
Time (sec)
Portland State University ECE 223 DT Filters Ver. 1.03 35 Portland State University ECE 223 DT Filters Ver. 1.03 36
Application Example 1: MATLAB Code subplot(2,1,1);
h = plot(f,abs(X(k)),’r’);
set(h,’LineWidth’,0.6);
%function [] = MER(); xlim([min(f) max(f)]);
close all; ylim([0 50]);
set(gca,’XTick’,[0:500:max(f)]);
[x,fs,nbits] = wavread(’Henderson2.wav’); box off;
x = decimate(x,2); ylabel(’FT Magnitude’);
fs = fs/2; subplot(2,1,2);
h = plot(f,abs(X(k)),’r’);
k = round(fs*1):round(fs*3); % Look at only 5 s set(h,’LineWidth’,0.6);
x = x(k); xlim([0 300]);
nx = length(x); ylim([0 500]);
%set(gca,’XTick’,[0:500:max(f)]); S
figure; box off;
FigureSet(1,’LTX’); ylabel(’FT Magnitude’);
t = (k-1)/fs; AxisSet(6);
h = plot(t,x,’b’); print -depsc MERSpectralDensity;
set(h,’LineWidth’,0.6);
xrng = max(x)-min(x);
xlim([min(t) max(t)]); Wp = 210/(fs/2); % Passband ends
ylim([min(x)-0.01*xrng max(x)+0.01*xrng]); Ws = 190/(fs/2); % Stopband begins
AxisLines; Rp = -20*log10(0.95); % Maximum deviation from 1 in the passband (dB)
xlabel(’Time (sec)’); Rs = -20*log10(0.05); % Minimum attenuation in the stopband (dB)
ylabel(’’); [od,wn] = ellipord(Wp,Ws,Rp,Rs);
title(’Microelectrode Recording’); [B,A] = ellip(od,Rp,Rs,wn,’high’);
box off; stFilter = ’Elliptic’;
AxisSet(8);
print -depsc MERSignal; y = filtfilt(B,A,x);
X = fft(x,2^12); figure;
nX = length(X); FigureSet(1,’LTX’);
k = 1:floor((length(X)+1)/2); k = 1:length(x);
f = (k-1)*(fs)./(nX+1); t = (k-1)/fs;
subplot(2,1,1);
figure; t = (k-1)/fs;
FigureSet(1,’LTX’); h = plot(t,x,’b’);
Portland State University ECE 223 DT Filters Ver. 1.03 37 Portland State University ECE 223 DT Filters Ver. 1.03 38
set(h,’LineWidth’,0.6); h = plot(f,abs(Y(k)),’g’);
xrng = max(x)-min(x); set(h,’LineWidth’,0.6);
xlim([min(t) max(t)]); xlim([min(f) max(f)]);
ylim([min(x)-0.01*xrng max(x)+0.01*xrng]); ylim([0 50]);
AxisLines; set(gca,’XTick’,[0:500:max(f)]);
xlabel(’Time (sec)’); box off;
ylabel(’’); ylabel(’FT Magnitude Filtered’);
title(’Microelectrode Recording’); AxisSet(6);
box off; print -depsc MERSpectralDensityFiltered;
subplot(2,1,2);
h = plot(t,y,’g’);
set(h,’LineWidth’,0.6);
xlim([min(t) max(t)]);
ylim([min(x)-0.01*xrng max(x)+0.01*xrng]);
AxisLines;
xlabel(’Time (sec)’);
ylabel(’’);
box off;
AxisSet(8);
print -depsc MERSignalFiltered;
Y = fft(y,2^12);
nY = length(Y);
k = 1:floor((length(Y)+1)/2);
f = (k-1)*(fs)./(nY+1);
figure;
FigureSet(1,’LTX’);
subplot(2,1,1);
h = plot(f,abs(X(k)),’r’);
set(h,’LineWidth’,0.6);
xlim([min(f) max(f)]);
ylim([0 50]);
set(gca,’XTick’,[0:500:max(f)]);
box off;
ylabel(’FT Magnitude’);
subplot(2,1,2);
Portland State University ECE 223 DT Filters Ver. 1.03 39 Portland State University ECE 223 DT Filters Ver. 1.03 40