first three experiments
first three experiments
first three experiments
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
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) 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.
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);
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');
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.
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).
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
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.
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.
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
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.
𝐵(𝑍)
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');