Experiment 1 Basic operations of digital signal processing based on Matlab
Experiment 1 Basic operations of digital signal processing based on Matlab
Experimental purpose: Learn to use commonly used discrete time signals represented by MATLAB; learn to use MATLAB to implement basic operations of discrete time signals.
Experimental instruments: one computer, one set of MATLAB 6.5 or higher software.
Experimental content:
Representation of discrete time signals in MATLAB
Discrete time signals refer to signals that are defined at discrete moments, referred to as discrete signals, or sequences. Discrete sequences are usually used to represent that independent variables must be integers.
The waveform of discrete time signals is generally drawn in MATLAB using the stem function. The basic usage of the stem function is the same as the plot function. There is a small circle on each sample point of the waveform graph it draws, which is hollow by default. If you want to be solid, you need to use the parameters "fill", "filled", or the parameter ".". Since the number of matrix elements in MATLAB is limited, MATLAB can only represent sequences of finite lengths within a certain time range; and for infinite sequences, they can only be represented within a certain time range. Similar to continuous time signals, discrete time signals also have some typical discrete time signals.
Unit sampling sequence
Unit sampling sequence, also known as unit impulse sequence, is defined as
It should be noted that the unit impulse sequence is not a simple discrete sampling of the unit impulse function, it takes the definite value of 1 at n=0. In MATLAB, the impulse sequence can be implemented by writing the following file, i.e.
function y=impDT(n)
y=(n==0); % When the parameter is 0, impulse is 1, otherwise it is 0
When calling this function, n must be an integer or an integer vector.
[Example 1-1] Use the impDT function of MATLAB to draw the waveform diagram of the unit impulse sequence.
Solution: The MATLAB source program is
>>n=-3:3;
>>x=impDT(n);
>>stem(n,x,'fill'),xlabel('n'),grid on
>>title('Unit Impulse Sequence')
>>axis([-3 3 -0.1 1.1])
The program operation results are shown in Figure 1-1.
Unit step sequence
Unit step sequence is defined as
In MATLAB, the impulse sequence can be implemented by writing files, i.e.
function y=uDT(n)
y=n>=0; % outputs 1 when the parameter is non-negative
When calling this function, n must also be an integer or an integer vector.
[Example 1-2] Use the uDT function of MATLAB to draw a waveform diagram of a unit step sequence.
Solution: The MATLAB source program is
>>n=-3:5;
>>x=uDT(n);
>>stem(n,x,'fill'),xlabel('n'),grid on
>>title('Unit Step Sequence')
>>axis([-3 5 -0.1 1.1])
The program operation results are shown in Figure 1-2.
Rectangle sequence
The rectangular sequence is defined as
1
A rectangular sequence has an important parameter, which is the sequence width N. The relationship between
Therefore, the uDT function mentioned above can be used to represent a rectangular sequence using MATLAB.
[Example 1-3] Use the MATLAB command to draw a waveform diagram of a rectangular sequence.
Solution: The MATLAB source program is
>>n=-3:8;
>>x=uDT(n)-uDT(n-5);
>>stem(n,x,'fill'),xlabel('n'),grid on
>>title('Rectangle Sequence')
>>axis([-3 8 -0.1 1.1])
The program operation results are shown in Figure 1-3.
Unilateral index sequence
The unilateral index sequence is defined as
[Example 2-4] Try to draw the waveform graph of the unilateral exponential sequence, , and respectively.
Solution: The MATLAB source program is
>>n=0:10;
>>a1=1.2;a2=-1.2;a3=0.8;a4=-0.8;
>>x1=a1.^n;x2=a2.^n;x3=a3.^n;x4=a4.^n;
>>subplot(221)
>>stem(n,x1,'fill'),grid on
>>xlabel('n'),title('x(n)=1.2^{n}')
>>subplot(222)
>>stem(n,x2,'fill'),grid on
>>xlabel('n'),title('x(n)=(-1.2)^{n}')
>>subplot(223)
>>stem(n,x3,'fill'),grid on
>>xlabel('n'),title('x(n)=0.8^{n}')
>>subplot(224)
>>stem(n,x4,'fill'),grid on
>>xlabel('n'),title('x(n)=(-0.8)^{n}')
The value range of a unilateral exponential sequence is. The program operation results are shown in Figure 1-4. From the figure, we can see that at that time, the unilateral exponential sequence diverged; at that time, the sequence converged. At that time, both of the sequences were positive; at that time, the sequences were positive and negative.
Sine sequence
The sine sequence is defined as
in,