problem found
Recently, a problem was suddenly found in the simulated FFT transformation. The discrete Fourier transform of an ideal sinusoidal signal should be a single pulse spectrum, as shown in the figure below.
![](https://img-blog.csdnimg.cn/29e542349aa241ee935bdcda4f12bbac.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NjEwMTgzOQ==,size_16,color_FFFFFF,t_70)
As a result, the results of matlab's fft processing show that it does not seem to be true, and it presents a Lorentzian line type, as shown in the figure below.
![](https://img-blog.csdnimg.cn/d11cb3a9f5e1481ca7aeaa4da9a0cb9d.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80NjEwMTgzOQ==,size_16,color_FFFFFF,t_70)
DFT comparison written by myself
Especially under the condition that the signal frequency is an integer, the error is extraordinarily large.
It is also different when the signal frequency is a fraction. . . . Is it because my MATLAB is a cracked version?
The procedure is as follows, welcome to correct
clc;clear;
close all;
T = 1;
fs = 3e3;
len = fs*T;
t = linspace(0,T,len);
I = cos(2*pi*510*t); % 正弦信号
% MATLAB's FFT
real0 = 2*abs(fft(I))/len; % fft
freq0 = linspace(0,len-1,len);
% my DFT
real1 = zeros(1,len);
for m = 1:len
mid = mean(I.*exp(-2i*pi*(m-1)*t)); % 傅里叶变换的公式
real1(m) = 2*abs(mid);
end
freq1 = linspace(0,len-1,len);
figure,plot(freq1,10*log10(real1),'g',freq0,10*log10(real0),'k');
legend('DFT','FFT');
I asked a classmate to take a look and said that the coordinate base did not match, just change the time coordinate to the following code, the result is as follows, Niubility! !
t = linspace(0,T-1/fs,len);