Fundamentals of Digital Signal Processing Fourier Transform of continuous time signals X ( F ) FTx(t ) x(t )e j 2 Ft dt x(t ) IFTX ( F ) j 2 Ft X ( F ) e dF with t in sec and F in Hz (1/sec). Examples: T sinc FT FT rect t T0 0 0 FT e j 2 F0t F F0 FTcos2 F0t 12 e j F F0 12 e j F F0 Discrete Time Fourier Transform of sampled signals X ( f ) DTFTx[n] j 2 fn x [ n ] e n x[n] IDTFT X ( f ) 1 X ( f )e j 2 fn df 1 2 2 with f the digital frequency (no dimensions). Example: ( f f DTFT e j 2 f0n k 0 since, using the Fourier Series, k n (t k ) e j 2 nt k) Property of DTFT • f is the digital frequency and has no dimensions • X ( f ) X ( f 1) is periodic with period f = 1. X( f ) 1 1 2 1 1 2 • we only define it on one period 12 f X( f ) 1 2 1 2 f f 1 2 Sampled Complex Exponential: no aliasing x(t ) e x[n] x(nTs ) e j 2 F0t j 2 F0 n Fs Fs 1/ Ts 1. No Aliasing Fs F0 2 X (F ) F s 2 X( f ) F0 Fs 2 F 1 2 f0 1 2 digital frequency f 0 f F0 Fs Sampled Complex Exponential: aliasing x(t ) e x[n] x(nTs ) e j 2 F0t j 2 F0 n Fs Fs 1/ Ts 2. Aliasing F0 Fs 2 X( f ) X (F ) F s 2 Fs 2 F0 F f0 1 2 digital frequency f0 1 2 f F F0 round 0 Fs Fs Mapping between Analog and Digital Frequency x[n] x(nTs ) e j 2 f0n x(t ) e j 2 F0t Fs 1/ Ts F0 F0 f 0 round Fs Fs Example x(t ) e j 2 1000 t Fs 3kHz Then: • analog frequency F0 1000Hz • FT: X FT ( F ) ( F 1000) • digital frequency •DTFT: f0 F0 Fs round X DTFT ( f ) f 13 F0 Fs for | f | 1 2 1 3 round 13 1 3 Example x(t ) e j 2 2000 t Fs 3kHz Then: • analog frequency F0 2000Hz • FT: X FT ( F ) ( F 2000) • digital frequency •DTFT: f0 F0 Fs round X DTFT ( f ) f 13 for F0 Fs 2 3 round 23 13 | f | 12 Example x(t ) cos(8000 t 0.1 ) 12 e j 0.1 e j8000 t 12 e j 0.1 e j8000 t Fs 3kHz Then: • analog frequencies • FT: F0 4000Hz, F1 4000Hz X FT ( F ) 12 e j 0.1 (F 4000) 12 e j 0.1 (F 4000) • digital frequencies f0 43 round 43 43 1 13 f1 43 round 43 43 (1) 13 •DTFT X DTFT ( f ) 12 e j 0.1 f 13 12 e j 0.1 f 13 | f | 12 Linear Time Invariant (LTI) Systems and z-Transform x[n] y[n] h[n] If the system is LTI we compute the output with the convolution: y[n] h[n] * x[n] h[m]x[n m] m If the impulse response has a finite duration, the system is called FIR (Finite Impulse Response): y[n] h[0]x[n] h[1]x[n 1] ... h[ N ]x[n N ] Z-Transform X ( z ) Z x[n] n x [ n ] z n Facts: x[n] y[n] H (z ) Y ( z) H ( z) X ( z) Frequency Response of a filter: H ( f ) H ( z) z e j 2f Digital Filters x[n] H (z ) y[n] Ideal Low Pass Filter H( f ) constant magnitude in passband… 12 A fP 1 2 f H( f ) fP … and linear phase 12 1 2 passband f Impulse Response of Ideal LPF Assume zero phase shift, 1 2 hideal [ n] 1 H ( f )e j 2 fn 2 df fP fP Ae j 2 fn df hideal [n] 2 AfP sinc2 f P n fp=0.1 h[n] 0.2 0.15 f P 0.1 A 1 0.1 0.05 0 -0.05 -50 -40 -30 -20 -10 0 n 10 20 30 40 50 n This has Infinite Impulse Response, non recursive and it is noncausal. Therefore it cannot be realized. Non Ideal Ideal LPF The good news is that for the Ideal LPF lim hideal [ n] 0 n h[n] L L n h[n] L 2L n Frequency Response of the Non Ideal LPF | H( f ) | 1 1 ripple 1 1 f P f STOP stop pass f 2 stop transition region LPF specified by: • passband frequency fP or RP 20 log10 1111 dB 1 • stopband frequency f STOP • passband ripple • stopband attenuation 2 or RS 20log10 2 dB attenuation Best Design tool for FIR Filters: the Equiripple algorithm (or Remez). It minimizes the maximum error between the frequency responses of the ideal and actual filter. | H( f ) | 1 1 ripple 1 1 2 f1 attenuation 1 2 f2 h firpm N , 0, f1 , f 2 , f3 / f3 , 1,1, 0, 0 , w1 , w2 impulse response h h[0],...,h[ N ] / w1 1 / w2 0 f1 f 2 f3 12 Linear Interpolation The total impulse response length N+1 depends on: • transition region • attenuation in the stopband | H( f ) | Example: we want 2 f1 f 2 Passband: 3kHz f f 2 f1 Stopband: 3.5kHz f ~ Attenuation: 60dB 20 log10 ( 2 ) 22 Sampling Freq: 15 kHz Then: from the specs f 301 N~ We determine the order the filter 3.53.0 15.0 60 22 30 82 1 N Frequency response magnitude 20 0 -20 dB N=82 -40 -60 -80 -100 0 0.1 0.2 0.3 digital frequency magnitude 20 0 -20 N=98 dB -40 -60 -80 -100 -120 0 0.1 0.2 0.3 digital frequency 0.4 0.5 0.4 0.5 Example: Low Pass Filter Passband f = 0.2 Stopband f = 0.25 with attenuation 40dB Choose order N=40/(22*(0.25-0.20))=37 magnitude 20 | H( f ) | 0 -20 Almost 40dB!!! dB -40 -60 -80 -100 -120 0 0.1 0.2 0.3 digital frequency 0.4 0.5 f Example: Low Pass Filter Passband f = 0.2 Stopband f = 0.25 with attenuation 40dB Choose order N=40 > 37 magnitude 10 | H( f ) | 0 -10 -20 OK!!! dB -30 -40 -50 -60 -70 -80 0 0.1 0.2 0.3 digital frequency 0.4 0.5 f General FIR Filter of arbitrary Frequency Response w1 H0 H1 H w2 f [0, f1 , f 2 ,..., f M ] 2 H [ H 0 , H1 ,...,H M ] H3 0 Weights for Error: f1 f 2 f3 w( M 1) / 2 H M 1 H M f M 1 f M 12 w [w1, w2 ,...,w( M 1) / 2 ] Then apply: h firpm N , f / f M , H , w … and always check frequency response if it is what you expect! Example: H ( f ) 1/ sinc( f ) for H( f ) 0 0 f 0.2 0.25 f 0.5 A 40dB 0 0.2 0.25 0.5 f fp=0:0.01:0.2; % vector of passband frequencies fs=[0.25,0.5]; % stopband frequencies M=[1./sinc(fp), 0, 0]; % desired magnitudes Df=0.25-0.2; % transition region N=ceil(A/(22*Df)); % first guess of order h=firpm(N, [ fp, fs]/0.5,M); % impulse response magnitude 1.4 not very good here! 1.2 1 0.8 0.6 0.4 0.2 0 0 0.1 0.2 0.3 digital frequency 0.4 0.5 10 0 -10 dB -20 -30 N 37 -40 -50 -60 -70 -80 -90 0 0.1 0.2 0.3 0.4 0.5 To improve it: 1. Increase order 2. Add weights A 40dB 0 w 1 0.2 0.25 w 0.2 0.5 f w=[1*ones(1,length(fp)/2), 0.2*ones(1, length(fs)/2)]; h=firpm(N, [fp, fs]/0.5,M,w); magnitude 1.4 1.2 1 0.8 0.6 0.4 0.2 0 0 0.1 0.2 0.3 digital frequency 0.4 0.5 20 0 N 100 dB -20 -40 -60 -80 -100 -120 -140 -160 0 0.1 0.2 0.3 0.4 0.5