Tuesday 26 December 2017

Discrete Time Systems in Time Domain and Convolution Using MATLAB

Introduction:
A discrete-time system processes an input signal in the time-domain to generate an output signal with more desirable properties by applying an algorithm composed of simple operations on the input signal and its delayed versions. The aim of this lab is to illustrate the simulation of some simple discrete-time systems on the computer using MATLAB and investigate their time domain properties.
R1 For a linear discrete-time system, if y1[n] and y2[n] are the responses to the input sequences x1[n] and x2[n], respectively, then for an input
x[n] = αx1[n] + β x2[n] (5.1)
the response is given by
y[n] = αy1[n] + β y2[n] (5.2)
The superposition property of Eq. (5.2) must hold for any arbitrary constants α and β and for all possible inputs x1[n] and x2[n]. If Eq. (5.2) does not hold for at least one set of nonzero values of α and β, or one set of nonzero input sequences x1[n] and x2[n], then the system is nonlinear.
R2 For a time-invariant discrete-time system, if y1[n] is the response to an input x1[n], then the response to an input
x[n] = x1[n − no]
is simply
y[n] = y1[n − no]
where no is any positive or negative integer. The above relation between the input and output must hold for any arbitrary input sequence and its corresponding output. If it does not hold for at least one input sequence and its corresponding output sequence, the system is time-varying.
R3 A linear time-invariant (LTI) discrete-time system satisfies both the linearity and the time-invariance properties.
R4 If y1[n] and y2[n] are the responses of a causal discrete-time system to the inputs
u1[n] and u2[n], respectively, then
u1[n] = u2[n] for n < N
implies also that
y1[n] = y2[n] for n < N
R5 A discrete-time system is said to be bounded-input, bounded-output (BIBO) stable if, for any bounded input sequence x[n], the corresponding output y[n] is also a bounded sequence, that is, if
|x[n]| < Bx for all values of n,
then the corresponding output y[n] is also bounded, that is,
|y[n]| < By for all values of n,
where Bx and By are finite constants.
R6 The response of a discrete-time system to a unit sample sequence {δ[n]} is called the unit sample response or, simply, the impulse response, and denoted as {h[n]}. Correspondingly, the response of a discrete-time system to a unit step sequence {μ[n]}, denoted as {s[n]}, is its unit step response or, simply the step response.
R7 The response y[n] of a linear, time-invariant discrete-time system characterized by an impulse response h[n] to an input signal x[n] is given by
𝒚[𝒏]=Σ𝒉[𝒌]𝒙[𝒏−𝒌],∞𝒌=−∞ (5.3)
which can be alternately written as
𝒚[𝒏]=Σ𝒉[𝒏−𝒌]𝒙[𝒌],∞𝒌=−∞ (5.4)
by a simple change of variables. The sum in Eqs. (5.3) and (5.4) is called the convolution sum of the sequences x[n] and h[n], and is represented compactly as:
y[n] = h[n]⊛ x[n], (5.5)
where the notation ⊛ denotes the convolution sum.
Code for Superposition Principle of LTI System
clc;
clear all;
close all;
%Properties of DT Systems(Linearity)
%y(n)=x(n);
x1=input('Enter first input sequence:');
x2=input('Enter second input sequence:');
a=input('Enter scaling constant(a):');
b=input('Enter scaling constant(b):');
subplot(2,2,1);
stem(x1);
xlabel('time');
ylabel('Amplitude');
title('First signal');
subplot(2,2,2);
stem(x2);
xlabel('time');
ylabel('Amplitude');
title('Second signal');
y1=x1;
y2=x2;
rhs=a*y1+b*y2;
x3=a*x1+b*x2;
lhs=x3;
if(lhs==rhs)
display('system is linear');
else
display('system is non-linear');
end;
subplot(2,2,3);
stem(lhs);
xlabel('time');
ylabel('Amplitude');
title('L.H.S');
subplot(2,2,4);
stem(rhs);
xlabel('time');
ylabel('Amplitude');
title('R.H.S');
Exercise 1: Write matlab code for system y[n] = (x[n]) ^2 + B and prove the superposition property with the help of above program.
Code for Time Invariance of LTI System
clc;
clear all;
close all;
%Properties of DT Systems(Time Invariance)
%y(n)=x(n);
x1=input('Enter input sequence x1:');
n0=input('Enter shift:');
x2=[zeros(1,n0),x1];
y1=x1;
y2=x2;
y3=[zeros(1,n0),y1];
if(y2==y3)
display('system is time invariant');
else
display('system is time variant');
end;
subplot(2,2,1);
stem(x1);
xlabel('time');
ylabel('Amplitude');
title('Input signal');
subplot(2,2,2);
stem(x2);
xlabel('time');
ylabel('Amplitude');
title('Signal after shift');
subplot(2,2,3);
stem(y2);
xlabel('time');
ylabel('Amplitude');
title('L.H.S');
subplot(2,2,4);
stem(y3);
xlabel('time');
ylabel('Amplitude');
title('R.H.S');
Exercise 2:
Write matlab code for system y[n] = n*(x[n]) and show if the system is time invariant to time variant with the help of above program.
Moving Average Filter
R10 An LTI discrete-time system is causal if and only if its impulse response sequence{h[n]} satisfies the condition
h[k] = 0 for k < 0 (5.9)
R11 The class of LTI discrete-time systems with which we shall be mostly concerned is characterized by a linear constant-coefficient difference equation of the form
Σ𝒅𝒌𝒚[𝒏−𝒌]Σ𝒑𝒌𝒙[𝒏−𝒌]𝑴𝒌=𝟎𝑵𝒌=
𝟎,
(
5.10)
where x[n] and y[n] are, respectively, the input and the output of the system, and {dk} and {pk} are constants. The order of the discrete-time system is max(N,M), which is the order of the difference equation characterizing the system. If we assume the system to be causal, then we can rewrite Eq. (5.10) to express y[n] explicitly as a function of x[n]:
𝒚[𝒏]=−Σ𝒅𝒌𝒅𝟎𝒚[𝒏−𝒌]Σ𝒑𝒌𝒅𝟎𝒙[𝒏−𝒌]𝑴𝒌=𝟎𝑵𝒌=
𝟏,
(
5.11)
provided 𝑑0≠0. The output y[n] can be computed using Eq. (5.11) for all n ≥ no knowing
x[n] and the initial conditions y[no − 1], y[no − 2], . . . , y[no − N].
A discrete-time system is called a finite impulse response (FIR) system if its impulse response h[n] is of finite length. Otherwise, it is an infinite impulse response (IIR) system. The causal system of Eq. (5.11) represents an FIR system if 𝑑𝑘 = 0 for k > 0. Otherwise, it is an IIR system. M point Moving Average filter is an FIR system to smooth the data. Try the following code and observe the output, it’s a 4-point average Filter
load count.dat
x = count(:,1);
a = 1; % Coefficient of y
b = [1/4 1/4 1/4 1/4]; % Coefficient of x
y = filter(b,a,x);
t = 1:length(x);
plot(t,x,'--',t,y,'-')
legend('Original Data','Filtered Data')
Difference equation for 3 point moving average filter is
𝒚[𝒏] =
𝟏
𝟑
(𝒙[𝒏] + 𝒙[𝒏 − 𝟏] + 𝒙[𝒏 − 𝟐])
General form of equation is 𝒚[𝒏] =
𝟏
𝑴
Σ𝑴−𝟏 𝒙[𝒏 − 𝒌]
𝒌=𝟎 (5.13)
Exercise 3: Write a program for M point moving average filter and run it over sum of two
sinusoids (s1,s2,x[n]=s1+s2) of frequency f1=0.05 and f2=0.47 for 0 < n < 100. Display all 4
signals using subplot.Run the filter for M=3.
Exercise 4: What will be the effect for M=2 and which component of x[n] is suppressed.
Exercise 5: If the LTI system is changed from y[n] = 0.5(x[n] + x[n - 1]) to
y[n] = 0.5(x[n] - x[n - 1]), what would be its effect on the input x[n] = s1[n] + s2[n]?
Exercise 6: investigate the linearity property of a causal system (as in Exercise 1) of the type described
by Eq. (5.10). Consider the system given by
y[n]−0.4 y[n−1]+0.75 y[n−2] = 2.2403 x[n]+2.4908 x[n−1]+2.2403 x[n−2]
to generate three different input sequences x1[n], x2[n], and x[n] = a · x1[n]+b · x2[n], and to compute
and plot the corresponding output sequences y1[n], y2[n], and y[n] where x1 and x2 are cosines with
f1=0.1 and f2=0.4 for n=0:40 ,a=2,b= -3
Exercise 6: Investigate the time-invariance property for the system of Exercise 5 using same
parameters and delay =10.
Linear Convolution
The response y[n] of a LTI system for any arbitrary input x[n] is given by convolution of impulse
response h[n] of the system and the arbitrary input x[n].
y[n] = x[n]*h[n]
h[k]x[n k]
If the input x[n] has N1 samples and impulse response h[n] has N2 samples then the output sequence
y[n] will be a finite duration sequence consisting of (N1 + N2 - 1) samples. The convolution results
in a non-periodic sequence called Aperiodic convolution.

STEPS IN LINEAR CONVOLUTION:
The process of computing convolution between x[k] and h[k] involves four steps.
1. Folding: Fold h[k] about k=0 to obtain h[-k]
2. Shifting: Shift h[-k] by ‘n0’to right if ‘n0’ is positive and shift h[-k] by ‘n0’ to the left if
‘n0’ is negative. Obtain h[n0-k]
3. Multiplication: Multiply x[k] by h[n0-k] to obtain the product sequence
yn0 [k] = x[k] h [n0 –k]
4. Summation: Find the sum of all the values of the product sequence to obtain values of
output at n = n0
Repeat steps 2 to 4 for all possible time shifts ‘n0’ in the range - <n< 
clc;
clear all;
close all;
%Program to perform Linear Convolution
x1=input('Enter the first sequence to be convoluted:');
subplot(3,1,1);
stem(x1);
xlabel('Time');
ylabel('Amplitude');
title('First sequence');
x2=input('Enter the second sequence to be convoluted:');
subplot(3,1,2);
stem(x2);
xlabel('Time');
ylabel('Amplitude');
title('Second sequence');
f=conv(x1,x2);
disp('The Linear convoluted sequence is');
disp(f);
subplot(3,1,3);
stem(f);
xlabel('Time');
ylabel('Amplitude');
title('Linear Convoluted sequence');
Exercise 7: Write a program to perform convolution of input sequences without using the built-in Conv function. Implement the convolution equation.

Summary: This lab gives a tutorial about generating different continuous and discrete time signals in MATLAB.

1 comments:

ekeeda001 said...

Congratulation for the great post. Those who come to read your Information will find lots of helpful and informative tips.
get more: Discrete Time Systems and Signal Processing

Post a Comment