0% found this document useful (0 votes)
108 views

Activity Signals

This document contains MATLAB code for generating and plotting various types of sequences including impulse, step, sinusoidal, complex exponential, and decaying exponential sequences. It also contains function definitions for operations on sequences such as addition, multiplication, shifting, folding, and computing the sum of sinusoidal terms. Plots are generated to illustrate sequences and the effects of sequence operations.

Uploaded by

api-273922893
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
108 views

Activity Signals

This document contains MATLAB code for generating and plotting various types of sequences including impulse, step, sinusoidal, complex exponential, and decaying exponential sequences. It also contains function definitions for operations on sequences such as addition, multiplication, shifting, folding, and computing the sum of sinusoidal terms. Plots are generated to illustrate sequences and the effects of sequence operations.

Uploaded by

api-273922893
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Midterm ex2_1a

Midterm ex1

n=[-5:5]

n=0:1:40; % sample index from 0 to 20

x=2*impseq(-2,-5,5) - impseq(4,-5,5);

x=sin(0.1*pi*n); % evaluate sin (0.2 pi n)

stem(n,x); title('Sequence in Problem 2.1a')

Hs=stem(n, x, 'b', 'filled') ; % stem plot with


handle Hs

xlabel('n');
ylabel('x(n)');

set(Hs, 'markersize', 4); % change circle size


xlabel('n'); ylabel('x(n) ') ; % label axis

title(' Stem Plot of sin (0.2 pi n) ') ; % title plot


Midterm ex2_1b
n=[0:20];
x1 = n.*(stepseq(0,0,20) - stepseq(10,0,20));
Midterm ex2
n=0:1:40; % sample index from 0 to 20
xn=sin(0.1*pi*n); % evaluate sin (0.2 pi n)

t=0:0.01:2;
xt=sin(2*pi*t);
plot(t, xt, 'b') ;
hold on;

x2 = 10*exp(-0.3*(n-10)).*(stepseq(10,0,20) stepseq(20,0,20));
x = x1+x2;
subplot (2,2,3); stem(n,x);
title('Sequence in Problem 2.1b')
xlabel('n');
ylabel('x(n)');

%creates plot with blue line


Hs=stem(n*0.05,xn,'b','filled');
%stem plot with handle hs

Midterm ex2_1c

set (Hs,' markersize', 4);

n= [0:50];

%change circle size

x=cos(0.04*pi*n) +0.2*randn(size(n));

ylabel('x(t) and x(n) ') ;

subplot(2,2,2); stem(n,x);

xlabel(' t in sec') ;

title('Sequence in Problemc 2.1c')

title('Plot of sin (2 pi t) and its samples') ;

xlabel('n');

hold off;

ylabel('x(n)');

Midterm ex2_1d
n=[-10:9]; x = [5,4,3,2,1];
xtilde = x'* ones(1,4);
xtilde = (xtilde(:))';
subplot (2,2,4);
stem(n,xtilde);

Midterm ex4

function[x, n] =impseq(n0,n1,n2)
%generates x(n) = delta (n-n0); n1<=n<=n2
%[x,n]=impseq(n0,n1,n2)
n=[n1:n2];
x=[(n-n0)==0];

title('Sequence in Problem 2.1d')


xlabel('n');

ylabel('xtilde(n)');

Midterm ex5
function[x, n] =stepseq(n0,n1,n2)

Midterm ex3
>> n=0:1:40; % sample index from 0 to 20
xn=sin(0.1*pi*n); % evaluate sin (0.2 pi n)
t=0:0.01:2;
xt=sin(2*pi*t);

%generates x(n) =u(n-n0);n1<=n<=n2


%-------%[x,n]=stepseq(n0,n1,n2l
%
n=[n1:n2]; x=[(n-n0)>=0];

subplot(2,1,1); %two rows, one column, first plot


plot(t, xt, 'b')
%creates plot with blue line

Midterm ex_Function

xlabel(' t in sec');

function xt= sinsum (t, ck)

ylabel('x(t) ') ;

% computes sum of sinusoidal terms of the form


in (1.1)

title(' Plot of sin(2 pi t)') ;


% x=sinsum(t,ck)
subplot(2,1,2); % two row, one column, second
plot

K=length(ck) ; k=1:K;

Hs=stem(n,xn,'b','filled');

ck=ck(:)'; t=t(:)';

%stem plot with handle hs

xt=ck * sin (2* pi *k'*t )

set (Hs,' markersize', 4);


%change circle size
Midterm ex_Compseq
ylabel(' x(n) ') ;
n = [0:10] ;
xlabel('n') ;

x = exp ((2+3j)*n)
title('Plot of sin (2 pi n)') ;

Midterm ex_Perseq
xtilde = x' * ones (1,P);
% P columns of x

Midterm ex_Realseq
n=[0:10]; x=(0.9).^n

xtilde = xtilde (:) ;


% long column vector
xtilde = xtilde'
% long row vector

Midterm ex_Sigadd
function [y, n] = sigadd (x1,n1,x2,n2)

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


Midterm ex_Script
%script file to implement(1.1)
t=0:0.01:1;
k=1:2:5;

%--------------------------------------------------%[y, n] = sigadd(x1,n1,x2,n2)
%y=sum sequence over n, w/c includes n1 and n2
%x1=first sequence over n1

ck=1./k;

%x2=second sequence over n2 (n2 can be


different from n1)

xt= ck* sin (2* pi *k'*t)

%
n = min(min(n1),min(n2)): max(max(n1),max(n2));
%duration of y(n)

Midterm ex_Sigfold

y1 = zeros (1,length(n)); y2=y1;

function [y, n] = sigfold(x, n)

%initialization

%implements y(n) =x(-n)

y1(find((n>=min(n1)) & (n<=max(n1))==1))=x1;

%--------

%x1 with the duration of y

%(y, n) = sigfold(x, n)

y2 (find((n>=min(n2))&(n<=max(n2)) ==1))=x2;

%x2 with duration of y

y=fliplr(x) ;

y=y1+y2;

n=-fliplr(n) ;

%sequence addition

Midterm ex_Sigmult

function[y, n] =sigmult(x1,n1,x2,n2)
%implements y(n) =x1(n)*x2(n)
%-------------------------------%[y,n]=sigmult(x1,n1,x2,n2)

Midterm ex_Sigshift
function[y, n] = sigshift(x, m, k)
%implements y(n) = x (n-k)
%---------------%[y, n] =sigshift(x, m, k)
%

%y=product sequence over n, w/c includes n1


and n2

n=m+k ;

%x1=first sequence over n1

y=x;

%x2=second sequence over n2


%------------n=min(min(n1), min(n2)): max(max(n1),max(n2));
%duration of y(n)

Midterm ex_Sinsum
function xt=sinsum(t, ck)

y1=zeros(1,length(n)); y2=y1;

% computes sum of sinusoidal terms of the form


in (1.1)

y1(find((n>=min(n1))&(n<=max(n1))==1))=x1;

% x=sinsum(t,ck)

y2(find((n>=min(n2))&(n<=max(n2))==1))=x2;

K=length(ck) ; k=1:K;

%x2 with duration of y

ck=ck(:)'; t=t(:)';

y=y1.*y2;

xt=ck * sin (2* pi *k'*t )

Midterm ex_Sinuseq
n = [0:10];
x = 3*cos (0.1*pi*n+pi/3) + 2*sin(0.5*pi*n)

You might also like