Vous êtes sur la page 1sur 10

Overview of Discrete-Time Filters Discrete-Time Filters Overview

• 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

Example 1: First-Order Filters Example 1: Workspace


Consider the following filter:
y[n] − ay[n − 1] = (1 − a)x[n]
1. Solve for the filter’s transfer function
2. Find the cutoff frequency as a function of a

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 )|

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

Example 1: Filtered Signals Example 1: MATLAB Code


%function [] = FirstOrderApplied();
close all;
Intel Closing Daily Price Over 1 Year
36 d = load(’Intel.txt’); % Closing daily price
nd = length(d);
x = d(nd:-1:1); % Reorder so first element is oldest data
34 n = (0:nd-1)’; % Discrete time index

%==============================================================================
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;

22 Raw signal %==============================================================================


Cutoff:0.56 % Plot the relationship between cutoff frequency and a
%==============================================================================
20 Cutoff:0.11 a = 0.1:0.1:0.9;
w = -pi:0.01:pi;
H = zeros(length(a),length(w));
0 50 100 150 200 for cnt = 1:length(a)
Time (day) [h,w] = freqz(1-a(cnt),[1 -a(cnt)],w);
H(cnt,:) = h;

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;

a = 0.90; % cutoff frequency approximately 0.1


w2 = acos((1-4*a+a.^2)./(-2*a));
y2 = zeros(nd,1);

Portland State University ECE 223 DT Filters Ver. 1.03 9 Portland State University ECE 223 DT Filters Ver. 1.03 10

Ideal Filters Practical Filters


Lowpass Highpass Notch • Practical filters are usually designed to meet a set of specifications
1 1 1 • Lowpass and highpass filters usually have the following
requirements
Ωc Ω Ωc Ω Ωc Ω
– Passband range
Bandpass Bandstop
1 1 – Stopband range
– Maximum ripple in the passband
Ωc1 Ωc2 Ω Ωc1 Ωc2 Ω – Minimum attenuation in the stopband
• MATLAB can be used to design standard frequency selective • If we know the specifications, we can ask MATLAB to generate
filters that meet user-specified requirements the filter for us
• These filters include: lowpass, highpass, bandpass, and bandstop • There are four popular types of standard filters
– Butterworth
• Unlike continuous-time filters, these must have cutoff frequencies
that range between 0 and π – Chebyshev Type I
– Chebyshev Type II
– Elliptic

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

Example 3: Butterworth Lowpass Example 3: Butterworth Lowpass

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

Example 3: Chebyshev-I Lowpass Example 3: Chebyshev-I Lowpass

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

Example 3: Chebyshev-II Lowpass Example 3: Elliptic Lowpass

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

Example 3: MATLAB Code %==============================================================================


% Plot Magnitude on Linear Scale
%==============================================================================
%function [] = Lowpass(); ymax = 1.05;
clear all; pbmax = 1;
close all; pbmin = 10^(-Rp/20);
sbmax = 10^(-Rs/20);
Wp = 0.20; % Passband ends wmax = pi;
Ws = 0.30; % Stopband begins w = 0:0.001:wmax;
Rp = -20*log10(0.95); % Maximum deviation from 1 in the passband (dB) [H,w] = freqz(B,A,w);
Rs = -20*log10(0.05); % Minimum attenuation in the stopband (dB) mag = abs(H);
phs = angle(H);
for cnt = 1:4, figure;
if cnt==1, FigureSet(1,’LTX’);
[od,wn] = buttord(Wp,Ws,Rp,Rs); h = patch([0 wp wp 0],[0 0 pbmin pbmin],0.5*[1 1 1]);
[B,A] = butter(od,wn); set(h,’LineWidth’,0.0001);
stFilter = ’Butterworth’; hold on;
elseif cnt==2, h = patch([0 ws ws wmax wmax 0],[pbmax pbmax sbmax sbmax ymax ymax],0.5*[1 1 1]);
[od,wn] = ellipord(Wp,Ws,Rp,Rs); set(h,’LineWidth’,0.0001);
[B,A] = ellip(od,Rp,Rs,wn); h = plot(w,mag,’r’);
stFilter = ’Elliptic’; set(h,’LineWidth’,1.0);
elseif cnt==3, hold off;
[od,wn] = cheb1ord(Wp,Ws,Rp,Rs); ylim([0 ymax]);
[B,A] = cheby1(od,Rp,wn); xlim([0 wmax]);
stFilter = ’Chebyshev-I’; grid on;
elseif cnt==4, ylabel(’|H(e^{j\omega})|’);
[od,wn] = cheb2ord(Wp,Ws,Rp,Rs); title(sprintf(’%s Lowpass Filter Transfer Function Order: %d’,stFilter,od));
[B,A] = cheby2(od,Rs,wn); xlabel(’Frequency (rad/sample)’);
stFilter = ’Chebyshev-II’; box off;
else AxisSet(8);
break; st = sprintf(’print -depsc Lowpass%s’,stFilter);
end; eval(st);

sys = tf(B,A,-1); %==============================================================================


wp = Wp*pi; % Impulse Response
ws = Ws*pi; %==============================================================================
figure;

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

Practical Filter Tradeoffs Application Example 1: Microelectrode Recording Filter


• Butterworth An engineer wishes to detect action potentials in a microelectrode
- Highest order H(ejω ) recording with a simple threshold detector. The signal contains
+ No passband or stopband ripple significant baseline drift. Action potentials typically last about 1 ms.

• Chebyshev Type I • What type of filter should the engineer use?


+ No stopband ripple • What should the filter specifications be?
• Chebyshev Type II • What should the cutoff frequency(ies) be?
+ No passband ripple
• Elliptic
+ Lowest order H(ejω )
- Passband and stopband ripple

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

Application Example 1: Frequency-Selective Filters Application Example 1: Frequency-Selective Filters


50
Microelectrode Recording
40

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

Vous aimerez peut-être aussi