eg
x= [ 1,2,2,3,3]
n = [-1,0,1,2,3]
The vector n represent time markings. the 0th postion of x[n] is marked by 0 in the vector n.
Delta function
Let us implement a delta function in Gnu Octave. Since we cannot implement infinite length sequences in Octave we will limit the length of the sequence to some finite value.
Write the following code and save it as impseq.m
function [x,n] =impseq (n0,n1,n2)
n=[n1:n2]; x=[ (n-n0) == 0];
The function takes 3 arguements. n1 and n2 are starting and ending points in time. n0 is the point at which the impulse occurs.
See the output below.
octave:47> [x,n]= impseq ( 4 ,0,10)
x =
0 0 0 0 1 0 0 0 0 0 0
n =
0 1 2 3 4 5 6 7 8 9 10
Unit Step
Now let us build a step sequence u(n)
Write an m file as below.
function [x,n] = stepseq(n0,n1,n2)
n=[n1:n2];x= [ (n-n0)>=0 ];
Here again n1 and n2 are time markings and n0 is the point at which step starts.
octave:48> [x,n]= stepseq ( 4 ,0,10)
x =
0 0 0 0 1 1 1 1 1 1 1
n =
0 1 2 3 4 5 6 7 8 9 10
Real exponential sequence
> n= [0:10];
> x=(0.9).^n
x =
Columns 1 through 8:
1.00000 0.90000 0.81000 0.72900 0.65610 0.59049 0.53144 0.47830
Columns 9 through 11:
0.43047 0.38742 0.34868
Complex exponetial sequence
> x= exp( ( 2 + 3j )*n)
x =
Columns 1 through 3:
1.0000e+00 + 0.0000e+00i -7.3151e+00 + 1.0427e+00i 5.2424e+01 - 1.5256e+01i
Columns 4 through 6:
-3.6758e+02 + 1.6626e+02i 2.5155e+03 - 1.5995e+03i -1.6733e+04 + 1.4324e+04i
Columns 7 through 9:
1.0747e+05 - 1.2223e+05i -6.5870e+05 + 1.0062e+06i 3.7693e+06 - 8.0471e+06i
Columns 10 and 11:
-1.9182e+07 + 6.2796e+07i 7.4837e+07 - 4.7936e+08i
Sinusoidal sequence
> x= 3* cos( 0.1*pi*n +pi*3) + 2 *sin(0.5* pi *n)
x =
Columns 1 through 8:
-3.00000 -0.85317 -2.42705 -3.76336 -0.92705 2.00000 0.92705 -0.23664
Columns 9 through 11:
2.42705 4.85317 3.00000
No comments:
Post a Comment