catalogue

5, Experimental contents and results

# 1, Experiment name

matlab implementation of sequence operation.

# 2, Experimental equipment

Computer with matlab software and textbook of digital signal processing course.

# 3, Experimental purpose

1. Understand the graphics and implementation methods of the complex exponential sequence and the sequence obtained by its extension period, and master the programming method of matlab to generate common discrete-time signals;

2. Understand the usage of length function, find function and mod function, and be able to implement the sequence well in the experiment.

# 4, Experimental principle

1. matlab implementation of common sequences

(1) Random sequence.

When the value of the sequence cannot be described by a certain mathematical expression, this sequence is called a random sequence. In MATLAB, there are two kinds of random sequences (actually pseudo-random sequences) to call.

Rand: this function produces a random sequence with a mean value of 0.5 and an amplitude of 0 ~ 1. The call format is rand(1,N) or rand(NXM). The former generates N-point random sequence and the latter generates NXM random matrix.

Randn: this function produces a white noise sequence with a mean of 0 and a variance of 1, which follows a normal (Gaussian) distribution. The call format is the same as above, including randn(1, N) and randn(NXM). The explanation is the same as above.

(2) Periodic sequence.

Let x(n), 0 < n < N-1, MATLAB can expand it into a periodic sequence of K cycles by using xtide(n). There are two methods.

① Simple copy.

That is, the length of the original x(n) is N=length(x), and the length of the xtide obtained by copying K times is K*N, but it is easy to make mistakes when k is too large.

② The method of finding the remainder (modular operation).

The function n1=mode(n.N) completes the modular operation nl=(n, mod, N)=((n)), that is, nl=n+KN, 0 < nl < N-1, K integer, that is, the remainder n1 is between 0 and N-1. Apply this operation to the position vector,

The periodic continuation of finite length sequences can be realized.

If the starting position of x is 0 and the length is N, the following statements can be used:

nxtide=0:K·N-1;

xtide=x(mod(nxtide,N)+1);

In the second statement, since the value of mod(nxtide, N) is always between 0 and N-1, and the rule of MATLAB is that the subscript of x is nx=[1: N], the result of mod function must be added by 1 in the last statement (i.e. the second statement).

2. MATLAB implementation of sequence operation.

(1) Sum of sequences.

To add the sample values with the same position sequence numbers of the two sequences x1 and x2, the position vectors of x1 and x2 must be

The start point and end point are the same, so the length of the sequence is the same, so it is possible to supplement "zero value".

First, make x1 and x2 have the same position vector, so pay attention to the subscript operation of MATLAB

The position vector n1 of x1 and the position vector n2 of x2 become the same position vector n. obviously, min(n) should be equal to the smaller of min(nl) and min(n2). max(n) should be equal to the greater of max(nl) and max(n2). Then, put x1 and X2 on the extended position vector n. since n may be longer than n1 and n2, the lengths of x1 and X2 should be lengthened, which are represented by y1 and y2 respectively, that is, put x1 and X2 on the corresponding position of position vector n, and set the redundant elements to zero.

(2) Product of sequences.

Name the function seqmult, change the head statement of the function to function [y,n]=seqmult(x1,x2,n1,n2), and replace the sixth line above with y=y1*y2 to obtain the product operation of the sequence. It can be seen that in some cases, the position vector of the sequence plays an important role in the operation of the sequence.

# 5, Experimental contents and results

The program uses matlab to realize the correct results and graphics of complex exponential sequence, extended periodic sequence and the sum and product of two sequences.

(1) Experiment 1: the following complex exponential sequence x(n)=e^[(aj-b)n] is generated by programming, in which - 1 < = n < = 10, a = 0.4, B = 0.6.

1. Experimental code

%Complex exponential sequence 1 n=0:10; %definition n Scope of x=exp((0.4*j-0.6)*n); %Generate real part image subplot(2,1,1); %Define the image window as 2 x1(2 Row 1 column)，Coordinates are(1,1)(First row (first column) stem(n,real(x),'b.'); %Draw a real discrete image and set the line to b((blue) dot Linetype axis([-1,10,min(real(x))-0.1,1.2*max(real(x))]); %Define the horizontal axis and vertical axis range of image 1 title('Real part image of complex exponential sequence'); %Description of the image theme xlabel('n'); %Describe the horizontal axis ylabel('real(x)'); %Describe the longitudinal axis grid on; %Open image grid %Generate imaginary part image subplot(2,1,2); %Define the image window as 2 x2(2 Row 2 column)，Coordinates are(2,1)(Second row (first column) stem(n,imag(x),'m.'); %Draw an imaginary discrete image and set the line to m(Magenta) dot Linetype axis([-1,10,min(imag(x))-0.1,1.3*max(imag(x))]); %Define the horizontal axis and vertical axis range of image 2 title('Imaginary part image of complex exponential sequence'); %Description of the image theme xlabel('n'); %Describe the horizontal axis ylabel('imag(x)'); %Describe the longitudinal axis grid on; %Open image grid

2. Experimental results

(2) Experiment 2: x(n)=[1,2,3,4], find the sequence obtained by delaying it by 5 cycles.

1. Experimental code

%Periodic sequence x=[1,2,3,4]; N=length(x); k=5; nx=0:N-1; ny=0:(k*N-1); y=x(mod(ny,N)+1); subplot(2,1,1); %Define the image window as 2 x1(2 Row 1 column)，Coordinates are(1,1)(First row (first column) stem(nx,x,'m.'); %Draw a discrete image and set the line to m(Magenta) dot Linetype axis([-1,N,0,5]); %Define the horizontal axis and vertical axis range of image 1 title('Periodic sequence'); %Description of the image theme xlabel('nx'); %Describe the horizontal axis ylabel('x'); %Describe the longitudinal axis grid on; %Open image grid subplot(2,1,2); %Define the image window as 2 x2(2 Row 2 column)，Coordinates are(2,1)(Second row (first column) stem(ny,y,'r.'); %Draw a discrete image and set the line to r((red) dot Linetype axis([-1,k*N,0,5]); %Define the horizontal axis and vertical axis range of image 2 title('Periodic sequence'); %Description of the image theme xlabel('ny'); %Describe the horizontal axis ylabel('y'); %Describe the longitudinal axis grid on; %Open image grid

2. Experimental results

(3) Experiment 3: we know that the two sequences are x1(n)=[1,3,5,7,6,4,2,1], the starting position is ns1=-3, x2(n)=[4,0,2,1,-1,3], and the starting position is ns2=1. Find their sum ya and product yb.

1. Experimental code

%Sequential matlab realization x1=[1,3,5,7,6,4,2,1],ns1=-3; %given x1 And its starting point ns1 x2=[4,0,2,1,-1,3],ns2=1; %given x2 And its starting point ns2 nf1=ns1+length(x1)-1; %reach x1 End position of nf1 nf2=ns2+length(x2)-1; %reach x1 End position of nf1 n1=ns1:nf1,n2=ns2:nf2; %definition n1 and n2 Scope of n=min(ns1,ns2):max(nf1,nf2); %definition n Scope of y1=zeros(1,length(n)); %y The vector is initialized to zero y2=y1; %y1，y2 Initialization of sequence y1(find((n>=ns1)&(n<=nf1)==1))=x1; %to y1 assignment x1 y2(find((n>=ns2)&(n<=nf2)==1))=x2; %to y2 assignment x2 ya=y1+y2,yb=y1.*y2; %Addition and multiplication of sequences subplot(2,2,1),stem(n1,x1,'b.'),title('sequence x1(n)'),xlabel('n1'),ylabel('x1'),grid on; subplot(2,2,2),stem(n2,x2,'r.'),title('sequence x2(n)'),xlabel('n2'),ylabel('x2'),grid on; subplot(2,2,3),stem(n,ya,'m.'),title('sequence ya'),xlabel('n'),ylabel('ya'),grid on; subplot(2,2,4),stem(n,yb,'k.'),title('sequence yb'),xlabel('n'),ylabel('xb'),grid on;

2. Experimental results

# 6, Experimental harvest

Through this experiment, I have gained a lot. I mainly learned the method of generating the real part and imaginary part of complex exponential sequence, the sequence after extending the period, the method of the sum and product of the two sequences, as well as the usage of some related functions: real function, imag function, mod function, length function, find function, and some self-cultivation: my garbage must be taken away, Take good care of public facilities (computer, mouse, etc.), help each other with classmates and study modestly.

In short, as long as we are proactive, careful, patient, pay attention to integrating theory with practice, do more, learn more and ask more, we will make progress and learn more knowledge.