Genaration of various signals and sequences

Aim: To generate different types of signals Using MATLAB Software.

EQUIPMENTS:

PC with windows OS

MATLAB Software

THEORY : If the amplitude of the signal is defined at every instant of time then it is called continuous signal. If the amplitude of the signal is defined at only at some instants of time then, it is called discrete signal. If the signal repeats itself at regular intervals  of time, then it is called periodic signal. Otherwise, they are called aperiodic signals.  

1.UNIT IMPULSE: a) Continuous signal:  

delta left parenthesis t right parenthesis equals open curly brackets table attributes columnalign left end attributes row cell 0 space space space space space space t equals n o t space e q u a l space t o space 0 end cell row cell infinity space space space space t equals 0 end cell end table close

and  

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

Also called unit impulse function. The value of delta function can also be defined in the sense of generalized function

integral subscript negative infinity end subscript superscript infinity delta left parenthesis t right parenthesis ? left parenthesis t right parenthesis d t space equals space ? left parenthesis 0 right parenthesis space space space space space space space space space space ? left parenthesis t right parenthesis equals T e s t space f u n c t i o n

space space space space space space space space space space space space space space space space space space space space space space space space space space space space space space space

b) Unit Sample sequence

delta left parenthesis n right parenthesis space space equals space open curly brackets table attributes columnalign left end attributes row cell 1 comma space n equals 0 end cell row cell 0 comma space n space space n o t space e q u a l space t o space 0 end cell end table close
space space space space space space space space space space space space space space space

Matlab program:

i) UNIT IMPULSE SIGNAL 

clc;  
clear all;
close all;
t=-5:0.001:5
i=find(t==0);
x=zeros(1,length(t));
x(i)=1;
plot(t, x)
xlabel('time')
ylabel('amplitude')
title('unit impulse function')]

Output:

 

ii) unit Impulse sequence

clc;
clear all;
close all;
n=-5:1:5
i=find(n==0);
x=zeros(1,length(n));
x(i)=1;
stem(n, x)
xlabel('time')
ylabel('amplitude')
title('unit impulse function')

Output:

 

 

2) Unit Step Function u(t):   

integral subscript negative infinity end subscript superscript infinity u left parenthesis t right parenthesis ? left parenthesis t right parenthesis d t space equals space integral subscript 0 superscript infinity ? left parenthesis t right parenthesis d t
u left parenthesis t right parenthesis space equals space open curly brackets table attributes columnalign left end attributes row cell 1 space space space space space t greater or equal than 0 end cell row cell 0 space space space space space t less than 0 end cell end table close

b)Unit Step Sequence u(n): )={ 1, n =

                                                                0, n < 0

iii) Unit step generation

clc;
clear all;
close all;
t=-10:0.01: 10;
x=zeros(1,length(t));
i=find(t==0);
x(i:length(x))=1;
plot(t, x)
xlabel('time')
ylabel('amplitude')
title('Unit Step Signal')
axis([-5 5 -1 2])

OUTPUT:

iv) Unit Step Sequence

clc;
clear all;
close all;
t=-10:1: 10;
x=zeros(1,length(t));
i=find(t==0);
x(i:length(x))=1;
stem(t, x)
xlabel('time')
ylabel('amplitude')
title('Unit Step Sequence')
axis([-5 5 -1 2])

OUTPUT:

3. Square waves: Like sine waves, square waves are described in terms of period, frequency and amplitude:

Peak amplitude, Vp , and peak-to-peak amplitude, Vpp , are measured as you might expect. However, the rms amplitude, Vrms , is greater than that of a sine wave. Remember that the rms amplitude is the DC voltage which will deliver the same power as the signal. If a square wave supply is connected across a lamp, the current flows first one way and then the other. The current switches direction but its magnitude remains the same. In other words, the square wave delivers its maximum power throughout the cycle so that Vrms is equal to Vp . 

Although a square wave may change very rapidly from its minimum to maximum voltage, this change cannot be instaneous. The rise time of the signal is defined as the time taken for the voltage to change from 10% to 90% of its maximum value. Rise times are usually very short, with duration measured in nanoseconds (1 ns = 10^(-9) s), or microseconds (1 µs = 10^(-6)s), as indicated in the graph

v) Square wave wave generator

fs = 1000;
t = 0:1/fs:1.5;
x1 = square(2*pi*50*t);
subplot(1,2,1),plot(t,x1), axis([0 0.2 -1.2 1.2])
xlabel('Time (sec)');ylabel('Amplitude'); title('Square Periodic Wave');
subplot(1,2,2),plot(t,x2), axis([0 0.2 -1.2 1.2])
xlabel('Time (sec)');ylabel('Amplitude'); title('discrete Square Periodic Wave');

 

OUTPUT:

4. Sawtooth Waveform Generation

The sawtooth wave is a non-sinusoidal waveform. It is named a sawtooth based on its resemblance to the teeth on the blade of a saw. The convention is that a sawtooth wave ramps upward and then sharply drops. However, there are also sawtooth waves in which the wave ramps downward and then sharply rises. The latter type of sawtooth wave is called a 'reverse sawtooth wave' or 'inverse sawtooth wave'. As audio signals, the two orientations of sawtooth wave sound identical. The piece wise linear function based on the floor function of time t, is an example of a saw tooth wave with period1.

Sawtooth waveform

vi)  Sawtooth wave generator

fs = 10000;
t = 0:1/fs:1.5;
x = sawtooth(2*pi*50*t);
subplot(1,2,1);
plot(t,x), axis([0 0.2 -1 1]);
xlabel('t'),ylabel('x(t)')
title('sawtooth signal');
N=2; fs = 500;n = 0:1/fs:2;
x = sawtooth(2*pi*50*n);
subplot(1,2,2);
stem(n,x), axis([0 0.2 -1 1]);
xlabel('n'),ylabel('x(n)')
title('sawtooth sequence');

OUTPUT:

Sawtooth wave output

Another method for generation Sawtooth waveform

vii) Sawtooth waveform

It is defined as x(t)=t for 0<t<T;

                               =0 elsewhere.

clc;
clear all;
close all;
fs=input('enter the value of sampling frequency')
T=1/fs;
t=0:T/fs:T;
p=zeros(1,length(t));
c=input('enter the  duration of the pulse interms of number of time instances to be included')
for i=2:c
   p(i)=p(i-1)+1;
end                                                                
plot(t,p)
title('sawtooth signal')
xlabel('time')
ylabel('amplitude')

Result:

enter the value of sampling frequency 1000

fs =  1000

enter the  duration of the pulse interns of number of time instances to be included 500

c = 500

OUTPUT:

viii) Saw tooth sequence

clc;
clear all;
close all;
fs=input('enter the value of sampling frequency')
T=1/fs;
t=0:T/fs:T;
p=zeros(1,length(t));
c=input('enter the  duration of the pulse interms of number of time instances to be included')
for i=2:c
   p(i)=p(i-1)+1;
end                                                                
stem(t,p)
title('sawtooth sequence')
xlabel('time')
ylabel('amplitude')

Result:

enter the value of sampling frequency 100

fs =  100

enter the  duration of the pulse interns of number of time instances to be included 50

c =50

OUTPUT:


 

ix)  Sawtooth Pulse Train

fs=input('enter the value of sampling frequency')
T=1/fs;
t=0:T/fs:T;
p=zeros(1,length(t));
k=input('enter the number of cycles to be plotted')
c=input('enter the  duration of the pulse interms of number of time instances to be included')
for i=2:c
   p(i)=p(i-1)+1;
end                                                                
t1=0:T/fs:k*T;
p1=zeros(1,length(t1));
p1(1:length(p)-1)=p(1:length(p)-1);
p(1)=[];
for i=1:k-1
   p1(i*length(p)+2:(i+1)*length(p)+1)=p      
end
plot(t1,p1)
title('Sawtooth pulse Train')
xlabel('time')
ylabel('amplitude')

Result:

enter the value of sampling frequency 100

fs = 100

enter the number of cycles to be plotted 3

k =3

enter the  duration of the pulse interms of number of time instances to be included 50

c =50

OUTPUT:

5. Triangular wave: A triangle wave is a non-sinusoidal waveform named for its triangular shape.A bandlimited triangle wave pictured in the time domain (top) and frequency domain (bottom). The fundamental is at 220 Hz (A2).Like a square wave, the triangle wave contains only odd harmonics.

Triangular wave

x) To generate a triangular pulse

A=2; t = 0:0.0005:1;
x=A*sawtooth(2*pi*5*t,0.25); %5 Hertz wave with duty cycle 25%
plot(t,x);
grid
axis([0 1 -3 3]);

OUTPUT:

Triangular wave

xi) To generate a triangular pulse

fs = 10000;t = -1:1/fs:1;
x1 = tripuls(t,20e-3); x2 = rectpuls(t,20e-3);
subplot(211),plot(t,x1), axis([-0.1 0.1 -0.2 1.2])
xlabel('Time (sec)');ylabel('Amplitude'); title('Triangular Aperiodic Pulse')
subplot(212),plot(t,x2), axis([-0.1 0.1 -0.2 1.2])
xlabel('Time (sec)');ylabel('Amplitude'); title('Rectangular Aperiodic Pulse')
set(gcf,'Color',[1 1 1])

OUTPUT:

6) Rectangular Pulse

xii) To generate a rectangular pulse

t=-5:0.01:5;
pulse = rectpuls(t,2); %pulse of width 2 time units
plot(t,pulse)
axis([-5 5 -1 2]);
grid

6. Sinusoidal Signal Generation: It is a continues signal, it will vary the amplitude of the signal w.r.t time. 

Periodic sinusoidal signal 

% sinusoidal signal

N=64; % Define Number of samples
n=0:N-1; % Define vector n=0,1,2,3,...62,63
f=1000; % Define the frequency
fs=8000; % Define the sampling frequency
x=sin(2*pi*(f/fs)*n); % Generate x(t)
plot(n,x); % Plot x(t) vs. t
title('Sinewave [f=1KHz, fs=8KHz]');
xlabel('Sample Number');

ylabel('Amplitude');

Sinusoidal signal output

% Program to generate a Sinusoidal sequence

clc;
clear all;
close all;
f=input('enter the frequency of the signal');
i=input('enter the no.of cycles to be plotted')
T=i/f;
t=0:T/f:T;
x=sin(2*pi*f*t);
stem(t, x)
title('sinusoidal sequence’)
xlabel(‘time’)
ylabel(‘amplitude’)

Result:

enter the frequency of the signal :100

enter the no.of cycles to be plotted:3

i = 3

OUTPUT:

 

 

7.  RAMP

Ramp Signal:  

It is defined as x(t)=t for t=0

                            = 0 elsewhere

 

% Program to generate  ramp Signal

t=0:0.1:1;
x=0;
for i=2:length(t)
   x(i)=x(i-1)+2;
end
plot(t, x)
grid
title(' Ramp Signal ')
xlabel('time')
ylabel('amplitude')

  OUTPUT

 

 

% Program to generate discrete ramp signal

t=0:0.1:1;
x=0;
for i=2:length(t)
   x(i)=x(i-1)+2;
end
stem(t, x)
grid
title(' Ramp Signal ')
xlabel('time')
ylabel('amplitude')

       OUTPUT:   

 

8. SINC FUNCTION:

% sinc

x = linspace(-5,5);
y = sinc(x);
subplot(1,2,1);plot(x,y)
xlabel(‘time’);
ylabel(‘amplitude’);
title(‘sinc function’);
subplot(1,2,2);stem(x,y);
xlabel(‘time’);
ylabel(‘amplitude’);
title(‘sinc function’);
Sinc function

Result: In this experiment various signals have been generated Using MATLAB

Viva Questions:

1. Define Signal?

Ans: Signal is function of one or more variables to convey information.

2. Define deterministic?

Ans:Signal that can be modeled exactly by a mathematical formula is known as determistic signal

3. Define Random Signal?

Ans: Random signals are random variables which evolve, often with time (e.g. audio noise), but also with distance (e.g. intensity in an image of a random texture), or sometimes another parameter.

4.What is a duty cycle and give the duty cycle for a Square wave?

Ans: Duty cycle=T1/T1+T2.

Duty cycle of squrewave=50%

5. Define Periodic and a periodic Signal.

Ans: If x(t)=x(t+T) then x(t) is periodic signal otherwise it is aperiodic signal.