Operations on signals and sequences 

Aim: To perform arithmetic operations different types of signals Using MATLAB Software.

Equipments:

PC with windows OS.

MATLAB Software

Basic Operation on Signals:

Time Shifting:

% program for time shifting of a Unit impulse signal 

n1=input('enter the value of n1<0')
n2=input('enter the value of n2>0')
n=input('enter the value of n lying between n1 and n2 and not equal to zero')
t=[n1:n2];
x=zeros(1,length(t));
y=x;
i=find(t==0);
x(i)=1;
i=find(t==n);
y(i)=1;
subplot(2,1,1)
plot(t,x)
title("", "time", "amplitude")
title('Unit Impulse function')  
subplot(2,1,2)
plot(t,y)
xlabel(‘time’)
ylabel(‘amplitude’)
if n>0  
title('Delayed Unit Impulse by  3 units')
else
title('Advanced Unit Impulse by 3 units ')    
end

Output:

 

 

% program for time shifting of a Unit step signal

fs=input('enter the sampling frequency')
T=1/fs;
t=-1*T:T/fs:T;
x=zeros(1,length(t));
x1=x;
x2=x;
i=find(t==0);
x(i:length(x))=1;
k=input('enter the amount of  positive shift required in between -T and +T')
i=find(t==k);
x1(i:length(x))=1;
j=input('enter the amount of  negative shift required in between -T and +T')
i=find(t==j);
x2(i:length(x))=1;
subplot(3,1,1)
plot(t,x)
xlabel(‘time’)
ylabel(‘amplitude’)
title('Unit Step signal with fs=1000')  
subplot(3,1,2)
plot(t,x1)
xlabel(‘time’)
ylabel(‘amplitude’)
title('Unit Step sgnal delayed by 0.0005sec')
subplot(3,1,3)
plot(t,x2)
xlabel(‘time’)
ylabel(‘amplitude’)
title('Unit Step sgnal advanced  by 0.0005sec')

Output:

 

% program for time shifting of a sinusoidal signal

Progarm-1:

f=input('enter the sampling frequency')
T=1/f
t=0:T/f:T;
x=sin(2*pi*f*t);
b= input('select a value for b which is greater than one')
t1=-1*b*T:T/f:b*T;
p=zeros(1,length(t1));
q=p;
i=find(t1==0);
p(i:i+length(t)-1)=x;
k=input('enter the amount of shift required which is  bounded by -b.T and +b.T')
j=find(t1==k)
q(j:j+length(t)-1)=x;
if k<0
subplot(2,1,1)
plot(t1,p)
xlabel(‘time’)
ylabel(‘amplitude’)
title('sinusoidal pulse with f=500,b=2')  
subplot(2,1,2)
plot(t1,q)
xlabel(‘time’)
ylabel(‘amplitude’)
title('sinusoidal pulse advanced by 0.002sec')
else
subplot(2,1,1)
plot (t1,p)
xlabel(‘time’)
ylabel(‘amplitude’)
title('sinusoidal pulse with f=500,b=2')  
subplot(2,1,2)
plot(t1,q)
xlabel(‘time’)
ylabel(‘amplitude’)
title('sinusoidal pulse delayed by 0.002sec')
end

 Output:

% program for time shifting of a sinusoidal signal

Program-2:

clc
clear all
close all
t = [0:.01:pi];        % independent (time) variable 
A = 8; % amplitude 
f1 = 2; 
s1 = A*sin(2*pi*f1*t); 
subplot(3,1,1)
plot(t,s1)
xlabel('t');
ylabel('amplitude');
title('input signal')
subplot(3,1,2)
plot(t+10,s1)
xlabel('t');
ylabel('amplitude');
title('right shifted signal')
subplot(3,1,3)
plot(t-10,s1)
xlabel('t');
ylabel('amplitude');
title('left shifted signal')
Time shifting of a signal

% program for time shifting of a sequence

clc
clear all
close all
n=0:1:4;
h=[1,1,1,-1,2];
subplot(3,1,1)
stem(n,h);
xlabel('n'); ylabel('h(n)'); title('impulse sequence');
subplot(3,1,2)
stem(n+2,h);
xlabel('n')&nbsp;; ylabel('h(n)'); title('folded sequence');
subplot(3,1,3)
stem(n-2,h) 
xlabel('n')&nbsp;; ylabel('h(n)'); title('shifted sequence');
subplot(3,1,3)
Time shifting of a sequence

Signal Addition and Substraction :

Addition: any two signals can be added to form a third signal,

z (t) = x (t) + y (t) 

signal addition

Multiplication :Multiplication of two signals can be obtained by multiplying their values at every instants . z (t) = x (t) *y (t)

Multiplication of two signals 

%Program for addition and multiplication of continuous sinusoidal signals 

t = [0:.01:1]; % independent (time) variable 
A = 8; % amplitude 
f1 = 2; 
s1 = A*sin(2*pi*f1*t); % create a 2 Hz sine wave
f2 = 6; 
s2 = A*sin(2*pi*f2*t); % create a 4 Hz sine wave
figure 
subplot(4,1,1) 
plot(t, s1) 
title('1 Hz sine wave') 
ylabel('Amplitude') 
subplot(4,1,2) ;plot(t, s2) 
title('2 Hz sine wave') 
ylabel('Amplitude') 

%plot the summed sine waves in the bottom panel 

subplot(4,1,3) ;plot(t, s1+s2) 
title('Summed sine waves') 
ylabel('Amplitude') 
xlabel('Time (s)') 

%plot the multiplied sine waves

xmult=s1.*s2;
subplot(4,1,4);plot(xmult);
title('multiplication');
ylabel('Amplitude') 
xlabel('Time (s)')

%Program for addition and multiplication of two discrete sinusoidal sequences with different time durations

f1=10;
f2=10;
T1=1/f1
t1=0:T1/f1:T1
x1=sin(2*pi*f1*t1)
T2=2/f2;
t2=0:T2/f2:T2
x2=sin(2*pi*f2*t2)                                      
t=sort([t1,t2])
 
for i=2:length(t)
if t(i)==t(i-1)
t(i)=pi
end
end
j=find(t==pi)
t(j)=[]
p1=zeros(1,length(t))
for i1=1:length(t)
for j1=1:length(t1)
if t(i1)==t1(j1)
p1(i1)=x1(j1)
end
end
end
subplot(3,2,1)
stem(t1,x1)
xlabel('time')
ylabel('amplitude')
title('x1')
subplot(3,2,2)
stem(t,p1)
xlabel('time')
ylabel('amplitude')
title('p1')
p2=zeros(1,length(t))
for i2=1:length(t)
for j2=1:length(t2)
if t(i2)==t2(j2)
p2(i2)=x2(j2)
end
end
end
subplot(3,2,3)
stem(t2,x2)
xlabel('time')
ylabel('amplitude')
title('x2')
subplot(3,2,4)
stem(t,p2)
xlabel('time')
ylabel('amplitude')
title('p2')
p=p1+p2
q=p1.*p2
subplot(3,2,5)
stem(t,p)
xlabel('time')
ylabel('amplitude')
title('p1+p2')
subplot(3,2,6)
stem(t,q)
xlabel('time')
ylabel('amplitude')
title('p1.*p2')

Output:

%Program for addition and multiplication & addition of sequences 

n1=1:1:9 
s1 = [1 2 3 4 5 6 2 3 1]; 
subplot(4,1,1)          % plot sequence 1
stem(n, s1)
xlabel('n1')
title('input sequence') 
ylabel('Amplitude') 
n2=-2:1:6;
s2=[1 1 1 0 2 3 1 1 0 ]
subplot(4,1,2) ;stem(n2, s2)         % plot sequence 2
title('second sequence') ;
ylabel('Amplitude') 
xlabel('n2')
s3=s1+s2;
subplot(4,1,3) ;stem(n2,s3)           % plot summed sequence
title('Summed sequence') 
ylabel('Amplitude') 
xlabel('n2') 
s4=s1.*s2;
subplot(4,1,4);stem(n2,s4);        % plot multiplied sequence
title('multiplication');
ylabel('Amplitude') 
xlabel('n2')

Time reversal

Time reversal of a signal x(t) can be obtained by folding the signal about t=0. Y(t)=y(-t).

% Folding for signal or time reversal Unit Step Signal 

t=-5:0.01:5
x=zeros(1,length(t));
i=find(t>=0);
x(i:length(x))=1;
subplot(2,1,1)
plot(t,x)
xlabel('time')
ylabel('amplitude')
title('Unit Step signal ')  
axis([-2 2 -2 2])
x=zeros(1,length(t));
j=find(t==min(t));
x(j:i)=1;
subplot(2,1,2)
plot(t,x)
xlabel('time')
ylabel('amplitude')
title('Unit Step signal folded about Y-axis')  
grid
axis([-5 5 -2 2])

Output:

 

% Folding for signal or time reversal sine wave

Clc
Close all
Clear all
t = [0:.01:1]; % independent (time) variable 
A = 8; % amplitude 
f1 = 2; % create a 2 Hz sine wave lasting 1 sec 
x = A*sin(2*pi*f1*t); 
lx=length(x);
nx=0:lx-1;
xf=fliplr(x);
nf=-fliplr(nx);
subplot(2,1,1);
stem(nx,x);
xlabel('nx');
ylabel('amplitude)');
title('original signal');
subplot(2,1,2);
stem(nf,xf);
xlabel('nf');
ylabel('amplitude');
title('folded signal');

 

Time reversal output

% Folding for signal or time reversal Ramp wave

 clc;
 clear all
t=0:0.1:10;
x=0.5*t;
lx=length(x);
nx=0:lx-1;
xf=fliplr(x);
nf=-fliplr(nx);
subplot(2,1,1);
stem(nx,x);
xlabel('nx');
ylabel('x(nx)');
title('original signal');
subplot(2,1,2);
stem(nf,xf);
xlabel('nf');
ylabel('xf(nf)');
title('folded signal');
Ramp time shifted

% Folding for signal or time reversal Sawtooth wave

fs=input('enter the sampling frequency:')
T=1/fs;
t= -1*T:T/fs: T;
p=zeros(1,length(t));
c=input('enter the number of samples to be included:')
i=find(t==0);
for j=i+1:i+c
   p(j+1)=p(j)+1;
end
subplot(2,1,1)
plot(t,p)
xlabel('time')
ylabel('amplitude')
title('Sawtooth pulse')
p1=zeros(1,length(t));
p1(i-c:i-1)=fliplr(p(i+1:i+c))
subplot(2,1,2)
plot(t,p1)
xlabel('time')
ylabel('amplitude')
title('Sawtooth pulse folded about Y-axis')
Result:
enter the sampling frequency:1000
fs = 1000
enter the number of samples to be included:200
c=200

Output:

% Amplitude scaling

t = [0:.01:1];         % independent (time) variable 
A = 8; % amplitude 
f1 = 2; % create a 2 Hz sine wave lasting 1 sec 
s1 = A*sin(2*pi*f1*t); 
subplot(3,1,1)
plot(s1);
xlabel('t');
ylabel('amplitude');
title('input signal');
s2=2*s1;
subplot(3,1,2)
plot(s2);
xlabel('t');
ylabel('amplitude');
title('amplified input signal');
s3=s1/2;
subplot(3,1,3)
plot(s3);
xlabel('t');
ylabel('amplitude');
title('attenuated input signal');
Signal amplified and attenuated

Signal Amplification/Attenuation :  

 Y(n)= ax(n) if                    a < 1  attenuation

                                             a >1  amplification

 

% Amplitude scaling of sine wave

clc;
clear all;
close all;
t=0:.01:1;                
A = 8;  
f1 = 2;                        
s1 = A*sin(2*pi*f1*t);  
subplot(3,1,1);
plot(t,s1);
xlabel('time');
ylabel('amplitude');
title('input signal');
s2=2*s1;
subplot(3,1,2);
plot(t,s2);
xlabel('time');
ylabel('amplitude');
title('amplified input signal');
s3=s1/2;
subplot(3,1,3);
plot(s3);
xlabel('time');
ylabel('amplitude');
title('attenuated input signal');

Output:

% Amplitude scaling for sequences

n=0:1:6
s1 = [1 2 3 3 1 1 1]
subplot(3,1,1)
stem(n,s1);
xlabel('n');
ylabel('amplitude');
title('input signal');
s2=4*s1;
subplot(3,1,2)
stem(n,s2);
xlabel('t');
ylabel('amplitude');
title('amplified input signal');
s3=s1/4;
subplot(3,1,3)
stem(n,s3);
xlabel('t');
ylabel('amplitude');
title('attenuated input signal');
Amplified and attenuated signal

Time scaling: 

The Time scaling of a signal x(t) can be accomplished by replacing t by at where t is a scaling factor.

Y(t)=x(at) : a= arbitrary constant 

If a<1 (a=1/2) i e x(t/2)---- the signal y(t) is expanded by 2

If a>1 (a=2) i e x(2 t )---- the signal y(t) is compressed 2

% Time scaling of Triangular wave

fs=input('enter the sampling frequency')
T=1/fs;
t=0:T/fs:T;
p=zeros(1,length(t));
p1=p;
for i=2:((length(t)-1)/2)+1
   p(i)=p(i-1)+1;
   p(length(t)-(i-1))=p(i);
end
c=input('enter the scaling factor')
t1=t./c;
if c<1
subplot(2,1,1)
plot(t,p)
title('triangular pulse')
xlabel('time')
ylabel('amplitude')
grid
subplot(2,1,2)
plot(t1,p)
title('expanded triangular pulse')
xlabel('time')
ylabel('amplitude')
grid  
else
subplot(2,1,2)    
plot(t1,p)
grid
title('Compressed Triangular Pulse')
end
xlabel('time')
ylabel('amplitude')

Result:

enter the sampling frequency:10

fs =10

enter the scaling factor:2

c = 2

Output:

enter the sampling frequency10

fs = 10

enter the scaling factor:0.2

c =0.2

Output:

% Time scaling of sine wave

t = [0:.05:pi];                 % independent (time) variable 
A = 8;                             % amplitude 
f1 = 2;                            % create a 2 Hz sine wave lasting 1 sec 
s1 = A*sin(2*pi*f1*t); 
subplot(3,1,1)
plot(s1);
xlabel('t');
ylabel('amplitude');
title ('sine signal')
s2=A*sin(2*2*pi*f1*t);                % scaling by A=4
subplot(3,1,2)
plot(s2);
xlabel('t');
ylabel('amplitude');
title ('scaled sine signal with a=4')
s3=A*sin(.5*pi*f1*t);          % scaling by A=1/4
subplot(3,1,3);
plot(s3);
xlabel('t');
ylabel('amplitude');
title ('scaled sine signal with a=1/4')
Time scaling of signal

% Time scaled version of a Sawtooth Pulse

fs=input('enter the sampling frequency')
T=1/fs;
t=0:T/fs:T;
p=zeros(1,length(t));
k=input('enter the  duration of the pulse interms of number of time instances to be included')
for i=2:k
   p(i)=p(i-1)+1;
end                                                                
c=input('enter the scaling factor')
t1=t./c;
if c<1
subplot(2,1,1)
plot(t,p)
xlabel('time')
ylabel('amplitude')
grid
title('Sawtooth Pulse')  
subplot(2,1,2)
plot(t1,p)
xlabel('time')
ylabel('amplitude')
grid
title('Expanded Sawtooth Pulse')
else
subplot(2,1,1)
plot(t,p)
xlabel('time')
ylabel('amplitude')
grid
title('Sawtooth Pulse')    
subplot(2,1,2)    
plot(t1,p)
xlabel('time')
ylabel('amplitude')
grid
title('Compressed Triangular Pulse')
end

Output:

Result: In this experiment the various operations on signals have been performed Using MATLAB have been demonstrated.

Viva Questions:

1. Define Delta Function.

Ans:The delta function is a generalized function that can be defined as the limit of a class of delta sequences. The delta function is sometimes called "Dirac's delta function" or the "impulse symbol”. The Dirac delta function, often referred to as the unit impulse or delta function, is the function that defines the idea of a unit impulse in continuous-time. Informally, this function is one that is infinitesimally narrow, infinitely tall, yet integrates to one. 

integral subscript negative infinity end subscript superscript infinity delta left parenthesis t right parenthesis d t space equals space 1

2. What is Signal Modeling.

Ans: Small-signal modeling is a common analysis technique in engineering which is used to approximate the behavior of nonlinear devices with linear equations and signals.

3. Define Periodic and a periodic Signal.

Ans: A signal is said to be periodic, if it is repeated over a cycle of time or a regular interval of time.

         A signal which does not repeat itself after a specific interval of time is called aperiodic signal

4. Define Continuous and Discrete Time Signals.

Ans:If for a signal, the quantities are defined only on a discrete set of times, we call it a discrete-time signal

A signal is defined at any instant of time is called continuous signal .

  • Created
    Dec 02, 2019
  • Updated
    Feb 13, 2020
  • Views
    121