Sie sind auf Seite 1von 5

1

Digital Signal Processing

G V V Sharma∗

Contents 2.2 You will find a spectrogram at


https://academo.org/demos/spectrum-analyzer.
1 Software Installation 1 Upload the sound file that you downloaded
in Problem 2.1 in the spectrogram and play.
2 Digital Filter 1 Observe the spectrogram. What do you find?
Solution: There are a lot of yellow lines
3 Difference Equation 2 between 440 Hz to 5.1 KHz. These represent
the synthesizer key tones. Also, the key strokes
4 Z-transform 2 are audible along with background noise.
2.3 Write the python code for removal of out of
5 Impulse Response 3 band noise and execute the code.
Solution:
6 DFT and FFT 4
import soundfile as sf
7 Exercises 4 from scipy import signal

Abstract—This manual provides a simple introduction #read .wav file


to digital signal processing. input signal,fs = sf.read(’Sound Noise.wav’
)

1 Software Installation #sampling frequency of Input signal


Run the following commands sampl freq=fs

sudo apt−get update #order of the filter


sudo apt−get install libffi−dev libsndfile1 python3 order=4
−scipy python3−numpy python3−matplotlib
sudo pip install cffi pysoundfile #cutoff frquency 4kHz
cutoff freq=4000.0

2 Digital Filter #digital frequency


Wn=2∗cutoff freq/sampl freq
2.1 Download the sound file from
# b and a are numerator and denominator
wget https://raw.githubusercontent.com/
polynomials respectively
gadepall/
b, a = signal.butter(order,Wn, ’low’)
EE1310/master/filter/codes/Sound Noise.wav
#filter the input signal with butterworth filter
*The author is with the Department of Electrical Engineering, output signal = signal.filtfilt(b, a,
Indian Institute of Technology, Hyderabad 502285 India e-mail:
gadepall@iith.ac.in. All content in the manuscript is released under input signal)
GNU GPL. Free to use for anything. #output signal = signal.lfilter(b, a,
2

input signal) 4 Z-transform

#write the output signal into .wav file


4.1 The Z-transform of x(n) is defined as
sf.write(’Sound With ReducedNoise.wav’,

output signal, fs) X
X(z) = Z{x(n)} = x(n)z−n (4.1)
2.4 The output of the python script n=−∞

in Problem 2.3 is the audio file Show that


Sound With ReducedNoise.wav. Play
the file in the spectrogram in Problem 2.2. Z{x(n − 1)} = z−1 X(z) (4.2)
What do you observe? and find
Solution: The key strokes as well as Z{x(n − k)} (4.3)
background noise is subdued in the audio.
Also, the signal is blank for frequencies above Solution: From (4.1),
5.1 kHz. X∞
Z{x(n − k)} = x(n − 1)z−n (4.4)
n=−∞
3 Difference Equation X∞ ∞
X
= x(n)z−n−1 = z−1 x(n)z−n
3.1 Let ( )
n=−∞ n=−∞
x(n) = 1, 2, 3, 4, 2, 1 (3.1) (4.5)

resulting in (4.2). Similarly, it can be shown
Sketch x(n).
that
3.2 Let
Z{x(n − k)} = z−k X(z) (4.6)
1
y(n) + y(n − 1) = x(n) + x(n − 2), 4.2 Find
2 Y(z)
y(n) = 0, n < 0 (3.2) H(z) = (4.7)
X(z)
Sketch y(n). from (3.2) assuming that the Z-transform is a
Solution: The following code yields Fig. 3.2. linear operation.
wget https://github.com/gadepall/EE1310/raw/ Solution: Applying (4.6) in (3.2),
master/filter/codes/xnyn.py 1
Y(z) + z−1 Y(z) = X(z) + z−2 X(z) (4.8)
2
Y(z) 1 + z−2
=⇒ = (4.9)
X(z) 1 + 12 z−1
Digital Filter Input-Output
4
4.3 Find the Z transform of
3 
2 1 n = 0

x(n)


δ(n) =  (4.10)
1 0 otherwise

0
0 1 2 3 4 5 and show that the Z-transform of

4 1 n ≥ 0


3 u(n) =  (4.11)
0 otherwise

2
y(n)

1
is
0 1
U(z) = , |z| > 1 (4.12)
0.0 2.5 5.0 7.5 10.0 12.5 15.0 17.5 1 − z−1
n
Solution: It is easy to show that
Fig. 3.2 Z
δ(n) ⇋ 1 (4.13)
3

and from (4.11), response of the system defined by (3.2).


X ∞ Solution: From (4.9),
U(z) = z−n (4.14) 1 z−2
n=0 H(z) = + (5.2)
1 1 + 12 z−1 1 + 12 z−1
, |z| > 1
= (4.15) !n !n−2
1 − z−1 1 1
=⇒ h(n) = − u(n) + − u(n − 2)
using the fomula for the sum of an infinite 2 2
geometric progression. (5.3)
4.4 Show that using (4.16) and (4.6).
Z 1 5.2 Sketch h(n). Is it bounded? Convergent?
an u(n) ⇋ |z| > |a| (4.16)
1 − az−1 Solution: The following code plots Fig. 5.2.
4.5 Let wget https://raw.githubusercontent.com/
H (eω ) = H (z = eω ) . (4.17) gadepall/EE1310/master/filter/codes/hn.py
Plot |H (eω )|. Comment. H(eω ) is known as
the Discret Time Fourier Transform (DTFT) of
x(n). Filter Impulse Response
Solution: The following code plots Fig. 4.5. 1.25

wget https://raw.githubusercontent.com/ 1.00

gadepall/EE1310/master/filter/codes/dtft. 0.75
py 0.50
h(n)

0.25

0.00

Filter Frequency Response


−0.25
4.0
−0.50
3.5

3.0 0 2 4 6 8 10
n
2.5
Fig. 5.2: h(n) as the inverse of H(z)
|H(e ω)|

2.0

1.5
5.3 The system with h(n) is defined to be stable if
1.0
X∞
0.5 h(n) < ∞ (5.4)
0.0 n=−∞
−10.0 −7.5 −5.0 −2.5 0.0 2.5 5.0 7.5 10.0
ω Is the system defined by (3.2) stable for the
impulse response in (5.1)?
Fig. 4.5: |H (eω )| 5.4 Compute and sketch h(n) using
1
h(n) + h(n − 1) = δ(n) + δ(n − 2), (5.5)
2
5 Impulse Response This is the definition of h(n).
Solution: The following code plots Fig. 5.4.
5.1 Find an expression for h(n) using H(z), given Note that this is the same as Fig. 5.2.
that
Z wget https://raw.githubusercontent.com/
h(n) ⇋ H(z) (5.1)
gadepall/EE1310/master/filter/codes/hndef
and there is a one to one relationship between .py
h(n) and H(z). h(n) is known as the impulse
4

6 DFT and FFT


Impulse Response Definition
1.25 6.1 Compute
1.00 N−1
X

0.75 X(k) = x(n)e−2πkn/N , k = 0, 1, . . . , N − 1
n=0
0.50 (6.1)
h(n)

0.25 and H(k) using h(n).


0.00
6.2 Compute
Y(k) = X(k)H(k) (6.2)
−0.25

−0.50
6.3 Compute
N−1
0 2 4 6 8 10 1X
n y (n) = Y (k)·e2πkn/N , n = 0, 1, . . . , N−1
N k=0
Fig. 5.4: h(n) from the definition (6.3)

Solution: The following code plots Fig. 5.5.


5.5 Compute Note that this is the same as y(n) in Fig. 3.2.

X wget https://raw.githubusercontent.com/
y(n) = x(n) ∗ h(n) = x(k)h(n − k) (5.6) gadepall/EE1310/master/filter/codes/yndft.
n=−∞
py
Comment. The operation in (5.6) is known as
convolution.
Solution: The following code plots Fig. 5.5.
Note that this is the same as y(n) in Fig. 3.2. Filter Output using DFT

wget https://raw.githubusercontent.com/ 4
gadepall/EE1310/master/filter/codes/
ynconv.py 3

2
y(n)

Filter Output using Convolution


1
4
0
3
0 2 4 6 8 10 12
n
2
y(n)

Fig. 6.3: y(n) from the DFT


1
6.4 Repeat the previous exercise by computing
0 X(k), H(k) and y(n) through FFT and IFFT.
6.5 Wherever possible, express all the above equa-
0.0 2.5 5.0 7.5 10.0 12.5 15.0 17.5 20.0 tions as matrix equations.
n

Fig. 5.5: y(n) from the definition of convolution


7 Exercises
5.6 Show that Answer the following questions by looking at the

X python code in Problem 2.3.
y(n) = x(n − k)h(k) (5.7)
n=−∞
7.1 The command
5

output signal = signal.lfilter(b, a,


input signal)

in Problem 2.3 is executed through the follow-


ing difference equation
M
X N
X
a (m) y (n − m) = b (k) x (n − k) (7.1)
m=0 k=0

where the input signal is x(n) and the output


signal is y(n) with initial values all 0. Replace
signal.filtfilt with your own routine and verify.
7.2 Repeat all the exercises in the previous sections
for the above a and b.
7.3 What is the sampling frequency of the input
signal?
Solution: Sampling frequency(fs)=44.1kHZ.
7.4 What is type, order and cutoff-frequency of the
above butterworth filter
Solution: The given butterworth filter is low
pass with order=2 and cutoff-frequency=4kHz.
7.5 Modifying the code with different input param-
eters and to get the best possible output.

Das könnte Ihnen auch gefallen