MATLAB Program For Basic Arithmetic Operations On Signals

  A signal is a physical quantity that varies with time, space or any other independent variable by which information can be conveyed. A discrete-time signal is often identified as a sequence of numbers, denoted by x[n], where n is an integer. Signals are broadly classified into continuous and discrete signals. A continuous signal will be denoted by x(t), in which the variable t can represent any physical quantity. A discrete signal will be denoted by x[n], in which the variable n is integer value. The variables t and n are assumed to represent time.

Operations on Signals:

a. Signal addition 

It is implemented in MATLAB by the arithmetic operator “+”. However, the lengths of x1(n) and x2(n) must be the same.

y(n) = x1(n) + x2(n)

b. Signal multiplication

It is implemented in MATLAB by the array operator “*”. To multiply sequences of different lengths we can use the following function

y(n) = x1(n) * x2(n)

Program:
clc;
close all;
clear all

%Generate the first sequence
L1=input('Enter input for lower value=');
H1=input('Enter input for higher value=');
n1=L1:H1
disp('Display the no. of samples value to be enter ')
L1=length(n1)
x=input('Enter a first sequence=')
subplot(2,2,1);
stem(n1,x);
title('X');
axis tight;
grid on;

%Generate the Second sequence
L2=input('Enter input for lower value=');
H2=input('Enter input for higher value=');
n2=L2:H2
disp('Display the no. of samples value to be enter=');
L2=length(n2)
y=input('Enter a second sequence=');
subplot(2,2,2);
stem(n2,y);
title('Y');
axis tight;
grid on;

%Finding the duration of output signal
n3=min(min(n1),min(n2)):max(max(n1),max(n2));
s1=zeros(1,length(n3));
s2=s1;
s1((n3>=min(n1))&(n3<=max(n1))==1)=x;
s2((n3>=min(n1))&(n3<=max(n1))==1)=y;

%Adding operation
display('Addition of two sequence is= ');
add=s1+s2
subplot(2,2,3)
stem(n3,add)
title('Z=X+Y');
axis tight;
grid on;

%Subtracting operation
display('subtraction of two sequence is= ');
sub=s1-s2
subplot(2,2,4)
stem(n3,sub)
title('Z=X-Y');
axis tight;
grid on;

Popular Posts