Академический Документы
Профессиональный Документы
Культура Документы
𝜹(𝒏 − 𝟐) , −𝟓 ≤𝒏 ≤𝟓
clc;
close all;
clear all;
n=-5:5;
a=[zeros(1,7) 1 zeros(1,3)];
stem(n,a,'r');
xlabel('samples')
ylabel('amplitude')
title('Impulse at n=2')
Impulse at n=2
1
0.9
0.8
0.7
0.6
amplitude
0.5
0.4
0.3
0.2
0.1
0
-5 -4 -3 -2 -1 0 1 2 3 4 5
samples
In MATLAB, the function zeros(1,N) is used to generate unit sample sequence over a finite interval of
length N. A unit sample sequence of length N and delayed by samples M, where M < N, can be
generated by ud=[zeros(1,M) 1 zeros(1,N-M-1)];
Impulse function at n=2 is plotted using above code as n-2 represents that the impilse is delayed two
units so two more zeros are included on the left.
𝒖(𝒏 + 𝟒) , −𝟖 ≤𝒏 ≤𝟖
clc;
close all;
clear all;
n=-8:8;
b=[zeros(1,4) ones(1,13)];
stem(n,b,'r');
xlabel('samples')
ylabel('amplitude')
title('Unit Step at n>=-4')
0.9
0.8
0.7
0.6
amplitude
0.5
0.4
0.3
0.2
0.1
0
-8 -6 -4 -2 0 2 4 6 8
samples
A unit step sequence of length N delayed by samples M, where M < N, can be generated by
sd=[zeros(1,M) ones(1,N-M)].
A unit step function at n>= -4 is plotted using above code as n+4 represents that signal is advanced 4
units so four zeros are decreased on left side.
Task 2: Generate and plot the following sequence over the indicated interval
𝜋
𝑥(𝑛) = cos(0.1𝜋𝑛 + ) + 𝑒 (0.1+𝑗0.3)𝑛 + 0.2 𝑤(𝑛) , −10 ≤ 𝑛 ≤ 10
6
where 𝑤(𝑛) is normally distributed random sequence with zero mean and unit variance.
clc;
close all;
clear all;
n=-10:10;
a= cos((0.1*pi*n)+(pi/6));
b=exp((0.1 + 0.3*1i)*n);
c = 0.2*(randn(1,21));
s=a+b+c;
stem(n,s,'r');
xlabel('samples')
ylabel('amplitude')
title('Addition of all signals')
0
amplitude
-1
-2
-3
-4
-10 -8 -6 -4 -2 0 2 4 6 8 10
samples
A random signal of length N with samples normally distributed with zero mean and unity variance can be
generated by x=randn(1,N).All the signals are aligned and then added.
y=zeros(1,length(n4));
y1=y;y2=y;y3=y;
y(find((n4>=min(n))&(n4<=max(n))==1))=x;
y1(find((n4>=min(n1))&(n4<=max(n1))==1))=x;
y2(find((n4>=min(n2))&(n4<=max(n2))==1))=x;
y3(find((n4>=min(n3))&(n4<=max(n3))==1))=x3;
s=(y.*y3)+(y1.*y2);
figure(1);
stem(n4,s,'r');
xlabel('samples')
ylabel('amplitude')
title('Signal = x(3-n)x(n) + x(n+4)x(n-1)')
70
60
50
40
amplitude
30
20
10
-10
-20
-8 -6 -4 -2 0 2 4 6 8
samples
Even and Odd Parts:
s1=fliplr(s);
n5=-fliplr(n4);
t=min(min(n4),min(n5)):max(max(n4),max(n5));
s2=zeros(1,length(t));
s3=zeros(1,length(t));
s2(find((t>=min(n4))&(t<=max(n4))==1))=s;
s3(find((t>=min(n5))&(t<=max(n5))==1))=s1;
se=(s2+s3)/2;
s0=(s2-s3)/2;
figure(2);
subplot(211);
stem(t,se,'g');
xlabel('samples')
ylabel('amplitude')
title('Even Part Of signal')
subplot(212);
stem(t,s0,'g');
xlabel('samples')
ylabel('amplitude')
title('Odd Part Of signal')
30
amplitude
20
10
0
-8 -6 -4 -2 0 2 4 6 8
samples
Odd Part Of signal
50
amplitude
-50
-8 -6 -4 -2 0 2 4 6 8
samples
%Energy of signal
E=sum(abs(s).^2);
E=
13264
The even and odd parts are given by
Using fliplr and –fliplr command inverse of the signal is found out and then as their length are not equal
so using find command , their length become equal and then they are added. Energy of signal is found
out by taking square of absolute value of signal.