Unit Impulse
Unit Impulse
n=[-5:5]; x=[n==0]; stem(n,x); title('Unit impulse sequence'); xlabel('n'); ylabel('(xn)'); ylim([-2,2]); % Unit step sequence. n=[-5:5]; x=[n>=0]; %'>='Greater then or Equal to. stem(n,x); title('Unit step sequence'); xlabel('n'); ylabel('(xn)'); %'=='Equal to.
% Square wave genration. t=[0:0.1:2]; sqw1=square(2*pi*2*t); plot(t,sqw1); ylim([-2,2]); %ylim([ymin ymax]) sets the axis limits in the current axes to the specified values. title('Square wave'); % Square wave genration. t=[0:0.01:2]; sqw1=square(2*pi*2*t); subplot(2,1,1); plot(t,sqw1); ylim([-2,2]); %ylim([ymin ymax]) sets the axis limits in the current axes to the specified values. title('Square wave'); t=[0:0.1:2]; sqw2=square(2*pi*2*t,75); subplot(2,1,2); plot(t,sqw2); ylim([-2,2]); %ylim([ymin ymax]) sets the axis limits in the current axes to the specified values.
title('Square wave with 75% duty cycle'); % Saw-tooth and triangular wave generation. t=[0:0.01:2]; saw1=sawtooth(2*pi*3*t); subplot(2,1,1); plot(t,saw1); ylim([-2,2]); %ylim([ymin ymax]) sets the axis limits in the current axes to the specified values. title('sawtooth wave'); subplot(2,1,2); saw2=sawtooth(2*pi*3*t,1/2); plot(t,saw2); ylim([-2,2]); %ylim([ymin ymax]) sets the axis limits in the current axes to the specified values. title('Triangular wave'); %Real exponential sequence. %To generate x(n)=(0.9)^n;. n=[0:10]; 0<=n<=10; x=(0.9).^n; plot(n,x) title('Real exponential sequence');
x=exp(2*n); plot(n,x) title('Real exponential sequence'); %Step reponse of frist order system. t=0:0.1:10; tow=0.3; x=1-exp(-t/tow); plot(t,x); title('Step reponse of frist order system'); xlabel('t'); ylabel('x(t)'); ylim([0,2]); % Periodic sequence %A sequence is periodic if x(n)=x(n+N). %To genrate p period of x(n) from one period ,we can copy x(n)p time. %xtilde=[x,x,x,x,x]; x=[0 1 1.5 1 0 0 1 2 3 4 3 2 1 -1 -1.5 -1 0 0 0.5 0 0 0]; x1=[x,x,x,x,x,x,x]; subplot(2,1,1); plot(x1); x2=[x,x,x,x,x]; subplot(2,1,2); plot(x2);
% To add tow sequence x1(n) and x2(n) require operation "+". % But the length of both sequence must be equal have the same sample % position. y1=[10 10 10 10 10] n1=1:5; y2=[1 2 3 4 5] n2=1:5; n=1:5; y=y1+y2; subplot(3,1,1); stem(n,y1); subplot(3,1,2); stem(n,y2); subplot(3,1,3); stem(n,y); Signal scaling. % each sample is multiplied by scalar use the command "*" for scaling. y1=[2 5 6 1 4] n=2:6 y=2.5*y1 subplot(3,1,1) stem(n,y) subplot(3,1,2) stem(n,y1) ylim([0,20]) xlim([0,8]) % Signal shifting.
% Each sample of x(n) is shifted by an amount k to obtain shifted sequence % y(n). % Right shift: y(m)=x(m-k) % Left shift: y(m)=x(m+k) x=[2 5 6 1 4]; n=2:6; % Right shift by 3 samples y(m). m=n+3; y=x; % Left shift by 1 sample z(t) t=n-1 z=x subplot(3,1,1); stem(n,x); xlim([0,10]); subplot(3,1,2); stem(m,y); xlim([0,10]); subplot(3,1,3); stem(t,z); xlim([0,10]); %folding. % Implemanted by "fliplr(x)" x=[2 5 6 1 4] n=2:6 y=-fliplr(x) subplot(2,1,1) stem(n,x) xlim([0,10])
%Sample summation %add all sample value of x(n)between n1 & n2 % implementation by "sum(x(n1:n2)) x=[2 5 6 1 4] sx=sum(x(1:5)) %Sample multiplication %multiplies all sample value of x(n)between n1 & n2 % implementation by "prod(x(n1:n2)) x=[2 5 6 1 4] sx=prod(x(1:5))