You are on page 1of 33

Lab 5

Signals and Operations


Basic Signals

 Unit impulse:
 Unit step
 Rectangle
 Triangle
 Saw tooth
 Square wave
 Sinc function
Unit impulse:

>> t = 0:0.01:1;
>> y = [zeros(1,50),1,zeros(1,50)];
>> plot(t,y);

Another method
>>t=[-5:10];
>>y=[zeros(1,5) 1 zeros(1,10)];
>>stem(t,y);
>>title('Unit Impulse Sequence')
>>xlabel('t');
>>ylabel('y(t)');
Unit Step

>>t = 0:0.01:1;
>> y = [zeros(1,50),ones(1,51)];
>> plot(t,y);

Another method
t=[0:10];
y = ones(11,1);
stem(t,y);
title('Unit Step Sequence')
xlabel('t');
ylabel('y(t)');
Unit Step

Another method
t=[-5:5]
y=[zeros(5,1);ones(6,1)]
stem(t,y);
title('Unit Step Sequence')
xlabel('t');
ylabel('y(t)');

 The built-in function of Heaviside can also be


used.
Rectangular pulse

>>t=-1:0.001:1;
>> y=rectpuls(t);
>> plot (t,y);
Triangular pulse

>> t=-1:0.001:1;
>> y=tripuls(t);
>> plot (t,y);
sawtooth

>> fs = 10000;
>> t = 0:1/fs:1.5;
>> x = sawtooth(2*pi*50*t);
>> plot(t,x), axis([0 0.2 -1 1]);
Square wave

>> t=0:0.001:20;
>> y=square(t);
>> plot(t,y)
Sinc

>> t = -5:0.1:5;
>> y = sinc(t);
>> plot(t,y)
Complex signals

 f=3;
 t=[0:.01:2]
 x = exp(2*pi*j*f*t);
 plot(x)
 plot(real(x));
 plot(imag(x))
Basic operations on signals

Addition of signals:

y1=[10 10 10 10 10]
y2=[1 2 3 4 5]
n=[-1:3];
y=y1+y2;
subplot(3,1,1);
stem(n,y1)
subplot(3,1,2);
stem(n,y2)
subplot(3,1,3);
stem(n,y)
scaling

y1=[2 5 6 1 4]
n=[2:6]
y=2.5*y1
plot(n,y,n,y1)
ylim([0 20]);
xlim([0 8]);
axis([2 6 -2 16])
Basic Signal Operations

 Original Signal

x=[0,0,0,1,2,3,4,3,2,1,0,0,0];
n=[0,1,2,3,4,5,6,7,8,9,10,11,12];
stem(n,x,'filled')
title('signal x[n]')
ylabel('magnitude')
xlabel('Sample No.')
axis([0 12 -1 5])
Delayed Signal x[n-2]

x=[0,0,0,0,0,1,2,3,4,3,2,1,0];
n=[0,1,2,3,4,5,6,7,8,9,10,11,12];
stem(n,x,'filled')
title('signal x[n-2]')
ylabel('magnitude')
xlabel('Sample No.')
axis([0 12 -1 5])
Advance Signal x[n+2]

x=[0,1,2,3,4,3,2,1,0,0,0,0,0];
n=[0,1,2,3,4,5,6,7,8,9,10,11,12];
stem(n,x,'filled')
title('signal x[n+2]')
ylabel('magnitude')
xlabel('Sample No.')
axis([0 12 -1 5])
Down sampling x[2n]

 x=[1:20 19:-1:1];
 figure,stem(x,'filled');
 axis([0 41 -1 22]);
 Dx=x(1:2:length(x));
 figure,stem(Dx,'filled');
 axis([0 41 -1 22]);
Up sampling x[n/2]

x=[1:20 19:-1:1];
figure,stem(x,'filled');
axis([0 41 -1 22]);
Ux=zeros(1,2*length(x));
Ux(1:2:2*length(x))=x(1:length(x));
figure,stem(Ux,'filled');
axis([0 80 -1 22]);
Signal folding

x=[2 5 6 1 4] ;
n=[2:6];
y=fliplr(x);
subplot(2,1,1);
stem(n,x);
xlim([0,10]);
subplot(2,1,2);
stem(n,y);
xlim([0,10]);

You might also like