1. Overview of Signal Transformation
Signal is the most basic and important concept in the field of digital signal processing. Digital signal conversion technology is one of the most basic and effective ways to process and operate signals. Therefore, digital signal conversion technology has become one of the most basic skills that professionals in the field of digital signal processing must master.
To put it simply, digital signal conversion technology is a method of mapping a signal in one domain to a signal in another domain through mathematical transformation for the convenience and possibility of processing and operation. Commonly used digital signal transformation mainly includes: Fourier transform (DTFT), discrete Fourier transform (DFT), Z transform (ZT) and so on. These transformations all have their own theories and application backgrounds.
Two, Fourier transform
Fourier transform is an important tool for signal analysis and processing. As a kind of discrete signal, finite-length sequences occupy an extremely important position in digital signal processing. For finite length sequences, discrete Fourier transform not only has important significance in theory, but also has a fast calculation method - fast Fourier transform. Therefore, it plays a more and more important role in various digital signal processing calculation methods.
2.1 Several forms of Fourier transform
1) Fourier transform of non-periodic continuous-time signal
The Fourier transform of a non-periodic continuous-time signal x(t) can be expressed as:
The inverse transform is:
here, is the analog angular frequency. It can be seen that a continuous function in the time domain results in an aperiodic spectrum in the frequency domain, and aperiodicity in the time domain results in a continuous spectrum in the frequency domain.
Conclusion: The aperiodic continuous time function corresponds to an aperiodic continuous frequency domain transform function.
2) Fourier transform of periodic continuous time signal
The Fourier transform of a periodic continuous-time signal x(t) with period T is a discrete frequency domain function, which can be expressed as
inverse transform to
This is the form of the transformation that is often referred to as the Fourier series. Here, too, the angular frequency is simulated. It can be seen that the continuous function in the time domain results in an aperiodic spectrum in the frequency domain, and the discretization of the frequency domain function results in the periodicity of the time domain function.
Conclusion: The periodic continuous time function corresponds to an aperiodic discrete frequency domain transform function.
3) Fourier transform of non-periodic discrete-time signal
The Fourier transform of a non-periodic discrete-time signal x(n) can be expressed as:
Inverse transforms to:
Here, w is the digital frequency, and its relationship with the analog angular frequency is . It can be seen that the sampling in the time domain corresponds to the periodic extension in the frequency domain, and the aperiodicity of the time domain function results in a discrete spectrum in the frequency domain.
Conclusion: The non-periodic discrete-time function corresponds to a periodic continuous frequency-domain transform function.
4) Fourier transform of periodic discrete-time signal
The Fourier transform of a periodic discrete-time signal - the discrete Fourier series, can be expressed as:
Inverse transforms to:
It can be seen that the sampling in the time domain corresponds to the periodic extension in the frequency domain, and the periodicity of the time domain function results in a discrete spectrum in the frequency domain.
Conclusion: The periodic discrete time function corresponds to a periodic discrete frequency domain transform function.
2.2 Discrete Fourier Transform (DFT)
Discrete Fourier series is a periodic sequence, which is still not convenient for computer calculation. However, although the discrete Fourier series is a periodic sequence, it has only N independent values, so many of its characteristics can be obtained by continuation of finite-length sequences. For a finite length sequence x(n) of length N, that is, x(n) only has non-zero values at n=0~(N-1) points, and the rest of the values are all zero, that is
The sequence x(n) is periodically extended with N as the period to obtain a periodic sequence, then we have
Therefore, the discrete Fourier transform (DFT) of the finite length sequence x(n) is
inverse transform to
2.3 Fast Fourier Transform (FFT)
In signal processing, the calculation of DFT plays a decisive role, and the correlation, filtering, and spectrum estimation of signals must be realized through DFT. However, when N is very large, it is necessary to complete N complex number multiplications and N (N-1) complex number additions to obtain an N-point DFT, and the calculation amount is quite large. In 1965, JW Cooley and JW Tukey cleverly used the periodicity and symmetry of factors to construct a fast DFT algorithm, namely the concept of Fast Fourier Transform (FFT).
Fast Fourier transform is not another transform different from DFT, but a fast and effective algorithm to reduce the number of DFT calculations. This fast algorithm mainly uses the periodicity, symmetry and reducibility of , and continuously decomposes the long sequence DFT into several short sequence DFTs, thereby reducing the number of operations. The simplest and most commonly used algorithm is the radix-2FFT.
The base 2FFT algorithm is divided into two categories, that is, by time extraction (Decimation-In-Time, referred to as DIT-FFT) method and by frequency extraction (Decimation-In-Frequency, referred to as DIF-FFT) method.
In order to calculate the fast Fourier transform of data, a series of rich mathematical functions are provided in the fft module of the numpy library, mainly including fft, ifft, fft2, ifft2 and fftshift, ifftshift, etc. When the length of the processed data is a power of 2, the calculation speed will be significantly increased by using the radix-2 algorithm for calculation. Therefore, try to make the length of the data to be processed a power of 2 or fill it with zeros to make it a power of 2.
3. Analysis of Frequency Response Characteristics of Discrete Time LTI System
For a causally stable discrete-time system, the frequency response of the system is defined as:
Among them, it is called the amplitude-frequency characteristic of the discrete-time system; it is called the phase-frequency characteristic of the discrete-time system; it is a periodic function with a period of 2π. Therefore, as long as the situation within the range , the entire frequency characteristics of the system can be analyzed.
In the signal module of the scipy library, a function dfreqresp for calculating the frequency response characteristics of a discrete-time system is provided.
Statement format:
w, H = signal.dfreqresp(sys,whole=False)
where the return value w includes N frequency equal division points within the range ;
the return value H is the value at N frequencies within the frequency response range . Another calling format of this function is:
w, H = signal.dfreqresp(sys,whole=True)
The difference from the first method is that the range of the angular frequency is extended from to .
The parameter sys used in the function call represents the system, which can be realized by the function signal.TransferFunction in the scipy library.
The statement format is:
sys = signal.TransferFunction(b, a, dt)
where b and a respectively represent the coefficient vectors of the numerator and denominator polynomials (arranged according to the positive power of z, and the last item is a constant item). dt is the sampling time.
Draw the frequency response curve of .
The program code example is as follows:
from scipy import signal
import matplotlib.pyplot as plt
import numpy as np
b=[1,-0.96,0.9028]
a=[1,-1.56,0.8109]
sys = signal.TransferFunction(b, a,dt=0.05)
w, H = signal.dfreqresp(sys,whole=True)
plt.figure(figsize=(15,15))
plt.subplot(211)
plt.plot(w, np.abs(H), "b")
plt.xlabel('ω(rad/s)')
plt.ylabel('Magnitude')
plt.title('|H(e^jw)|')
plt.grid('on')
plt.subplot(212)
plt.plot(w, np.angle(H), "r")
plt.xlabel('ω(rad/s)')
plt.ylabel('Phase')
plt.title('φ(w)')
plt.grid('on')
plt.show()
The result of running the program is as follows:
.
It is known that the amplitude-frequency characteristic and phase-frequency characteristic curves of the system are drawn. The program code example is as follows:
from scipy import signal
import matplotlib.pyplot as plt
import numpy as np
b=[1,0,0,0,0,0,0,0,-1]
a=[1,0,0,0,0,0,0,0,0]
sys = signal.TransferFunction(b,a,dt=0.05)
w, H = signal.dfreqresp(sys,whole=True)
plt.figure(figsize=(12,12))
plt.subplot(211)
plt.plot(w, np.abs(H), "b")
plt.xlabel('ω(rad/s)')
plt.ylabel('Magnitude')
plt.title('|H(e^jw)|')
plt.grid('on')
plt.subplot(212)
plt.plot(w, np.angle(H), "r")
plt.xlabel('ω(rad/s)')
plt.ylabel('Phase')
plt.title('φ(w)')
plt.grid('on')
plt.show()
The result of the program running is shown in the figure below.
Applying the functions learned in DSP 3, we can draw the zero-pole distribution graph of this system function, as follows.
It can be seen from the figure that the system has 8 zeros, which are evenly distributed on the unit circle, and there is an 8th-order pole at the origin. This system is called a comb filter.
It is known that its Fourier transform is , plot its magnitude spectrum and phase spectrum.
The program code example is as follows:
from scipy import signal
import matplotlib.pyplot as plt
import numpy as np
b=[1,0,0,0,-1]
a=[1,-1,0,0,0]
sys = signal.TransferFunction(b,a,dt=0.05)
w, H = signal.dfreqresp(sys,whole=True)
plt.figure(figsize=(10,10))
plt.subplot(211)
plt.plot(w, np.abs(H), "b")
plt.xlabel('ω(rad/s)')
plt.ylabel('Magnitude')
plt.title('|X(e^jw)|')
plt.grid('on')
plt.subplot(212)
plt.plot(w, np.angle(H), "r")
plt.xlabel('ω(rad/s)')
plt.ylabel('Phase')
plt.title('arg[X(e^jw)]')
plt.grid('on')
plt.show()
The program running result is shown in the figure below.
In the same way, we can get the magnitude spectrum and phase spectrum of R5(n) and R6(n), as shown in the figure below.
4. Calculation of DFT
To do N-point DFT (N>=M) on a finite sequence of length M, you can directly call the functions fft and ifft in the fft module in the numpy library. If N is equal to the integer power of 2, you can use the FFT fast algorithm to calculate.
The function used to calculate the DFT forward transformation is fft, and the calling format is as follows: np.fft.fft(x), where x is a sequence in the time domain. The function used to find the inverse DFT transform is ifft, and the calling format is as follows: np.fft.ifft(X), where X is the spectrum value in the frequency domain.
Given that , find the 4-point and 8-point DFT of (n), and draw the magnitude spectrum.
The program code example is as follows:
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.font_manager import FontProperties
font_set = FontProperties(fname=r"c:\windows\fonts\simsun.ttc", size=12)
N=4 # DFT的长度
x=[1,1,1,1]
N1=len(x) # 序列x(n)的原始长度
xn=np.zeros(N)
xn[0:N1]=x # 通过补零,使得x(n)的长度等于N
XK = np.fft.fft(xn) # 计算FFT
print('X(k)=',XK) # 打印DFT的结果
n=np.arange(N)
k=np.arange(N)
plt.figure(figsize=(12,12))
plt.subplot(211)
plt.stem(n,xn, "r")
plt.xlabel('n')
plt.ylabel('x(n)')
plt.title('R4(n)')
plt.grid('on')
plt.subplot(212)
plt.stem(k,np.abs(XK))
plt.xlabel('k')
plt.ylabel('|X(k)|')
plt.title('4点DFT结果|X(k)|',fontproperties=font_set)
plt.grid('on')
plt.show()
The program running result is shown in the figure below.
Change the value of N in the program to 8, and the result of 8-point DFT can be obtained, as shown in the figure below.
If the L-point DFT of x(n) is required, just change the value of N in the program to the corresponding value.
Given that , find the 6-point DFT result X(k) of x(n).
The program code example is as follows:
import numpy as np
xn=[2,1,5,4,5,1]
XK = np.fft.fft(xn) #计算6点DFT
print(XK)
The program running result is: [18.+0.j -6.+0.j 0.+0.j 6.+0.j 0.+0.j -6.+0.j]
It can be seen from the results that
in this example, since it is a sequence of real numbers and satisfies even symmetry, X(k) is also a real number and even symmetric.
Known, find the 6-point IDFT result of X(k).
The program code example is as follows:
import numpy as np
XK=[18,-6,0,6,0,-6]
xn = np.fft.ifft(XK) #计算6点IDFT
print(xn)
The program running result is: [2.+0.j 1.+0.j 5.+0.j 4.+0.j 5.+0.j 1.+0.j]
It can be seen from the results that , is consistent with the result of the previous question.
In the above example, the spectrum we obtained is symmetrical about N/2 points. In order to move the DC
component middle of the spectrum, the function np. fft.fftshift, the calling format is: np.fft.fftshift(XK).
For the shifted spectrum, the spectrum must be shifted back before doing the inverse Fourier transform back to the time domain. The function used is np.fft.ifftshift, and the calling format is: np.fft.ifftshift(XK) .
Known , find the 6-point DFT result X(k) of x(n), and move the DC component in the frequency domain to the middle of the frequency spectrum.
The program code example is as follows:
import numpy as np
xn=[2,1,5,4,5,1]
XK = np.fft.fft(xn) #计算6点DFT
XK_shift=np.fft.fftshift(XK)
print(XK)
print(XK_shift)
The program running result is:
[18.+0.j -6.+0.j 0.+0.j 6.+0.j 0.+0.j -6.+0.j]
[ 6.+0 .j 0.+0.j -6.+0.j 18.+0.j -6.+0.j 0.+0.j]
5. The relationship between DFT and DTFT
The N-point DFT of x(n) is equal-spaced sampling of N-points on the interval [0, 2π]. Let's verify it with an example.
It is known that its Fourier transform is to draw the magnitude spectrum of its DTFT and the magnitude spectrum of the N-point DFT. (N is 8, 16, 32, 64, 128 respectively)
When N=8, the program code example is as follows:
from scipy import signal
import matplotlib.pyplot as plt
import numpy as np
b=[1,0,0,0,-1]
a=[1,-1,0,0,0]
sys = signal.TransferFunction(b,a,dt=0.05)
w, H = signal.dfreqresp(sys,whole=True)
N=8 # DFT的长度
x1=[1,1,1,1]
N1=len(x1)
x=np.zeros(N)
x[0:N1]=x1
n1=np.arange(N)
n=(2*np.pi)/N
k=n*n1
XK = np.fft.fft(x) #计算FFT
plt.figure(figsize=(8,4))
plt.plot(w, np.abs(H), "r")
plt.xlabel('ω(rad/s), k')
plt.ylabel('Magnitude')
plt.title('|X(e^jw)|, |X(k)|')
plt.grid('on')
plt.stem(k,np.abs(XK))
plt.show()
The program running result is shown in the figure below.
When N takes 16, 32, 64, and 128 respectively, the result is shown in the figure below.