first three experiments

Download as pdf or txt
Download as pdf or txt
You are on page 1of 14

1.

Generation of Elementary & composite signals

AIM: To write MATLAB program for the following and execute the same:
a) Generation of Elementary signals
b) Generation of single tone and composite signal

1a) Generation of Elementary signals:

There are several elementary or basic signals, which are used to model a large number of
physical signals that occur in nature. These elementary signals are also called Standard Signals.
Some of these signals are described below

i) Unit Impulse Function:


An ideal impulse function, δ(n) is a function that is zero everywhere but at the origin, where it
is infinitely high.

ii) Unit Step Function:


The unit step function, U (n) is defined as

iii) Unit Ramp Function:


A ramp function or ramp signal is a type of standard signal which starts at t = 0 and increases
linearly with time. The unit ramp function has unit slope.

iv) Exponential Signal:


An exponential signal or exponential function is a function that literally represents an
exponentially increasing or decreasing series. A discrete-time real exponential sequence is
defined as

 When a < 1, the exponential sequence x(n) grows exponentially.


 When 0 < a < 1, the exponential signal x(n) decays exponentially.
 When a < 0, the exponential sequence x(n) takes alternating signs.
MATLAB Code:

i) Generation of unit Impulse signal


clc; close all; clear all;
n=-2:1:2;
y=[zeros(1,2),ones(1,1),zeros(1,2)]
figure(1)
stem(n,y);
xlabel('n ----->'); ylabel('δ(n)');
title('unit impulse');
ii) Generation of unit step signal
clc; close all; clear all;
n=input('enter the n value');
n1=0:1:n-1;
y=ones(1,n);
figure(2)
plot(n1,y);
title('unit step');
xlabel('n ----->'); ylabel('u(n)');
iii) Generation of Ramp signal
clc; close all; clear all;
n=input('enter the n value');
n1=0:n;
y=n1;
figure(3)
stem(y,n1);
title('ramp');
xlabel('n ----->'); ylabel('r(n)');

iv) Generation of Exponential signal


clc; clear; close all
alpha = -.9;
n = -10 : 0.5 : 10;
y = power(alpha, n);
stem(n,y);
title ('Exponential signal ');
xlabel('n ----->'); ylabel('r(n)');
1a) Results and Conclusions
1b) Generation of single tone and Composite signal:

i) Single tone:

A single tone is a steady signal typically in the frequency range of sound for indicating a
condition, communication protocol state, or serve as an audible warning. It may be composed
of single frequency component. For example, to generate a series of five tones (1000 Hz, 1
sec.) with an interval of 2 seconds between the onset of each tone.

Generation of Single tone signal

Fs = 8192; % Default Sampling Frequency (Hz)


Ts = 1/Fs; % Sampling Interval (s)
T = 0:Ts:(Fs*Ts); % One Second
Frq = 1000; % Tone Frequency
Y = sin(2*pi*Frq*T); % Tone
Y0 = zeros(1, Fs*2); % Silent Interval
Ys = [repmat([Y Y0], 1, 4) Y];
disp(Ys)
figure;
stem(Ys);
xlabel('n ----->'); ylabel('Ys');

ii) Composite signal

A composite signal can be periodic or non-periodic. A periodic composite signal can be


decomposed into a series of simple waves with discrete frequencies, frequencies that have
integer values (1, 2, 3, and so on). A non-periodic composite signal can be decomposed into a
combination of an infinite number of simple waves with continuous frequencies, frequencies
that have real values.

MATLAB Program:

% Number of samples
num_samples = 100;

% Time vector
t = linspace(0, 1, num_samples);
% Ramp signal
slope = 2; % Adjust the slope as needed
ramp_signal = slope * t;

% Step signal
step_start = 0.4;
step_amplitude = 1; % Adjust the amplitude as needed
step_signal = step_amplitude * (t >= step_start);

% Composite signal (sum of ramp and step)


composite_signal = ramp_signal + step_signal;

% Plotting individual signals and composite signal


figure;

subplot(3, 1, 1);
stem(t, ramp_signal);
title('Ramp Signal');

subplot(3, 1, 2);
stem(t, step_signal);
title('Step Signal');

subplot(3, 1, 3);
stem(t, composite_signal);
title('Composite Signal (Ramp + Step)');
xlabel('Time');
ylabel('Amplitude');

% Display the plot


title('Composite Signal Example (Ramp + Step)');

Results:
Exercise: Generate a composite signal using mathematical expression

x[n]=Asine⋅sin(2πfsinen)+Asquare⋅sign(sin(2πfsquaren))+Anoise⋅randn(1,length(n))

with Asine=2,fsine=0.1,Asquare=2,fsquare=0.1,Anoise=0.2.

1b) Results and Conclusions:


Evaluation Table:

Design/Write-up Conduction Results & Viva Total


(10 Marks) (15 Marks) Conclusions (05 Marks) (40 Marks)
(10 Marks)

2. Linear convolution & System identification using deconvolution

AIM: To write MATLAB program for the following cases and execute the same:
a) Linear convolution of two finite length Non-Causal sequences
b) System identification using deconvolution

Linear convolution defines the relationship between input and output of linear time invariant
systems in time domain. Since any arbitrary input can be expressed as weighted sum of unit
sample sequences, the response to any arbitrary input signal x(n) can be expressed in terms of
the unit sample response of the system, h(n). Correspondingly the output sequence of the LTI
system is y(n).
+∞

𝑂𝑢𝑡𝑝𝑢𝑡, 𝑦(𝑛) = 𝑥(𝑛) ∗ ℎ(𝑛) = ∑ 𝑥 (𝑘). ℎ(𝑛 − 𝑘)


𝑘= −∞

If we have two sequences h(n) of length M and x(n) of length L, then the length of the linearly
convolved sequence y(n)=x(n)*h(n) will be L + M - 1. By using convolution sum, the output
of a system can be found with the knowledge of the input x(n) and the impulse response h(n).

2a) Linear Convolution of two finite length Non-causal sequences


clc; close all; clear all;
x = input('Enter the sequence x(n): \n');
h = input('Enter the sequence h(n): \n');
xr = input('input the range of x: \n');
hr = input('input the range of h: \n');
Zri = xr(1) + hr(1)
Zre = xr(length(x))+ hr(length(h))
yr = [Zri:Zre];
y = conv(x,h);
disp(y)
disp(yr)
figure;
% to plot the input sequences
subplot(3,1,1), stem(xr,x);
xlabel('n ----->'); ylabel('x(n)');
title('Input Sequence');
subplot(3,1,2), stem(hr,h);
xlabel('n ----->'); ylabel('h(n)');
title('Impulse response');
% to plot the convolved sequences
subplot (3,1,3), stem(yr,y);
xlabel('n ----->'); ylabel('y(n)');
title('Linear convolved Sequence');

Example:
Enter the sequence x(n): [1 3 3 1]
Enter the sequence h(n): [2 3 3 2]
input the range of x: -1:2
input the range of h: -2:1
Zri = -3
Zre = 3
y = [2 9 18 22 18 9 2]
n = -3 -2 -1 0 1 2 3

Results and Conclusions:

Exercise: Consider two non-causal sequences x1[n] and x2 [n] defined as follows and find the
linear convolution.
x1[n]={1,2,3}, n=0,1,2 and x2[n]={0,−1,1}, n=0,1,2.

2a) Results and Conclusions:


2b) System Identification using Deconvolution
The impulse response is the output of the system due to an impulse input applied at time n=0.
The output of an LTI (linear time invariant) system given by a weighted superposition of time
shifted impulse responses. Thus given the impulse response of a system, output of the system
computed for a given input. Similarly, for a given output and input, the impulse response of a
system can be calculated, using deconvolution.

MATLAB program:
clc; close all; clear all
x = input('Enter the input sequence x(n):');
y = input('Enter the output sequence y(n):');
h = deconv(y,x);
disp('The impulse response is :'); disp(h);
%Plot the input sequence
n = 0:length(x) - 1;
subplot(2,2,1), stem(n,x);
title('Input Sequence');
xlabel('n---->'); ylabel('x(n)---->');
%Plot the output sequence
n = 0:length(y) - 1;
subplot(2,2,2), stem(n,y);
title('Output Sequence');
xlabel('n---->'); ylabel('y(n)---->');
%Plot the impulse response
n = 0:length(h) - 1;
subplot(2,1,2); stem(n,h);
title('Impulse Response');
xlabel('n---->'); ylabel('h(n)---->');

Example-1:
Enter the input sequence x(n): [2 4 6]
Enter the output sequence y(n): [2 8 14 12]
The impulse response is: [1 2]

Find z-transforms X(z) and Y(z). Find H(z) using H(z) = Y(z) / X(z).
By inverse z-transform, Impulse response h(n) = [1 2 ].

Exercise: Given the input signal x[n]={1,2,3,4}and the output signal y[n]={2,1,0,1}, perform
system identification to estimate the impulse response h[n] using deconvolution.

2b) Results and Conclusions:


Evaluation Table:

Design/ Conduction Results & Viva Total


Write-up (15 Marks) Conclusions (05 Marks) (40 Marks)
(10 Marks) (10 Marks)

3. Circular Convolution and Impulse Response


AIM: To write MATLAB program for the following cases and execute the same.
a) Circular convolution of two finite length sequences using time domain
approach.
b) To find impulse response of LTI system from transfer function and obtain the
pole-zero plot.
3a) Circular Convolution of two finite length sequences
Consider two finite sequences x1(n) and x2(n) of length N, then circular convolution is defined
as
N 1
x3(n) = 
m= 0
x1(m) x2((n-m))N for n = 0,1,2,3………..N-1

x3(n) = x1(n) * x2(n)

Matlab Program:
clc; close all; clear all;
x=input('enter the first sequence');
h=input('enter the second sequence');
N=max(length(x), length(h));
x1=[x,zeros(1,N-length(x))];
h1=[h,zeros(1,N-length(h))];
n=0;
for m=1:N
sum=0;
for k=1:N
if((m-k)>=0)
n=m-k+1;
else
n=m-k+N+1;
end
sum=sum+(x1(k)*h1(n));
end
%disp(sum);
y(m) = sum;
end
disp(y)

EXAMPLE :
Enter the first sequence: [1 3 3 1]
Enter the second sequence: [2 3 3 2]
y(n) = [20 18 20 22]

Exercise : Consider two sequences x1[n] and x2[n] with lengths N1 and N2 respectively. Perform
linear convolution using circular convolution in the time domain for the given sequences:
X1[n] = {1, 2, 3}, N1=3 and X2[n] = {0, −1, 1}, N2=3

3a) Results and Conclusions:


3b) To find impulse response of LTI system from transfer function and obtain the pole-
zero plot

For a discrete-time LTI system, the impulse response h[n] is the output of the system when an
impulse function (Dirac delta function) is used as the input. Mathematically, the convolution
sum for the impulse response is given by:

h[n] =∑∞
𝑘=−∞ 𝑥 [𝑘 ] 𝛿[𝑛 − 𝑘]

Here, x[n] is the input sequence, and δ[n] is the discrete-time impulse function. The impulse
response h[n] essentially describes how the system responds to a single sample at time n=0.

Pole-Zero Plot of a Discrete-Time LTI System:

The transfer function of a discrete-time LTI system is often represented as a ratio of


polynomials in the variable z (which corresponds to the Z-transform domain). The transfer
function is given by:

𝐵(𝑍)
H (z) =
𝐴(𝑍)

Here, B (z) and A (z) are the numerator and denominator polynomials, respectively. The pole-
zero plot is a graphical representation of the location of poles and zeros of the transfer function
in the complex plane. Poles are points where the transfer function becomes infinite, and zeros
are points where the transfer function becomes zero. The Zeros are represented by 'o' marks
and Poles are represented by 'x' marks. The pole-zero plot provides valuable insights into the
stability and frequency response characteristics of the system. Specifically, the system is stable
if all poles lie inside the unit circle in the z-plane.

MATLAB Program:
% To find the impulse response of a system defined by the Transfer Function.
clc; close all; clear all;
b = input('Enter the coefficients of X:');
a = input('Enter the coefficients of Y:');
N = input('Enter the length of the impulse response N:');
% To calculate the impulse response
Xi = [1, zeros(1,N-1)]; % Define an Impulse sequence.
h = filter(b, a, Xi); % compute impulse response.
disp( 'The impulse response is:'); disp(h);
% To calculate poles and zeros of H(z)
Z = roots(b); %Zeroes are roots of the numerator polynomial
P = roots(a); % Poles are roots of the denominator polynomial
disp('The Zeros of H(z) are'); disp(Z);
disp('The Poles of H(z) are'); disp(P);
% To get Pole-zero plot
figure;
zplane(b,a); title('pole zero plot');

Example: y[n] = 0.5x[n] +x [n-1] - 2 y [n-1] - 3y [n-2]


Enter the coefficients of X: [0.5 1]
Enter the coefficients of Y: [1 2 3]
Enter the length of the impulse response N: 5
The impulse response is
[0.5000 0 -1.5000 3.0000 -1.5000]

The Zeros of H (z) are -2


The Poles of H (z) are -1.0000 + 1.4142i and -1.0000 - 1.4142i

Exercise: Consider a discrete-time LTI system described by the following input-output


relationship y[n] =2x[n] −3x [n−1] +x [n−2] where y[n] is the output and x[n] is the input. Find
the impulse response of the system, which is excited with the delta function δ[n] as the input.

3b) Results and Conclusions:

You might also like