Matlab FFT differs from theory and oscilloscope
9 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Alexander Engeln
am 12 Apr. 2021
Kommentiert: Alexander Engeln
am 14 Apr. 2021
Hello together,
I am currently trying to reproduce simple results from my oscilloscope-FFT. I generated a simple sine wave signal with 300 MHz Frequency and used a simple rectangular window: the voltage data u1 range in time from -10 Microseconds to 10 Microseconds.
Why does the Matlab FFT show the windowing effect and the integral and the oscilloscope not? I am kind of worried since I rather trust the oscilloscope than I trust the Matlab FFT... Have I forgot something essential?
I am running out of ideas and would be happy for some help. The code:
close all
clear
% Import Oscilloscope Data
modus = "sinus";
m = importdata("C1--" + modus + "--00000.dat");
time = m(1:end-1,1);
N = size(time,1);
u1 = m(1:end-1,2);
% Determine Frequencies
DeltaT = (time(size(time,1))-time(1))/(N-1);
Fs = 1/DeltaT;
df = Fs/(N-1);
f_four = (0:df:Fs/2)';
% Theoretical DFT
B1 = zeros(size(f_four,1),1);
for f=1:size(f_four,1)
disp(f)
B1(f) = 2*sum(u1.*exp(-1i*time*f_four(f)*2*pi)/N);
end
% Matlab FFT
Bh2 = fft(u1)/N;
Bh2 = fftshift(Bh2);
B2 = 2*Bh2((N+1)/2:end);
% Plot
f_compare = importdata("F1--" + modus + "-rechteck--00000.dat"); % Oscilloscope FFT
figure(1)
plot(f_four/1e06, 20*log10(abs(B1)), f_four/1e06, 20*log10(abs(B2)), f_compare(:,1)/1e06, 20*log10(f_compare(:,2)));
set(gca, 'FontSize', 14);
axis([250 350 -300 0]);
legend('Fourier Integral', 'Matlab-FFt', 'Oscilloscope', 'Location', 'southwest');
xlabel('$\textit{f}$ in MHz', 'Interpreter', 'Latex');
ylabel('dBV');
Thank you in advance!
4 Kommentare
Akzeptierte Antwort
Matt J
am 12 Apr. 2021
Is the oscilloscope computing the FFT, or is it trying to compute a continuous Fourier transform approximation? If the latter, it should differ from the FFT by a factor of DeltaT.
6 Kommentare
Matt J
am 14 Apr. 2021
Bearbeitet: Matt J
am 14 Apr. 2021
Maybe you can have a look whether I get it right?
Here is how I would set things up,
N=5;
T=10;
dT=T/(N-1) %time sampling interval
dF=1/dT/N %frequency sampling interval
NormalizedAxis= (0:N-1) -ceil((N-1)/2);
time_axis=NormalizedAxis*dT
frequency_axis=NormalizedAxis*dF
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Timing and presenting 2D and 3D stimuli finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!