How can Fourier transform be implemented in Matlab?

In MATLAB, the fft function can be used to perform Fourier transformation. Here is an example code:

% 生成一个信号
Fs = 1000;      % 采样频率
t = 0:1/Fs:1;   % 时间序列
f1 = 50;        % 信号频率1
f2 = 120;       % 信号频率2
A1 = 1;         % 信号幅值1
A2 = 0.5;       % 信号幅值2
x = A1*sin(2*pi*f1*t) + A2*sin(2*pi*f2*t);

% 进行傅里叶变换
N = length(x);              % 信号长度
X = fft(x);                 % 傅里叶变换结果
f = (0:N-1)*(Fs/N);         % 频率坐标
power = abs(X).^2/N;        % 频谱功率

% 绘制频谱图
plot(f,power)
xlabel('Frequency (Hz)')
ylabel('Power')

The code first generates a signal composed of two superimposed sine waves. Then, the signal undergoes Fourier transformation using the fft function to obtain frequency spectrum information. Finally, the spectrum plot is created using the plot function.

bannerAds