Digital signal processing experiment 2: time domain sampling and frequency domain sampling

Experimental content

Experimental purpose

Time domain sampling theory and frequency domain sampling theory are important theories in digital signal processing. It is required to master the changes in the spectrum of analog signals before and after sampling, and how to choose the sampling frequency so that the sampled signal does not lose information; it is required to master the concept that frequency domain sampling will cause time domain periodization, as well as the frequency domain sampling theorem and its application to frequency domain sampling. Point selection guide.

Experimental principles and methods

The key points of the time domain sampling theorem are:
(1) For analog signalsx_{a}(t)Perform equal-spaced ideal sampling in the time domain at intervals T, resulting in the spectrum of the sampled signal \hat{X}(j\Omega )is the spectrum of the original analog signalX_{ a}(j\Omega ) With sampling angular frequency \Omega_{s}(\Omega_{s} = 2 \pi/T )Period continuation for the cycle. The formula is:

\hat{X}_{a}(j\Omega )=FT[\hat{x}(t)]=\frac{1}{T}\sum_{n =-\infty }^{\infty }X_{a}(j\Omega -jn\Omega _{s})

Sampling frequency\Omega _{s}Must be greater than or equal to twice the highest frequency of the analog signal so that the spectrum of the sampled signal does not produce spectrum aliasing.
It is not convenient to use a computer to calculate the above formula. Below we derive another formula to facilitate experiments on a computer.
Ideal sampled signal\hat{x}_{a}(t)and analog signalx_{a}(t) is:

\hat{x}_{a}(t)=x_{a}\sum_{n=-\infty }^{\infty}\delta (t-nT)\

Perform Fourier transform on the above equation to get:

\hat{X}_{a}(j\Omega )=\int_{-\infty}^{\infty}[x_{a}(t)\sum_{ n=\infty}^{\infty}\delta(t-nT)]e^{-j\Omega t}dt

=\sum_{n=-\infty}^{\infty}\int_{-\infty}^{\infty}x_{a}(t)\delta( t-nT)e^{-j\Omega}dt

In the integral sign of the above formula, there is a non-zero value only when t=nT, therefore:

\hat{X}_{a}(j\Omega)=\sum_{n=-\infty}^{\infty}x_{a}(nT)e^{ -j\Omega nT}

In the above formula, numerically x_{a}(nT)=x(n), then \omega=\Omega T to get:

\hat{X}_{a}(j\Omega)=\sum_{n=-\infty}^{\infty}x(n)e^{-j\ \omega n}

The right side of the above formula is the Fourier transform of the sequence X(e^{j\omega}), that is

\hat{X}_{a}(j\Omega)=X(e^{j\omega}) \mid _{\omega=\Omega T}

The above formula shows that the Fourier transform of the ideal sampling signal can be obtained by the Fourier transform of the corresponding sampling sequence, as long as the independent variable \omegaUse \OmegaJust replace it.
The key points of the frequency domain sampling theorem are:
Spectral function of signal x(n)X(e^{j\omega})Sampling N points at equal intervals on [0, 2π], we get

X_{N}(k)=X(e^{j\omega})\mid _{\omega=\frac{2\pi}{N}} k=0 ,1,2,...,N-1
Then N pointIDFT[X_{N}(k)]The obtained sequence is the main value area sequence after periodic extension of the original sequence x(n) with N as the period.

The formula is:

X_{N}(n)=IDFT[X_{N}(k))]_{N} = [\sum_{i=\infty}^{\infty}x(n + iN)]R_{N}(n)

It can be seen from the above formula that the number of sampling points N in the frequency domain must be greater than or equal to the length M of the discrete signal in the time domain (that is, N≥M), so that aliasing does not occur in the time domain, then point NIDFT[X_{N }(k)]]obtained Sequencex_{N}(n)It is the original sequence x(n), that is, X_{n}(n)=x(n). If N>M, x_{N}(n)N-M more zero points than the tail of the original sequence; if NTime domain occurred Aliasing distortion, andx_{N}(n) is also shorter than the length M of x(n). Therefore, x_{N}(n)is not the same as x(n).

In the application of digital signal processing, as long as time domain or frequency domain sampling is involved, the key points of these two sampling theories must be obeyed.

Comparing the time domain sampling principle and the frequency domain sampling principle described above, a useful conclusion is drawn. These two sampling theories have duality: “time domain sampling spectrum period extension, frequency domain sampling time domain signal period extension”. So put them together for experiments.

Experimental content and steps

Verification of time domain sampling theory. Given analog signal

x_{a}=Ae^{-at}sin(\Omega_{0}t)u(t)

In the formula, A=444.128, \alpha = 50\sqrt{2}\pi, \Omega_{0}=50\sqrt{2}\pi Its amplitude-frequency characteristics The curve is as shown in the figure

x_{a}(t)Amplitude-frequency characteristic curve

Now use DFT (FFT) to find the amplitude-frequency characteristics of the analog signal to verify the time domain sampling theory.

Follow x_{a}(t)‘s amplitude-frequency characteristic curve, select three sampling frequencies, namely F_{s}?=1kHz, 300Hz, 200Hz. Select the observation time T_{p}? =50ms.

To use DFT, first use the following formula to generate a time domain discrete signal. For three sampling frequencies, the sampling sequence is in order: x_{1}(n), x_{2}(n), x_{3 }(n)means.

x(n)=x_{a}(nT)=Ae^{-\alpha nT}sin(\Omega_{0}nT)u(nT)

Because the sampling frequencies are different, the obtainedx_{1}(n), x_{2}(n), x_{3}(n)are different lengths, and the length (number of points) is FormulaN=Y_{p}\times F_{s}Calculation. Select the number of transformation points of FFT as M=64, and add zero to the tail if the sequence length is less than 64.

X(k)=FFT[x(n)], k=0,1,2,...,M-1

In the formula, the frequency represented by k is \omega_{k}=\frac{2\pi}{M}k.

Requirements: Write experimental programs and calculate x_{1}(n), x_{2}(n), x_{3}(n)amplitude properties and plotted. Observe and analyze spectral aliasing distortion.

Verification of frequency domain sampling theory. The given signal is as follows:

Write a program to analyze the spectrum functions respectively X(e^{j\omega})=FT[x(n)]andX_{16}(k)

X_{32}(k)=X(e^{j\omega})\mid_{\omega}=\frac{2\pi}{32}k,k= 0,1,2,...,31

X_{16}(k)=X(e^{j\omega})\mid_{\omega}=\frac{2\pi}{16}k,k= 0,1,2,...,15

Then perform 32-point and 16-point IFFT on and respectively, and get x_{32}(k)andx_{16}(k)

x_{32}(n)=IFFT[X_{32}(k)]_{32},n=0,1,2,...,31

x_{16}(n)=IFFT[X_{16}(k)]_{16},n=0,1,2,...,15

Draw each X(e^{j\omega})X_{32}(k)andX_{16}(k)amplitude spectrum, and plot to display x(n), mathcode” src=”//i2.wp.com/latex.csdn.net/eq?x_{32}(k)”>andx_{16}(k)waveforms are compared and analyzed to verify and summarize the frequency domain sampling theory. .

Tips: Frequency domain sampling can be easily implemented in a program using the following method.

Directly call the MATLAB function fft to calculate X_{32}(k)=FFT[x(n)]_{32}You will get )at [ 0 , 2 π ]’s 32-point frequency domain samplingX_{32}(k).

ExtractX_{32}(k)You can get even pointsX(e^{j\omega})Sampling in the 16-point frequency domain of [0,2π]X_{16}(k), that isX_{16}(k)=X_ {32}(2k),k=0,1,2,..,15.

Of course, you can also follow the frequency domain sampling theory, first extend the signal x(n) with a period of 16, take its main value area (16 points), and then perform a 16-point DFT (FFT) on it, and the result is < img alt="X(e^{j\omega})" class="mathcode" src="//i2.wp.com/latex.csdn.net/eq?X(e^{ j\omega})">Sampling in the 16-point frequency domain of [0,2π]X_{16}(k).

Experimental Procedure

% "Digital Signal Processing (4th Edition)" Chapter 10 Experiment 2 Program exp2b.m
% Published by Xi'an University of Electronic Science and Technology Press, co-authored by Gao Xiquan and Ding Yumei, 2016
% Frequency domain sampling theory verification
M=27;N=32;n=0:M;
%Generate M long triangle wave sequence x(n)
xa=0:floor(M/2); xb= ceil(M/2)-1:-1:0; xn=[xa,xb];
Xk=fft(xn,1024); 24-point FFT[x(n)], used to approximate the TF of the sequence x(n)
X32k=fft(xn,32);2-point FFT[x(n)]
x32n=ifft(X32k); 2 points IFFT[X32(k)] gets x32(n)
X16k=X32k(1:2:N);% extract X32k at every other point to get X16(K)
x16n=ifft(X16k,N/2); Click IFFT[X16(k)] to get x16(n)
subplot(3,2,2);stem(n,xn,'.');box on
title('(b) triangle wave sequence x(n)');xlabel('n');ylabel('x(n)');axis([0,32,0,20])
k=0:1023;wk=2*k/1024;
subplot(3,2,1);plot(wk,abs(Xk));title('(a)FT[x(n)]');
xlabel('\omega/\pi');ylabel('|X(e^j^\omega)|');axis([0,1,0,200])
k=0:N/2-1;
subplot(3,2,3);stem(k,abs(X16k),'.');box on
title('(c) 16-point frequency domain sampling');xlabel('k');ylabel('|X_1_6(k)|');axis([0,8,0,200])
n1=0:N/2-1;
subplot(3,2,4);stem(n1,x16n,'.');box on
title('(d) 16-point IDFT[X_1_6(k)]');xlabel('n');ylabel('x_1_6(n)');axis([0,32,0, 20])
k=0:N-1;
subplot(3,2,5);stem(k,abs(X32k),'.');box on
title('(e) 32-point frequency domain sampling');xlabel('k');ylabel('|X_3_2(k)|');axis([0,16,0,200])
n1=0:N-1;
subplot(3,2,6);stem(n1,x32n,'.');box on
title('(f) 32-point IDFT[X_3_2(k)]');xlabel('n');ylabel('x_3_2(n)');axis([0,32,0, 20])
% "Digital Signal Processing (4th Edition)" Chapter 10 Experiment 2 Program exp2a.m
% Published by Xi'an University of Electronic Science and Technology Press, co-authored by Gao Xiquan and Ding Yumei, 2016
% Time domain sampling theory verification
Tp=64/1000;
%Generate M long sampling sequence x(n)
% Fs=1000;T=1/Fs;
Fs=1000;T=1/Fs;
M=Tp*Fs;n=0:M-1;
A=444.128;alph=pi*50*2^0.5;omega=pi*50*2^0.5;
xnt=A*exp(-alph*n*T).*sin(omega*n*T);
Xk=T*fft(xnt,M); %M point FFT[xnt)]
yn='xa(nT)';
subplot(3,2,1);tstem(xnt,yn);box on;title('(a) Fs=1000Hz');
k=0:M-1;fk=k/Tp;
subplot(3,2,2);plot(fk,abs(Xk));title('(a) T*FT[xa(nT)],Fs=1000Hz');
xlabel('f(Hz)');
ylabel('amplitude');axis([0,Fs,0,1.2*max(abs(Xk))])
% Fs=300;T=1/Fs;
Fs=300;T=1/Fs;
M=ceil(Tp*Fs);n=0:M-1;
xnt=A*exp(-alph*n*T).*sin(omega*n*T);
Xk=T*fft(xnt,M); %M point FFT[xnt)]
yn='xa(nT)';
subplot(3,2,3);tstem(xnt,yn);box on;title('(b) Fs=300Hz');
k=0:M-1;fk=k/Tp;
subplot(3,2,4);plot(fk,abs(Xk));title('(b) T*FT[xa(nT),Fs=300Hz');
xlabel('f(Hz)');ylabel('amplitude');axis([0,Fs,0,1.2*max(abs(Xk))])
% Fs=200;T=1/Fs;
Fs=200;T=1/Fs;
M=ceil(Tp*Fs);n=0:M-1;
xnt=A*exp(-alph*n*T).*sin(omega*n*T);
Xk=T*fft(xnt,M); %M point FFT[xnt)]
yn='xa(nT)';subplot(3,2,5);tstem(xnt,yn);box on;title('(c) Fs=200Hz');
k=0:M-1;fk=k/Tp;
subplot(3,2,6);plot(fk,abs(Xk));title('(c) T*FT[xa(nT),Fs=200Hz');
xlabel('f(Hz)');ylabel('amplitude');axis([0,Fs,0,1.2*max(abs(Xk))])
function tstem(xn,yn)
%Time domain sequence drawing function
% xn: signal data sequence, yn: ordinate name of the drawing signal (string)
n=0:length(xn)-1;
stem(n,xn,'.');
xlabel('n');ylabel(yn);
axis([0,n(end),min(xn),1.2*max(xn)])

Experimental results

Experimental result analysis and experimental summary

It can be seen from Figure 1 that the spectrum of the sampling sequence is indeed a periodic continuation of the spectrum of the analog signal with the sampling frequency as the period. When the sampling frequency is 1000Hz, the spectrum aliasing is very small; when the sampling frequency is 300Hz, the spectrum aliasing is serious near the folding frequency 150Hz; when the sampling frequency is 200Hz, the spectrum aliasing is even more serious near the folding frequency 110Hz.

Figure 2 verifies the frequency domain sampling theory and frequency domain sampling theorem. Spectral function of signal x(n)X(e^{j\omega})When sampling N=16 at equal intervals on [0,2π], N pointsIDFT[X_N(k)]\ The obtained sequence is exactly the original sequence x(n) starting from 16 is the main value area sequence after period extension:

X_{N}(n)=IDFT[X_{N}(k))]_{N} = [\sum_{i=\infty}^{\infty}x(n + iN)]R_{N}(n)

Since Nwith x(n ) are not the same, as shown in the figure. When N=32, as shown in the figure, due to N>M, frequency domain sampling theorem, there is no time domain aliasing distortion. Therefore, X_{N}(n)Same as x(n).