You are on page 1of 32

PSG COLLEGE OF TECHNOLOGY

DEPARTMENT OF INSTRUMENTATION AND CONTROL SYSTEMS


ENGINEERING

15U510 INTERFACING AND SIGNAL PROCESSING LABORATORY

Name : Srimithra K
Roll No : 18U254
Year / Semester : III / 5 Sem
th

Experiment No : 3
Experiment Name : Analysis of Discrete time systems
Date : 03-10-2020
3. ANALYSIS OF DISCRETE TIME SYSTEMS

AIM

The objective of this experiment is to analyze discrete-time (DT) systems. In these


experiments, the impact of poles and zeros are analyzed for the first and second order
systems.

System 1: First order system with zero at z=1, and pole at the origin

For a DT system with „M‟ zeros and „N‟ poles, the expression for the transfer function
is given by
(1 − 𝑧 𝑧 )(1 − 𝑧 𝑧 ) … (1 − 𝑧 𝑧 )
𝐻(𝑧) = … … … (1)
(1 − 𝑝 𝑧 )(1 − 𝑝 𝑧 ) … (1 − 𝑝 𝑧 )

In the above expression, z1, z2 etc., represent the location of zeros, p1, p2, etc., represent the
location of poles.

For the system 1, the zero is at z=1, this implies z1 =1, the pole is at the origin, hence
p1=0. Substituting these in equation (1) we get

(1 − 1 × 𝑧 )
𝐻(𝑧) = … … … (2)
1
The above equation can be simplified as

H (z) 1 z1 ………(3)

Upon taking Inverse Z-transform, the expression for impulse response of the system is given
by

h[n]   [n]   [n 1] …….(4)

The zero at z=1, will block the low frequency component and it will allow the high
frequency component to pass through it. The system will behave like a high pass filter.

For this system, two inputs namely DC and AC signal are given. The MATLAB code
which implements this system and gives response to the DC and AC signal are shown in figure
1 and the corresponding output is shown in figure 2. The system impulse response, pole-zero
plot, magnitude and phase response are shown in figure 3.
%System 1: High pass filter
clc
clear all
close all
%Step 1: Generation of DC and AC signal
n=-10:10;
x1=ones(1,length(n)); %DC signal
x2=(-1).^n; %AC signal
%Step2: System description
num=[1,-1];
den=[1];
% Step 3: Response of the system to the two inputs
y1=filter(num,den,x1);
y2=filter(num,den,x2);
%Step 4: Plotting the input and output
subplot(2,2,1),stem(n,x1,'filled'),title('DC signal'),
subplot(2,2,2),stem(n,x2,'filled'),title('AC signal'),
subplot(2,2,3),stem(n,y1,'filled'),title('System
response to DC signal'),
subplot(2,2,4),stem(n,y2,'filled'),title('System
response AC signal'),
figure
%System behaviour
[H,w]=freqz(num,den);
subplot(2,2,1),impz(num,den),
subplot(2,2,2),zplane(num,den),title('Pole-zero plot')
subplot(2,2,3),plot(w,abs(H)),title('Magnitude
response')
subplot(2,2,4),plot(w,angle(H)),title('Phase response')

Figure 1 MATLAB program to implement high pass filter

The built-in functions used in the program are given in table 1.


Table 1 List of built-in functions used in the program
S.I.No Built-in function Use
1 filter Obtain the response of the system
2 freqz Frequency response of the system
3 abs Magnitude response of the system
4 angle Phase response of the system
5 impz Impulse response of the system
6 zplane Obtain the pole-zero plot of the system
Figure 2 Input-Output of the system
Imaginary Part
Amplitude

Figure 3 System characteristics


Inferences

1. From figure 2, it is possible to observe that the system blocks DC signal and allows
AC signal to pass through it. The system behaves like a high pass filter.
2. The magnitude response shown in figure 3 shows that the system behaves like a high
pass filter.
3. From figure 3, it is possible to observe that the impulse response is h[n]={1,-1}.
4. From figure 3, it is possible to observe that the system has a zero at z=1 and the pole
at the origin. Since the pole occurs at the origin, the given DT system is stable.

System 2: First order system with zero at z=-1, and pole at the origin

For the system 2, the zero is at z=-1, this implies z1 =-1, the pole is at the origin,
hence p1=0. Substituting these in equation (1) we get

1 − (−1) × 𝑧
𝐻(𝑧) = … … … (5)
1
 
The above equation can be simplified as

H (z)  1 z 1 ………(6)

Upon taking Inverse Z-transform, the expression for impulse response of the system is given
by

h[n]   [n]   [n 1] …….(7)

The zero at z=-1, will block the high frequency component and it will allow the low
frequency component to pass through it. The system will behave like a low pass filter.

For this system, two inputs namely DC and AC signal are given. The MATLAB code
which implements this system and gives response to the DC and AC signal are shown in figure
4 and the corresponding output is shown in figure 5. The system impulse response, pole-zero
plot, magnitude and phase response are shown in figure 6.
%System2:Low pass filter
clc
clear all
close all
%Step 1: Generation of DC and AC signal
n=-10:10;
x1=ones(1,length(n)); %DC signal
x2=(-1).^n; %AC signal
%Step2: System description
num=[1,1];
den=[1];
% Step 3: Response of the system to the two inputs
y1=filter(num,den,x1);
y2=filter(num,den,x2);
%Step 4: Plotting the input and output
subplot(2,2,1),stem(n,x1,'filled'),title('DC
signal'),
subplot(2,2,2),stem(n,x2,'filled'),title('AC
signal'),
subplot(2,2,3),stem(n,y1,'filled'),title('System
response to DC signal'),
subplot(2,2,4),stem(n,y2,'filled'),title('System
response AC signal'), figure
%System behaviour
[H,w]=freqz(num,den);
subplot(2,2,1),impz(num,den),
subplot(2,2,2),zplane(num,den),title('Pole-zero
plot')
subplot(2,2,3),plot(w,abs(H)),title('Magnitude
response')
subplot(2,2,4),plot(w,angle(H)),title('Phase
response')

Figure 4 MATLAB program to implement low pass filter


Figure 5 Input-Output of a low pass filter
Imaginary Part
Amplitude

Figure 6 Low pass filter characteristics


Inferences

1. From figure 5, it is possible to observe that the system blocks AC signal and allows
DC signal to pass through it. The system behaves like a low pass filter.
2. The magnitude response shown in figure 6 shows that the system behaves like a low
pass filter.
3. From figure 6, it is possible to observe that the impulse response is h[n]={1,1}.
4. From figure 6, it is possible to observe that the system has a zero at z=-1 and the pole
at the origin. Since the pole occurs at the origin, the given DT system is stable.

System 3: Second order system with zero at z=1 and at z=-1, and pole at the origin

The zero at z=1 will block DC component, whereas the zero at z=-1 will block AC
component of the signal. Thus the system behaves like a bandpass filter. The transfer function
of the system with z=1 and at z=-1 is given by

H (z)  (1 z1)(1 z  1 ) ....... (8)

Simplifying the above expression we get

𝐻(𝑧) = 1 − 𝑧 … … … (9)

Upon taking Inverse Z-transform, the impulse response is obtained as

h[n]   [n]   [n  2] ............ (10)

The MATLAB code which implements the bandpass filter is shown in figure 7, the input and
the output of the bandpass filter is shown in figure 8 and the characteristics of the bandpass
filter is shown in figure 9.
%System 3: Bandpassfilter
clc
clear all
close all
%Step 1: Generation of DC and AC signal
n=-10:10;
x1=ones(1,length(n)); %DC signal
x2=(-1).^n; %AC signal
%Step2: System description
num=[1,0,-1];
den=[1];
% Step 3: Response of the system to the two inputs
y1=filter(num,den,x1);
y2=filter(num,den,x2);
%Step 4: Plotting the input and output
subplot(2,2,1),stem(n,x1,'filled'),title('DC signal'),
subplot(2,2,2),stem(n,x2,'filled'),title('AC signal'),
subplot(2,2,3),stem(n,y1,'filled'),title('System response to
DC signal'),
subplot(2,2,4),stem(n,y2,'filled'),title('System response AC
signal'), figure
%System behaviour
[H,w]=freqz(num,den);
subplot(2,2,1),impz(num,den),
subplot(2,2,2),zplane(num,den),title('Pole-zero plot')
subplot(2,2,3),plot(w,abs(H)),title('Magnitude response')
subplot(2,2,4),plot(w,angle(H)),title('Phase response')

Figure 7 MATLAB code to realize bandpass filter


Figure 8 Input and output to bandpass filter
Imaginary Part
Amplitude

Figure 9 Characteristics of bandpass filter


Inferences

1. From figure 8, it is possible to observe that the system blocks both DC and AC signal.
The system behaves like a band pass filter.
2. The magnitude response shown in figure 9 shows that the system behaves like a band
pass filter.
3. From figure 9, it is possible to observe that the impulse response is h[n]={1,0,-1}.
4. From figure 9, it is possible to observe that the system has a zero at z=-1 and z=1, the
pole at the origin. Since the pole occurs at the origin, the given DT system is stable.

System 4: Second order system with complex conjugate zeros occurring at z1 e j and
z2 e j , and pole at the origin (Notch filter)

The transfer function of the system with two complex conjugate zeros occurring at z1= ejω and
z2=e-jω
𝐻(𝑧) = (1 − 𝑧 𝑧 )(1 − 𝑧 𝑧 ) … … . . (11)

Substituting z1 e j and z2  e j in equation (11) we get

H (z)  (1 e j z1) (1 e j z 1 ) …….(12)

Simplifying the above expression we get

H (z) 1 e j z1  e j z1  z2 …….(13)

The above equation can be expressed as

H (z)  1 z1(e j  e j )  z2 ………(14)

The above equation can be simplified as

H (z) 1 2cos()z1  z2 ........ (15)

This system has the ability to reject one specific frequency. The system behaves like a
NOTCH filter.

In this MATLAB example, three sinusoidal notes corresponding to 500 Hz, 1000 Hz
and 1500 Hz are generated. These three notes are passed through the notch filter. The notch
frequency is selected as 1000 Hz. In the output, it is possible to hear that the note corresponding
to 1000 Hz being nulled. The MATLAB code which performs this task is shown in figure 10.
%Notch filter
clc
close all
%Step 1: Three sinusoidal notes
fs=8000;
t=0:1/fs:1;
f1=500;
f2=1000;
f3=1500;
x1=sin(2*pi*f1*t);
x2=sin(2*pi*f2*t);
x3=sin(2*pi*f3*t);
x=[x1,x2,x3];
%Step 2: Notch filter specfication
fn=f2;
w=2*pi*(fn/fs);
num=[1,-2*cos(w),1];
den=1;
%Step 3: Output of the filter
y=filter(num,den,x);
%Step 4: Hearing the sound
soundsc(x),pause,soundsc(y),
%Step 5: STFT of input and output signal
spectrogram(x,[],[],512,fs),title('Spectrogram of input
signal'),figure,
spectrogram(y,[],[],512,fs),title('Spectrogram of output signal')
figure,
[H,w]=freqz(num,den,512,8000);
subplot(2,2,1),impz(num,den),
subplot(2,2,2),zplane(num,den),title('Pole-zero plot')
subplot(2,2,3),plot(w,10*log10(abs(H))),xlabel('frequency'),ylabel('
Magnitude in (dB)')
title('Magnitude response')
subplot(2,2,4),plot(w,angle(H)),title('Phase response')

Figure 10 MATLAB code for notch filter


(a) STFT of input signal (b) STFT of filtered signal
Figure 11 STFT of input and output signal
By comparing figure 11(a) and (b) it is possible to observe that signal frequency 1000 Hz
being removed by the notch filter. The impulse response, pole-zero plot, magnitude and phase
response of the filter are shown in figure 12. Imaginary Part
Amplitude
Magnitude in (dB)

Figure 12 Characteristics of notch filter


Inferences
From figure 12, the following inferences can be made
(i) The impulse response of the filter is finite.
(ii) The notch filter can be considered as a system with two complex conjugate
zeros.
(iii) In this example, 1000 Hz being notched. The magnitude response of the filter
shows that the filter can remove 1000 Hz interference.
(iv) The phase response of the filter shows that the filter exhibits linear phase
characteristics in the pass band.

System 5: System with one pole at z=1 (Accumulator)

Consider a system which has a pole at z=1, the pole has the tendency to enhance the
signal. The transfer function of the system with the pole at z=1 is represented as

1
H (z)  ……..(16)
1 p1z1

Substituting p1=1 in the above equation we get

1
H (z)  ……..(17)
1 (1)z 1
The above equation can be simplified as

1
H (z)  ………(18)
1 z1

Upon taking Inverse Z-transform, the impulse response is obtained as

h[n]  Z 1{H (z)} ........ (19)

Substituting equation (18) in equation (19) we get

1
ℎ(𝑛) = 𝑍 … … . . (20)
1−𝑧

The expression for the impulse response is obtained as

h[n]  u[n] ............ (21)

The MATLAB code which implements the accumulator is shown in figure 13. The
input and the output of the accumulator are shown in figure 14. The impulse response,
magnitude response, phase response and the pole-zero plot of the accumulator is shown in
figure 15.
%Accumulator
clc
clear all
close all
%Step 1: Generation of DC and AC signal
n=-10:10;
x1=ones(1,length(n)); %DC signal
x2=(-1).^n; %AC signal
%Step2: System description
num=[1];
den=[1,-1];
% Step 3: Response of the system to the two inputs
y1=filter(num,den,x1);
y2=filter(num,den,x2);
%Step 4: Plotting the input and output
subplot(2,2,1),stem(n,x1,'filled'),title('DC signal'),
subplot(2,2,2),stem(n,x2,'filled'),title('AC signal'),
subplot(2,2,3),stem(n,y1,'filled'),title('System
response to DC signal'),
subplot(2,2,4),stem(n,y2,'filled'),title('System
response AC signal'), figure
%System behaviour
[H,w]=freqz(num,den);
subplot(2,2,1),impz(num,den),
subplot(2,2,2),zplane(num,den),title('Pole-zero plot')
subplot(2,2,3),plot(w,abs(H)),title('Magnitude
response')
subplot(2,2,4),plot(w,angle(H)),title('Phase response')

Figure 13 MATLAB code to implement accumulator

DC signal AC signal
1 1

0.5

0.5 0

-0.5

0 -1
-10 -5 0 5 10 -10 -5 0 5 10

System response to DC signal System response AC signal


1
20

15

10 0.5

0 0
-10 -5 0 5 10 -10 -5 0 5 10

Figure 14 Input and Output of the accumulator


Impulse Response Pole-zero plot
1
1

Imaginary Part
0.5
Amplitude

0.5 0

-0.5

-1
0
0 2 4 6 8 -1 -0.5 0 0.5 1
n (samples) Real Part
Magnitude response Phase response
200 0

150
-0.5

100
-1
50

-1.5
0
0 1 2 3 0 1 2 3

Figure 15 Characteristics of accumulator

Inferences

(i) From figure 14, for DC input, the output is unbounded. This shows that bounded
input results in a unbounded output, hence the system is NOT a stable system.
(ii) From figure 15, the impulse response of the accumulator is a unit step sequence.
Unit step sequence is not absolutely summable. Since the impulse response is not
absolutely summable, the system is an unstable system.
(iii) By observing the pole-zero plot in figure 15, it is possible to observe that the pole
lies on the unit circle. Since the pole lies on the unit circle, it is not a stable system.
For a DT system to be stable, the pole should lie within the unit circle.

System 6: System with one pole at z=-1

Consider a system which has a pole at z=-1, the pole has the tendency to enhance the
signal. The transfer function of the system with the pole at z=-1 is represented as

1
H (z)  ……..(22)
1 p1z1

Substituting p1=-1 in the above equation we get


1
H (z)  ……..(23)
1 (1)z 1
The above equation can be simplified as
1
H (z) 
1 z 1

The impulse response is obtained by taking the Inverse Z-transform of the transfer function
which is given by
 1 
h[n]  Z 1 …….(25)
  1
1 z 

h[n]  (1)nu[n]………(26)

The MATLAB code which implements this system is shown in figure 16. The input
and output of the system is shown in figure 17. From figure 17, it is possible to observe that
bounded AC signal results in an unbounded output signal, hence the system is NOT a stable
system. From figure 18, it is possible to observe that the system has one pole at z=-1, hence
the system is NOT a stable system. From the impulse response, it is possible to observe that
the impulse response of the system is not absolutely summable, hence it is NOT a stable
system.

clc
clear all
close all
%Step 1: Generation of DC and AC signal
n=-10:10;
x1=ones(1,length(n)); %DC signal
x2=(-1).^n; %AC signal
%Step2: System description
num=[1];
den=[1,1];
% Step 3: Response of the system to the two inputs
y1=filter(num,den,x1);
y2=filter(num,den,x2);
%Step 4: Plotting the input and output
subplot(2,2,1),stem(n,x1,'filled'),title('DC
signal'),
subplot(2,2,2),stem(n,x2,'filled'),title('AC
signal'),
subplot(2,2,3),stem(n,y1,'filled'),title('System
response to DC signal'),
subplot(2,2,4),stem(n,y2,'filled'),title('System
response AC signal'),
figure
%System behaviour
[H,w]=freqz(num,den);
subplot(2,2,1),impz(num,den),
subplot(2,2,2),zplane(num,den),title('Pole-zero
plot')
subplot(2,2,3),plot(w,abs(H)),title('Magnitude
response')
subplot(2,2,4),plot(w,angle(H)),title('Phase
response')

Figure 16 MATLAB code which implement the system


DC signal AC signal
1 1

0.5

0.5 0

-0.5

0 -1
-10 -5 0 5 10 -10 -5 0 5 10

System response to DC signal System response AC signal


1 20

10

0.5 0

-10

0 -20
-10 -5 0 5 10 -10 -5 0 5 10

Figure 17 Input and output of the system

Impulse Response Pole-zero plot


1
1
Imaginary Part

0.5 0.5
Amplitude

0 0

-0.5 -0.5

-1
-1
0 2 4 6 8 -1 -0.5 0 0.5 1
n (samples) Real Part
Magnitude response Phase response
200
1.5

150
1
100

0.5
50

0 0
0 1 2 3 0 1 2 3

Figure 18 Characteristics of the system


System 7: Second order system having poles at z=1 and z=-1

The transfer function of a system having poles at z=1 and at z=-1 is given by

1 1
H (z)   1
……….(27)
1
1 p1z 1 p2 z

Substituting p1=1 and p2=-1 in the above expression we get

1 1
H (z)   ………(28)
1 (1)z 1 (1)z 1
1

The above equation can be simplified as


1 1.............
H (z)   (29)
1 z 1 1 z 1

The above equation can be simplified as

1
H (z)  ………..(30)
1 z2

The impulse response of the system is obtained by taking Inverse Z-transform of the transfer
function. Upon taking Inverse Z-transform of expression (29) we get
 1 1 
h[n]  Z 1 ………(31)
 1
  
1
1 z 1 z 

The above equation can be written as

𝐴 𝐴
ℎ(𝑛) = 𝑍 + … … … (32)
1−𝑧 1+𝑧

Solving A1=A2=0.5, the above expression can be written as

1 1
ℎ(𝑛) = 𝑍 2 + 2 … … … (33)
1−𝑧 1+𝑧

Upon taking Inverse Z-transform, the above equation can be written as


1 1
h[n]  u[n]  (1)nu[n]…….(34)
2 2
The above equation can be simplified as

1
ℎ(𝑛) = [1 + (−1) ]𝑢[𝑛] … … … (35)
2
The above equation can be written as

1, 𝑛 ≥ 0𝑛𝑒𝑣𝑒𝑛
ℎ(𝑛) = ……(37)
0, 𝑜𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒

The MATLAB code which implements the system is shown in figure 19.

clc
clear all
close all
%Step 1: Generation of DC and AC signal
n=-10:10;
x1=ones(1,length(n)); %DC signal
x2=(-1).^n; %AC signal
%Step2: System description
num=[1];
den=[1,0,-1];
% Step 3: Response of the system to the two inputs
y1=filter(num,den,x1);
y2=filter(num,den,x2);
%Step 4: Plotting the input and output
subplot(2,2,1),stem(n,x1,'filled'),title('DC
signal'),
subplot(2,2,2),stem(n,x2,'filled'),title('AC
signal'),
subplot(2,2,3),stem(n,y1,'filled'),title('System
response to DC signal'),
subplot(2,2,4),stem(n,y2,'filled'),title('System
response AC signal'),
figure
%System behaviour
[H,w]=freqz(num,den);
subplot(2,2,1),impz(num,den),
subplot(2,2,2),zplane(num,den),title('Pole-zero
plot')
subplot(2,2,3),plot(w,abs(H)),title('Magnitude
response')
subplot(2,2,4),plot(w,angle(H)),title('Phase
response')

Figure 19 MATLAB code to implement the system

Figure 20 shows the input and output of the system. From the figure, it is possible to observe
that both DC and AC signals are amplified. In other words, bounded input results in
unbounded output. In figure 21, from the pole-zero plot, it is possible to observe that two
poles occur at z=1 and at z=-1. The system is not a stable system. The impulse response is in
agreement with the theoretical result given in equation (37).
Figure 20 Input and output of the system
Imaginary Part
Amplitude

Figure 21 Characteristics of the system


System 8: System with complex conjugate poles
System with conjugate poles will behave like a digital resonator. Complex conjugate
poles refers to one pole occurring at p1  e j and p2 e j . The transfer function of the
system is given by

1 1
H (z)  1
 1
………(38)
1 p1z 1 p2 z

Substituting p1  e j and p2  e j in the above equation we get

1 1
𝐻(𝑧) = × … … . (39)
1−𝑒 𝑧 1−𝑒 𝑧

The above equation can be simplified as

1
H (z)  ……..(40)
1 2 cos()z1  z2

The MATLAB code which implements the digital resonator is shown in figure 22. The
input and output of the system is shown in figure 23 and the characteristics of the resonator
are given in figure 24.

%Digital resonator
clc
clear all
close all
%Step 1: Resonator
fs=100;
n=0:99;
fn=10;
w=2*pi*(fn/fs);
num=1;
den=[1,-2*cos(w),1];
%Step 2: Input to the system
x=[1,zeros(1,99)];
%Step 3: Output of the system
y=filter(num,den,x);
%Step 4: Plotting the input and output
subplot(2,1,1),stem(n,x,'filled'),title('Input to the system')
subplot(2,1,2),stem(n,y,'filled'),hold on,
plot(n,y),title('Output of the system') %Step 5:
Characteristics of the system
[H,w]=freqz(num,den);
figure,
subplot(2,2,1),impz(num,den),
subplot(2,2,2),zplane(num,den),title('Pole-zero plot')
subplot(2,2,3),plot(w,10*log10(abs(H))),xlabel('frequency'),
ylabel('Magnitude in (dB)'),title('Magnitude response')
subplot(2,2,4),plot(w,angle(H)),title('Phase response')

Figure 22 MATLAB code for digital resonator


Figure 23 Input and output of digital resonator
Imaginary Part
Amplitude
Magnitude in (dB)

Figure 24 Characteristics of digital resonator


Inferences

1. From figure 23, it is possible to observe that the input to the resonator is impulse
signal and the output of the resonator is a sinusoidal signal.
2. From figure 24, it is possible to observe the following facts
 By observing the impulse response, the impulse response is a sinusoidal signal.
 By observing the pole-zero plot, the digital resonator has two conjugate poles on
the unit circle.
 By observing the magnitude response, it is possible to infer that digital resonator
act as a narrow band pass filter.
 By observing the phase response, it is possible to infer that digital resonator
exhibits linear phase characteristics.

Tasks

(1) Read an ECG signal which is corrupted by 50/60 Hz power line interference. Use notch
filter to filter out the power line interference. Plot the noisy ECG and the filtered ECG
signal.

%Step 1: Reading the ECG signal


load('a01m.mat');
fs=100; % sampling frequency
t=linspace(0,1,1000);
%Step 2: Design of notch filter
fn=50;
w=2*pi*(fn/fs);
num=[1,-2*cos(w),1];
den=1;
%Step 5: Filtering of corrupted speech signal
y=filter(num,den,val);
%Step 6: plot the signal
subplot(2,1,1),plot(t,val),title('ECG signal')
subplot(2,1,2),plot(t,y),title('Output signal')

Figure 25 Matlab code for filtering ECG signal


Figure 26 noisy and filtered ECG signal

Inference:
From the figure 26, it can be observed that the ECG signal is corrupted by powerline
interference of 50Hz and then it is filtered from corrupted ECG signal by using the
function “filter()” and it can be observed that QRS complex lies within -500 to 1000
in amplitude in filtered ECG signal whereas in noisy ECG signal it lies within -200 to
400.
(2) Add sinusoidal interference of specific frequency (namely 1000 Hz) to your voice
signal. Now pass this corrupted voice signal to the notch filter to remove the sinusoidal
interference. Use the spectrogram command to plot the STFT of the corrupted and
filtered speech signal.

clc
clear all
close all
%Step 1: Reading the audio signal
[x,fs]=audioread('mithra.wav');
%Step 2: Adding sinusoidal interference
t=linspace(0,1,8000);
n=sin(2*pi*1000*t);
%Step 3: Adding sinusoidal interference to the voice
x1=x+n';
%Step 4: Design of notch filter
fn=1000;
w=2*pi*(fn/fs);
num=[1,-2*cos(w),1];
den=[1];
%Step 5: Filtering of corrupted speech signal
y=filter(num,den,x1);
%Step 6: Hearing the original, corrupted and filtered speech
soundsc(x,fs),pause,soundsc(x1,fs),pause,soundsc(y,fs)
%Step 7: Plotting the spectrogram
spectrogram(x,[],[],512,fs),title('Spectrogram of Input
voice'),figure,
spectrogram(x1,[],[],512,fs),title('Spectrogram of corrupted
voice'),figure,
spectrogram(y,[],[],512,fs),title('Spectrogram of filtered
voice')
%Step 8: Filter characteristics
[H,w]=freqz(num,den,512,fs);
figure,
subplot(2,2,1),impz(num,den),
subplot(2,2,2),zplane(num,den),title('Pole-Zero plot')
subplot(2,2,3),plot(w,10*log10(abs(H))),title('Magnitude
response')
subplot(2,2,4),plot(w,angle(H)),title('Phase response')

Figure 27 Matlab code for notch filter

Figure 28 STFT of input signal


Figure 29 STFT of corrupted signal

Figure 30 STFT of filtered signal


Imaginary Part
Amplitude

Figure 31 Characteristics of notch filter


Inference:
By comparing figure 28 and 30 it is possible to observe that signal frequency 1000 Hz
being removed by the notch filter.
From figure 31, the following inferences can be made
(i) The impulse response of the filter is finite.
(ii) The notch filter can be considered as a system with two complex conjugate
zeros.
(iii) In this task, 1000 Hz being notched. The magnitude response of the filter
shows that the filter can remove 1000 Hz interference.
(iv) The phase response of the filter shows that the filter exhibits linear phase
characteristics in the pass band.

(3) Design a digital resonator to generate 1500 Hz sinusoidal signal. This interference is
to be added to your favourite music signal. Now use notch filter to remove this
sinusoidal interference. Try to play your favourite music with sinusoidal interference
and the filtered music signal.

%Digital resonator
%Step 1: Resonator
fs=48000;
n=0:341615;
fn=1500;
w=2*pi*(fn/fs);
num=1;
den=[1,-2*cos(w),1];
%Step 2: Input to the system
x=[1,zeros(1,341615)];
%Step 3: Output of the system
y2=filter(num,den,x);
[x1,fs]=audioread('violin.mp3');
%Step 4: Adding sinusoidal interference to the voice
y1=x1+y2';
%Step 5: Design of notch filter
fn=1500;
w=2*pi*(fn/fs);
num=[1,-2*cos(w),1];
den=1;
%Step 6: Filtering of corrupted speech signal
y=filter(num,den,y1);
%Step 7: Hearing the original, corrupted and filtered speech
soundsc(x,fs),pause
soundsc(y1,fs),pause
soundsc(y,fs),
%Step 8: Filter characteristics
[H,w]=freqz(num,den,512,fs);
subplot(2,2,1),impz(num,den),
subplot(2,2,2),zplane(num,den),title('Pole-Zero plot'),
subplot(2,2,3),plot(w,10*log10(abs(H))),title('Magnitude
response'),
subplot(2,2,4),plot(w,angle(H)),title('Phase response')

Figure 32 Matlab code for digital resonator and notch filter


Imaginary Part
Amplitude

Figure 33 Characteristics of digital resonator and notch filter

Inference:
From figure 33, it is possible to observe the following facts
 The impulse response of the filter is finite
 By observing the pole-zero plot, the notch filter can be considered as a system
with two complex conjugate poles.
 By observing the magnitude response, it is possible to infer that 1500Hz is
notched. The magnitude response of the filter shows that the filter can remove
1500 Hz interference.
 By observing the phase response, it is possible to infer that notch filter
exhibits linear phase characteristics.

(4) Write a MATLAB code to generate “sinusoidal two dimensional grating” pattern. Try
to display the two dimensional sinusoidal grating pattern as the image. There should
be option to change the horizontal and vertical frequency. X-ray image with two
dimensional sinusoidal grating pattern is shown as illustration in figure 25

(a)X-ray image (b) X-ray image with sinusoidal interference


Figure 34 Two dimensional sinusoidal grating pattern
clear all
close all
%Reading the image
t=imread('kitty2.jpg');
h=rgb2gray(t);
h=imresize(h,[256 256],'nearest');
%Generating sinusoidal interference
[x,y]=meshgrid(1:256,1:256);
f1=1;
f2=1;
sinusoidalnoise=100*sin(2*pi/14*f1*x+2*pi/14*f2*y);
subplot(3,1,1),colormap(gray),
imagesc(sinusoidalnoise),title('Sinusoidal grating')
axis off;
%Image with sinusoidal interference
myinterferenceimg1=double(h)+sinusoidalnoise;
subplot(3,1,2),imshow(h),title('original image')
subplot(3,1,3),imshow(myinterferenceimg1,[]),
title('Image with sinusoidal interference')
Figure 35 Matlab code for sinusoidal 2D grating

Figure 36 Two-dimensional sinusoidal grating pattern of the image


Inference:

From figure 36, we can see that the normal 2D image is compared with the same image along
with 2D sinusoidal interference. Firstly, 2D sinusoidal interference is created and it is applied to
an image. Grating size can be varied by varying the amplitude of the sine waves and we can also
vary f1 and f2.
Pre-lab questions

(1) Define the term “pole” and “zero” of a system

ANS:
Poles and Zeros of a transfer function are the frequencies for which the value of the
denominator and numerator of transfer function becomes zero respectively. The values of
the poles and the zeros of a system determine whether the system is stable, and how well
the system performs.
(2) Define the term “order” of a discrete-time system
ANS:
The order of the discrete time system is defined by the number of independent energy
storage elements in the system, and intuitively by the highest order of the linear
differential equation that describes the system. In a transfer function, the order is the
highest exponent in the transfer function.
(3) Mention different ways to represent a discrete-time system
ANS:
(i) Graphical form
(ii) Functional form
(iii) Tabular form
(iv) Sequential form
(4) Mention two applications of digital resonator
ANS:
Digital resonators are useful in many applications, including simple bandpass filtering and
speech generations.
(5) Write the transfer function, impulse response and difference equation of a notch filter
ANS:
(i) The transfer function of notch filter is
𝐻 (𝑠 + 𝜔 )
𝐻(𝑠) = 𝜔
𝑠 + 𝑄 𝑠+𝜔
Where, ω0 = pole frequency
ωz = zero frequency
H0 =circuit gain
Q = selectivity of the filter
(ii) Difference equation of notch filter is
1
𝐻=
𝜔
1+ 𝜔
(6) What is a comb filter? How is it different from notch filter?
ANS:
A comb filter is a filter implemented by adding a delayed version of a signal to itself, causing
constructive and destructive interference. The frequency response of a comb filter consists of
a series of regularly spaced notches, giving the appearance of a comb.
A notch filter is a filter that contains one or more deep notches or ideally perfect nulls in its
frequency response characteristic. comb filters are similar to notch filters in which the nulls
occur periodically across the frequency band similar with periodically spaced teeth.
(7) What is the “x” and “y‟ axis in Short-Time Fourier Transform (STFT)?
ANS:
The X axis of STFT is Frequency(Hz) and the Y axis of STFT is Time(s).
(8) What is the significance of “linear phase”?
ANS:
In general, phase linearity is a parameter that is defined for the passband of a filter. If the
phase shift of a filter is linear with respect to frequency, then every frequency component of
the signal will be delayed by an equal amount. The result is an output signal that is delayed,
but not distorted. Group delay is defined as the negative slope of the phase with respect to
frequency. If the group delay is constant, tis implies phase linearity.
(9) What is the difference between “filter” and “conv” command in MATLAB?
ANS:

 Conv is to do convolution, that is, according to the practice of the book, first Flip, in
a step-by-step translation, to obtain results. For a sequence of two lengths of n,m,
the convolution result length is m+n-1

 Filter is to do the filter, in fact, the principle and convolution is figured out, but the
method of processing the results are different

(10) From the impulse response, how to interpret the causality and the stability of the
discrete-time system?

ANS:

(i) A LTI discrete time system is stable if and only if impulse response is absolutely
summable(h[n]-finite)

(ii) A LTI discrete time system is causal if and only if it has a causal impulse response
(h[n]=0 for all n>0)

RESULT:

Thus, the various discrete time systems were studied and analysed.

You might also like