200021344_EEE4702_exp01

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

NAME:M.

SADMAN ASTER

ID:200021344

SECTION:C

DEPARTMENT:EEE

SUBMISSION DATE : 11 October 2024

Course: EEE 4702 (Digital Signal Processing Lab)

Experiment no.: 01

Name of the experiment: The Study of basic concepts of digital


signals by simulation in MATLAB
A.Generation basic discrete signals

1. Unit Impulse Signal

clc;
clear all;
close all;
t = -3:1:3;
y = [zeros(1,3), ones(1,1), zeros(1,3)];
stem(t,y);
ylabel('Amplitude------>');
xlabel('(a)n ------>');
title ('Unit Impulse Signal');

2. Unit Step Sequence [u(n)-u(n-N)

n=input ('enter the N value ');


t=0: 1: n-1;
y=ones (1,n) ;
stem(t,y);
ylabel ('amplitude ---->'); 8

ans = 8

xlabel('(b)n ---->');
title (' unit step sequence ');
3. Ramp sequence

n=input('enter the length of ramp sequence ') ;


t=0:n-1 ;
stem(t,t) ;
ylabel('amplitude ---->') ;
xlabel('(c)n ---->') ;
title(' ramp sequence ') ;

n=input ('enter the length of exponential sequence');


t=0: n;
a=input ('enter the value of a ');
y=exp(a*t);
stem (t,y) ;
ylabel ('amplitude ---->') ;
xlabel ('(d)n ---->') ;
title (' exponential sequence ');
4. Exponential sequence
n=input ('enter the length of exponential sequence');
t=0: n;
a=input ('enter the value of a ');
y=exp(a*t);
stem (t,y) ;
ylabel ('amplitude ---->') ;
xlabel ('(d)n ---->') ;
title (' exponential sequence ')

5. Sine sequence

t=0:0.05:pi ;
y=sin(2*pi*t) ;
stem(t,y) ;
ylabel('amplitude ---->') ;
xlabel('(e)n ---->') ;
title(' sine sequence ') ;
6. Cosine sequence

t=0:0.05:pi ;
y=cos(2*pi*t) ;
stem(t,y) ;
ylabel('amplitude ---->') ;
xlabel('(f)n ---->') ;
title(' cosine sequence ') ;
B. Basic operations on discrete signals:

1. Scaling: This operation involves the multiplication of each sample in a sequence by a scalar
factor.

clc;
clear all;
close all;
x1=input('enter the scaling value value ')

x1 = 3

n=input('enter the N value ') ;


t=0:1:n-1 ;
x=ones(1,n) ;
y=x1*x;
subplot(2,2,1);
stem(t,x) ;
ylabel('amplitude ---->') ;
xlabel('(b)n ---->') ;
title(' unit step sequence ') ;
subplot(2,2,2);
stem(y);
title('scaled sequence');
Addition: This is a sample-by-sample addition given by and the length of x1(n) and x2(n) must be
the

same.

clear all;
close all;
x = input('ENTER THE FIRST SEQUENCE: ');
subplot(3,1,1);
stem(x);
title('X');
y = input('ENTER THE SECOND SEQUENCE: ');
subplot(3,1,2);
stem(y);
title('Y');
l1 = length(x);
l2 = length(y);
l3 = l1 - l2;
if l3 > 0
y = [y, zeros(1,l3)];
elseif l3 < 0
x = [x, zeros(1,abs(l3))];
end
z = x + y;
disp(z);

3 2 1 5 4

subplot(3,1,3);
stem(z);
title('Z=X+Y');
3.Subtraction:

clc;
clear all;
close all;

% Input for the first sequence


n11 = input('enter the lower boundary of the first sequence:');
n12 = input('enter the upper boundary of the first sequence:');
n1 = n11:n12;
x = input('ENTER THE FIRST SEQUENCE:');

% Input for the second sequence


n21 = input('enter the lower boundary of the second sequence:');
n22 = input('enter the upper boundary of the second sequence:');
n2 = n21:n22;
y = input('ENTER THE SECOND SEQUENCE:');

% Plotting the first sequence


subplot(3,1,1);
stem(n1, x);
xlabel('time');
ylabel('amplitude');
title('FIRST SEQUENCE');
axis([min(n1)-1 max(n1)+1 min(x)-1 max(x)+1]);

% Plotting the second sequence


subplot(3,1,2);
stem(n2, y);
xlabel('time');
ylabel('amplitude');
title('SECOND SEQUENCE');
axis([min(n2)-1 max(n2)+1 min(y)-1 max(y)+1]);

% Finding the range for the output signal


n3 = min(min(n1), min(n2)):max(max(n1), max(n2));

% Adjusting the sequences to match the output range


s1 = zeros(1, length(n3));
s2 = s1;

% Aligning sequence x with the new range


s1(ismember(n3, n1)) = x;

% Aligning sequence y with the new range


s2(ismember(n3, n2)) = y;

% Subtracting the sequences


sub = s1 - s2;

% Display the result


disp('subtracted sequence');

subtracted sequence

disp(sub);

1 -1 2 5 3 0

% Plotting the subtracted sequence


subplot(3,1,3);
stem(n3, sub);
xlabel('time');
ylabel('amplitude');
title('SUBTRACTED SEQUENCE');
axis([min(n3)-1 max(n3)+1 min(sub)-1 max(sub)+1]);
4.Multiplication: This is a sample-by-sample multiplication (or “dot” multiplication)

clc;
clear all;
close all;
n11=input('ENTER THE LOWER BOUNDARY OF THE FIRST SEQUENCE:');
n12=input('ENTER THE UPPER BOUNDARY OF THE FIRST SEQUENCE:');
n1=-n11:n12;
x=input('ENTER THE FIRST SEQUENCE:');
n21=input('ENTER THE LOWER BOUNDARY OF THE SECOND SEQUENCE:');
n22=input('ENTER THE UPPER BOUNDARY OF THE SECOND SEQUENCE:');
n2=n21:n22;
y=input('ENTER THE SECOND SEQUENCE:');
subplot(3,1,1);
stem(n1,x);
xlabel ('time')
ylabel ('amplitude')
title('FIRST SEQUENCE') ;
axis([-4 4 -5 5]);
subplot(3,1,2);
stem(n2,y);
xlabel ('time')
ylabel ('amplitude')
title('SECOND SEQUENCE');
axis([-4 4 -5 5]);
n3 =min (min(n1) ,min( n2 ) ) : max ( max ( n1 ) , max ( n2 ) );
% finding the duration of output signal (out)
s1 =zeros(1,length (n3) );
s2 =s1;
s1 (find ( ( n3>=min( n1 ) ) & ( n3 <=max ( n1 ) )==1 ) )=x;
% signal x with the duration of output signal 'mul'
s2 (find ( ( n3>=min ( n2 ) ) & ( n3 <=max ( n2 ))==1) )=y;
% signal y with the duration of output signal 'mul'
mul=s1 .* s2;
% multiplication
disp('MULTIPLIED SEQUENCE')
disp(mul)
subplot(3,1,3)
stem(n3,mul)
xlabel ('time')
ylabel ('amplitude')

5. Shifting

clc;
clear all;
close all;
n1=input('Enter the amount to be delayed');
n2=input('Enter the amount to be advanced');
n11=input('ENTER THE LOWER BOUNDARY OF THE FIRST SEQUENCE:');
n12=input('ENTER THE UPPER BOUNDARY OF THE FIRST SEQUENCE:');
n=n11:n12;
x=input('ENTER THE SEQUENCE');
subplot(3,1,1);
stem(n,x);
title('Signal x(n)');
m=n+n1;3
y=x;
subplot(3,1,2);
stem(m,y);
title('Delayed signal x(n-n1)');
t=n-n2;
z=x;
subplot(3,1,3);
stem(t,z);
title('Advanced signal x(n+n2)');

6. FOLDING or REVERSING:
clc;
clear all;
close all;
n11=input('ENTER THE LOWER BOUNDARY OF THE FIRST SEQUENCE:');
n12=input('ENTER THE UPPER BOUNDARY OF THE FIRST SEQUENCE:');
n=n11:n12;
x=input('ENTER THE SEQUENCE');
subplot(2,1,1)
stem(n,x);
axis([-3 3 -5 5]);
title('Signal x(n)');
c=fliplr(x);
y=fliplr(-n);
disp('FOLDED SEQUENCE')
disp(c)
subplot(2,1,2);
stem(y,c);
axis([-3 3 -5 5]);
title('Reversed Signal x(-n)') ;

7. Correlation

clc;
close all;
clear all;
% two input sequences
x=input('enter input sequence')
subplot(1,2,1);
stem(x);
xlabel('n');
ylabel('x(n)');
title('input sequence');
% auto correlation of input sequence
z=xcorr(x,x);
disp('The values of z are = ');
disp(z);
subplot(1,2,2);
stem(z);
xlabel('n');
ylabel('z(n)');
title('auto correlation of input sequence');

b. Cross Correlation

This correlation function is a measure of similarity between a signal & a different one.

% Program for computing cross-correlation of the sequences x5[1, 2, 3, 4] and


h5[4, 3, 2, 1]
clc;
clear all;
close all;
x=input('enter the 1st sequence');
h=input('enter the 2nd sequence');
y=crosscorr(x,h);
figure;
subplot(3,1,1);
stem(x);
ylabel('Amplitude --.');
xlabel(' (a) n --.');
title('input sequence');
subplot(3,1,2);
stem(h);
ylabel('Amplitude --.');
xlabel(' (b) n --.');
title('impulse sequence');
subplot(3,1,3);
stem(fliplr(y));
ylabel('Amplitude --.');
xlabel(' (c) n --.');
title('Cross correlated sequence');
disp('The resultant signal is');
fliplr(y)

8.Convolution:
clc;
clear all;
close all;
x1=input('Enter the first sequence x1(n) = ');
x2=input('Enter the second sequence x2(n) = ');
L=length(x1);
M=length(x2);
N=L+M-1;
yn=conv(x1,x2);
disp('The values of yn are= ');
disp(yn);
n1=0:L-1;
subplot(311);
stem(n1,x1);
grid on;
xlabel('n1--->');
ylabel('amplitude--->');
title('First sequence');
n2=0:M-1; subplot(312);
stem(n2,x2);
grid on;
xlabel('n2--->');
ylabel('amplitude--->');
title('Second sequence');
n3=0:N-1;
subplot(313);
stem(n3,yn);
grid on;
xlabel('n3--->');
ylabel('amplitude--->');
title('Convolved output');

circular convolution:
r all;
a = input('enter the sequence x(n) = ');
b = input('enter the sequence h(n) = ');
n1=length(a);
n2=length(b);
N=max(n1,n2);
x = [a zeros(1,(N-n1))];
for i = 1:N k = i; for j = 1:n2 H(i,j)=x(k)* b(j);
k = k-1; if (k == 0) k = N;
end
end
end
y=zeros(1,N);
M=H;
for j = 1:N
for i = 1:n2
y(j)=M(i,j)+y(j);
end
end
disp('The output sequence is y(n)= ');
disp(y);
stem(y);
title('Circular Convolution');
xlabel('n');
ylabel('y(n) ');
Assignment-01

1. Give a detailed and comprehensive difference between convolution and correlation nothing
carefully their domains of application
answer:
Convolution describes the output produced when a system receives an input. Each system has its
own transfer function, which defines how it reacts to a given input. When the input is applied, every
point in the input contributes a response based on the transfer function. Convolution accounts for all
input points through summation or integration, along with the transfer function, to estimate the
resulting output.

Correlation measures how alike two signals are. It compares the signals and indicates their
similarity. When normalized, correlation values range from [-1, 1], with 1 representing complete
similarity and -1 representing complete opposition. If the signals are identical except for a time shift,
it’s called autocorrelation. If other factors differ, it's referred to as cross-correlation.

2. Where are linear and circular convolution applied and why?

Answer:
Linear convolution is a mathematical method used to determine the output of a system that behaves
in a linear and time-invariant way, based on its input and response to a short-duration signal. In
linear convolution, the two sequences (input and response) may have different lengths, meaning
they might not have the same number of data points. As a result, the output can have more or fewer
data points than either of the input sequences. The output signal may or may not follow a repeating
pattern.

Circular convolution works similarly to linear convolution but deals with sequences that repeat in a
circular manner. It involves reversing, shifting, multiplying, and summing sequences, but since the
signals repeat, the shifting can be seen as rotating. In circular convolution, both sequences must
have the same number of data points. This results in an output that has the same number of points
as the input sequences.

3. Carefully distinguish between a continuous, discrete and


digital signal.

Answer:

A continuous signal is one that changes smoothly over time and can have any value within a certain
range at any given moment. These signals are defined for all points in time and are typically found in
analog systems, such as sound waves or temperature variations. Continuous signals are described
using continuous-time functions.
A discrete signal, however, is only defined at specific time intervals. Rather than being present at
every moment, it only has values at certain time points, and the values between these points are
ignored. An example of a discrete signal is the result of sampling a continuous signal at regular
intervals.

A digital signal is a type of discrete signal that can only take on a limited number of values, usually
represented by binary digits (0s and 1s). While discrete signals can have any numerical value at the
sampled points, digital signals are restricted to predefined levels and are commonly used in digital
electronics and computing.

Assignments 2:

Write short notes on the following topics:


1. Continuous time or discrete time signals
2. Periodic or aperiodic signals
3. Power or energy signals
4. Odd or even signals
5. Deterministic and non-deterministic signals
6. Real and imaginary signals
Answer:

1. Continuous Time or Discrete Time Signals


- Continuous-time signals These signals are defined at every point in time and can take any value
within a certain range. They are typically represented by analog signals, such as audio or
temperature variations.

- Discrete-time signals These signals are defined only at specific time intervals rather than
continuously. They often result from sampling continuous signals, like digital sound recordings.
2. Periodic or Aperiodic Signals
- Periodic signals These signals repeat themselves after a set time interval, called the period. For
example, a sine wave repeats its pattern regularly over time.

- Aperiodic signals These signals do not repeat and have no fixed time pattern. Examples include
signals like noise or single pulse waveforms.

3. Power or Energy Signals


- Power signals These signals have constant power over time but infinite energy. Typically, these
are periodic or continuous signals where power remains steady.

- Energy signals These signals have finite energy but zero average power, often occurring over a
short duration, like a pulse or a signal burst.
4. Odd or Even Signals
- Even signals A signal is even if it is symmetric around the vertical axis, meaning \( f(t) = f(-t) \). An
example is a cosine wave.

- Odd signals A signal is odd if it is antisymmetric, meaning \( f(t) = -f(-t) \). An example is a sine
wave.

5. Deterministic and Non-deterministic Signals


- Deterministic signals These signals are predictable and follow a specific pattern over time. They
can be expressed mathematically with accuracy.
- Non-deterministic (or random) signals These signals exhibit unpredictable behavior and cannot
be fully described mathematically. Noise is an example of such a signal.

6. Real and Imaginary Signals


- Real signals These signals consist only of real numbers and do not have any imaginary
components. Most signals encountered in the real world are real.

- Imaginary signals These signals contain only the imaginary part of a complex signal, which is
often seen in mathematical or frequency domain representations, such as in Fourier transforms.
Discussion:

In this experiment, we explored the fundamental concepts of digital signals and their simulation in
MATLAB. We generated and plotted several basic discrete signals, such as the unit impulse
sequence, unit step sequence, ramp sequence, exponential sequence, sinusoidal sequence, and
cosine sequence, and analyzed their characteristics.

Next, we implemented coding for essential operations on discrete signals, including scaling, addition,
subtraction, multiplication, shifting, folding, convolution, and correlation. We observed how each
operation influences the signal’s behavior and properties. Below are brief explanations of each
operation:

- Scaling: Multiplies each sample of the sequence by a constant factor.


- Addition: Combines two sequences by adding them sample by sample. The two sequences must
have the same length.
- Subtraction: Subtracts one sequence from another sample by sample. The sequences must be of
equal length.
- Multiplication: Performs sample-by-sample multiplication (or dot multiplication) of two sequences.
- Shifting: Shifts the entire sequence either to the left or right.
- Folding: Reverses the sequence, flipping it in the opposite direction.
- Autocorrelation: Measures the similarity between a signal and its time-delayed version.
- Cross-correlation: Measures the similarity between two different signals.
- Convolution: A mathematical operation used to describe the relationship between the input and
output of a linear time-invariant (LTI) system.

You might also like