使用MATLAB進行離散傅立葉變換及其逆變換


離散傅立葉變換和逆離散傅立葉變換是兩種用於在頻域分析函式和訊號的數學運算。DFT 和 IDFT 廣泛應用於數字訊號處理領域,用於合成和分析數字訊號。讓我們更詳細地討論一下離散傅立葉變換 (DFT) 和逆離散傅立葉變換 (IDFT)。

什麼是離散傅立葉變換 (DFT)?

在數學中,**離散傅立葉變換 (DFT)** 是一種轉換技術,用於將時間域中的一系列離散資料點轉換為頻域。

DFT 基本上將時間域中表示的一系列離散資料點轉換為頻域中表示的一系列複數。因此,離散傅立葉變換是一種數學技術,用於將數字訊號表示為不同頻率的正弦分量的總和。

計算時間域中序列的離散傅立葉變換的標準方程為:

$$\mathrm{X(k)=\displaystyle\sum\limits_{n=0}^{N−1} x(n).e^{−j^\frac{2{\pi}nk}{N}}}$$

其中,x(n) 是時間域中的輸入序列,X(k) 是頻域中的輸出序列,N 是輸入序列的長度。

現在,讓我們簡要概述一下逆離散傅立葉變換 (IDFT)。

什麼是逆離散傅立葉變換 (IDFT)?

**逆離散傅立葉變換 (IDFT)** 是一種數學運算,用於將頻域中表示的數字訊號轉換為時域。因此,逆離散傅立葉變換隻是離散傅立葉變換 (DFT) 的逆運算。

逆離散傅立葉變換主要用於從頻域訊號中恢復原始訊號。

在數學上,逆離散傅立葉變換是使用以下標準方程計算的:

$$\mathrm{X(n)=\frac{1}{N}\displaystyle\sum\limits_{k=0}^{N−1} x(k).e^{j^\frac{2{\pi}nk}{N}}}$$

因此,離散傅立葉變換 (DFT) 和逆離散傅立葉變換 (IDFT) 是兩種相關的數學運算,廣泛應用於工程和技術領域,用於訊號處理、影像處理、濾波、降噪以及執行許多其他任務。

現在,讓我們討論如何使用 MATLAB 計算離散傅立葉變換和逆離散傅立葉變換。

如何在 MATLAB 中找到離散傅立葉變換?

在 MATLAB 中,找到給定數字訊號的離散傅立葉變換 (DFT) 非常容易。我們可以使用 MATLAB 的內建函式“fft”來找到給定訊號的離散傅立葉變換。

下面解釋了查詢給定訊號的離散傅立葉變換 (DFT) 的分步過程:

  • **步驟 (1)** - 定義或建立或匯入輸入訊號。

  • **步驟 (2)** - 使用“fft”函式計算訊號的離散傅立葉變換。

  • **步驟 (3)** - 建立頻率軸以繪製幅度和相位譜。

  • **步驟 (4)** - 繪製 DFT 的幅度譜。

  • **步驟 (5)** - 繪製 DFT 的相位譜。

示例 (1)

現在,讓我們考慮一些示例,以使用 MATLAB 計算給定輸入訊號的離散傅立葉變換。

% MATLAB program to calculate the DFT of a signal
% Create a sample signal
fs = 500;	% Sampling frequency of the signal in Hz
T = 1/fs;	% Sampling period of the signal in seconds
N = 500;	% Length of the signal
t = (0:N-1)*T;	% Time vector
f = 50;		% Frequency of the input signal in Hz
x = cos(2*pi*f*t);	% A cosine signal wave

% Calculate the discrete Fourier transform of x
X = fft(x);

% Create a frequency axis
F = fs*(0:(N/2))/N;

% Plot the magnitude spectrum of DFT
MS = 2*abs(X(1:N/2 + 1))/N;  % Calculating the magnitude spectrum
figure;
plot(F, MS);
title('Magnitude Spectrum of DFT');
xlabel('Frequency (in Hz)');
ylabel('Magnitude');

% Plot the Phase Spectrum of DFT
PS = angle(X(1:N/2 + 1));	% Calculating the phase spectrum
figure;
plot(F, PS);
title('Phase Spectrum of DFT');
xlabel('Frequency (in Hz)');
ylabel('Phase');

輸出

(1). DFT 的幅度譜 -

(2). DFT 的相位譜 -

示例 (2)

讓我們考慮另一個示例程式,以計算隨機生成的輸入訊號的離散傅立葉變換。

% MATLAB program to calculate the DFT of a random sequence
% Create a random input sequence
N = 200;	% Length of the input sequence
x = randn(1, N); 

% Calculate the DFT of the sequence x
X = fft(x);

% Create the frequency
F = (0:N-1) / N;

% Plot the magnitude spectrum of the DFT
MS = abs(X);	% Calculating the magnitude spectrum
figure;
stem(F, MS);
title('Magnitude Spectrum of DFT');
xlabel('Frequency');
ylabel('Magnitude');

% Plot the phase spectrum of DFT
PS = angle(X);	% Calculating the phase spectrum
figure;
stem(F, PS);
title('Phase Spectrum of DFT');
xlabel('Frequency');
ylabel('Phase');

輸出

(1). DFT 的幅度譜 -

(2). DFT 的相位譜 -

現在讓我們探索如何使用 MATLAB 找到逆離散傅立葉變換 (IDFT)。

如何找到逆離散傅立葉變換?

在 MATLAB 中,有一個內建函式“ifft”,用於計算給定頻域序列的逆離散傅立葉變換。

計算頻域序列的逆離散傅立葉變換的分步過程如下所示:

  • **步驟 (1)** - 建立或匯入頻域中的序列。

  • **步驟 (2)** - 使用“ifft”函式計算逆離散傅立葉變換。

  • **步驟 (3)** - 繪製重建訊號的實部和虛部。

因此,使用 MATLAB 查詢逆離散傅立葉變換的過程是一個簡單的過程。

示例 (3)

現在,讓我們考慮一些示例,以瞭解如何計算給定頻域序列的逆離散傅立葉變換。

% MATLAB program to find the IDFT of a random sequence
% Create a sample random sequence in frequency domain 
N = 200;	% Length of the sequence
X = randn(1, N) + 1i * randn(1, N); % Random sequence in frequency domain

% Calculate the inverse discrete Fourier transform
x = ifft(X);	% Reconstructing the original sequence

% Creating a time axis
t = 0 : N-1;

% Plot the real part of the reconstructed sequence in time domain
subplot(2, 1, 1);
stem(t, real(x));	% Plotting the real part of sequence
title('Real Part of Reconstructed Signal');
xlabel('Time');
ylabel('Amplitude');

% Plot the imaginary part of the reconstructed sequence in time domain
subplot(2, 1, 2);
stem(t, imag(x));	% Plotting the imaginary part of sequence
title('Imaginary Part of Reconstructed Signal');
xlabel('Time');
ylabel('Amplitude');

輸出

結論

這就是關於離散傅立葉變換 (DFT) 和逆離散傅立葉變換 (IDFT) 以及使用 MATLAB 計算它們的所有內容。DFT 和 IDFT 是數字訊號處理中使用的強大數學工具。DFT 允許我們將時域序列轉換為頻域序列,而 IDFT 允許我們將頻域序列轉換為時域序列。

在 MATLAB 中,我們可以分別使用內建函式“fft”和“ifft”來執行 DFT 和 IDFT。總的來說,MATLAB 透過使用簡單的內建函式提供了一種查詢給定序列的 DFT 和 IDFT 的簡單方法。在本文的上述部分中,我們描述瞭如何使用 MATLAB 計算 DFT 和 IDFT。

更新於: 2023年9月6日

3K+ 瀏覽量

開啟您的 職業生涯

透過完成課程獲得認證

立即開始
廣告