Digital Signal Processing I: Representation and Operation of Discrete Time Signals

A discrete-time signal refers to a signal that is only defined at a discrete time, referred to as a discrete signal, or a sequence. Discrete sequences are usually denoted by x(n), and the arguments must be integers.
Waveform plotting of discrete-time signals uses the stem function in matplotlib.pyplot. Due to the limited number of matrix elements, it can only represent a sequence of finite length within a certain time range; and for an infinitely long sequence, it can only be represented within a certain time range.

1. Unit pulse train

The unit pulse sequence (n), also known as the unit sample 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 a definite value of 1 at n=0.

The program code example is as follows:

import numpy as np
import matplotlib.pyplot as plt
n0=0
n1=-12
n2=12
L=n2-n1+1
n=np.linspace(n1,n2,L)

a1 = np.zeros(L)#只有n=0时, a1=1;当n≠0时,a1=0
a1[n0-n1] = 1

plt.ylim(-0.1,1.2)
plt.xlim(-15,15)
plt.stem(n,a1)# 画棉棒
plt.title('δ(n)')
plt.grid('on')# 显示网格线

plt.show()

np.linspace(start, stop, num, endpoint, retstep, dtype)

star and stop are the start and end positions, both scalars
num is the total number of interval points including start and stop, the default is 50
endpoint is a bool value, when it is False, the last point will be removed to calculate the interval
rest is a bool value, and it is True The data list and the interval value will be returned at the same time.
The dtype defaults to the type of the input variable. After the type is given, the generated array type will be converted to the target type.

The program running result is shown in the figure below.
aaa

2. Unit step sequence u(n)

The unit step sequence u(n) is defined as
aaaa

The program code example is as follows:

import numpy as np
import matplotlib.pyplot as plt
n0=0
n1=-10
n2=15
L=n2-n1+1
n=np.linspace(n1,n2,L)
a2 = np.zeros(n2-n1+1)
a2[(n0-n1):] = 1# 只有n>=0时, x=1;当n<0时,x=0
plt.ylim(-0.1,1.2)

plt.xlim(-12,18)
plt.stem(n,a2)
plt.title('u(n)')
plt.grid('on')
plt.show()

The program running result is shown in the figure below.
aaa

3. Rectangular sequence RN(n)

The rectangular sequence RN (n) is defined as
aaaaaaa

The rectangular sequence has an important parameter, which is the sequence width N. The relationship between R (n) N and u(n) is:
insert image description here aaa

The program code example is as follows:

import numpy as np
import matplotlib.pyplot as plt

n0=0
n1=-5
n2=10
N=5
L=n2-n1+1

n=np.linspace(n1,n2,L)
a3 = np.zeros(L)
a3[(n0-n1):(n0-n1+N)] = 1
plt.ylim(-0.1,1.2)
plt.stem(n,a3)
plt.title('R5(n)')
plt.grid('on')
plt.show()

The program running result is shown in the figure below.
acd

4. Unilateral index series

A one-sided index series is defined as
acccc

The value range of the one-sided index sequence n is n  0 .
[Example 1-4] Draw unilateral index series respectivelyaccc
cddd

waveform diagram.
The program code example is as follows:

import numpy as np
import matplotlib.pyplot as plt

n0=0
n1=-5
n2=20
L=n2-n1+1

n=np.linspace(n1,n2,L)
un = np.zeros(n2-n1+1)
un[(n0-n1):] = 1

a1=1.2
a2=-1.2
a3=0.8
a4=-0.8
x1=(a1**n)*un
x2=(a2**n)*un
x3=(a3**n)*un
x4=(a4**n)*un
plt.figure('signal',figsize=(16,12))
plt.subplot(221)
plt.stem(n,x1)
plt.xlabel('n')
plt.ylabel('x(n)')
plt.title('(1.2)^n')
plt.grid('on')
plt.subplot(222)
plt.stem(n,x2)

plt.xlabel('n')
plt.ylabel('x(n)')
plt.title('(-1.2)^n')
plt.grid('on')
plt.subplot(223)
plt.stem(n,x3)
plt.xlabel('n')
plt.ylabel('x(n)')
plt.title('(0.8)^n')
plt.grid('on')
plt.subplot(224)
plt.stem(n,x4)
plt.xlabel('n')
plt.ylabel('x(n)')
plt.title('(-0.8)^n')
plt.grid('on')
plt.show()

The program running result is shown in the figure below.
accc

It can be seen from the figure that when |a|>1, the unilateral index sequence diverges; when |a|<1, the sequence converges. When a > 0, the sequence takes positive values; when a < 0, the sequence value swings positive and negative.

5. Sine sequence

A sine sequence is defined as
acccc

acccccc

The program code example is as follows:

import numpy as np
import matplotlib.pyplot as plt

n0=0
n1=-30
n2=30
L=n2-n1+1
PI=np.pi
w=1/6

n=np.linspace(n1,n2,L)
x=np.sin(w*PI*n)
plt.stem(n,x)
plt.ylim(-1.1,1.1)
plt.xlim(-30,30)
plt.xlabel('Time')
plt.ylabel('Amplitude')
plt.title('sin(πn/6)')
plt.grid('on')
plt.show()

The program running result is shown in the figure below.
accc

6. Complex exponential sequence

A complex exponential sequence is defined as
avf
avvfff

Draw accccthe curves of the real part, imaginary part, modulus and phase angle of the complex exponential sequence changing with time, and observe its time-domain characteristics. The program code example is as follows:

import numpy as np
import matplotlib.pyplot as plt

n1=0
n2=30
L=n2-n1+1
n=np.linspace(n1,n2,L)
A=2
a=-1/10
PI=np.pi
b=PI*1/6
c=complex(a,b)
x=A*np.exp(c*n)

plt.figure('signal',figsize=(12,10))
plt.subplot(2,2,1)
plt.stem(n,x.real)
plt.title('Re[x]')
plt.grid('on')
plt.subplot(2,2,2)
plt.stem(n,x.imag)
plt.title('Im[x]')
plt.grid('on')
plt.subplot(2,2,3)
plt.stem(n,np.abs(x))
plt.title('|x|')
plt.grid('on')
plt.subplot(2,2,4)
plt.stem(n,np.angle(x))
plt.title('arg[x]')
plt.grid('on')
plt.show()

The program running result is shown in the figure below.
aaccc

Daily "big pie":
every fall is to stand up magnificently

Guess you like

Origin blog.csdn.net/weixin_52051554/article/details/127840741