How to match FFT results from Matlab and LTSpice
5 views (last 30 days)
Show older comments
Hello!
I want to create a FFT in LTSpice and in Matlab for a sinus with an amplitude of 1 and an frequency of 1kHz and my goal is to get the same output from both programs. Here is the build in LTSpice with the voltage plot:

In LTSpice i set the maximum timestep to 100n and also added the options numdgt & plotwinsize to disable the compression. With that and the settings in LTSpice for "Number of data point samples in time: 16777216" and "Binominal Smoothing done before FFT and windowing -> Number of Points = 1" I get the following FFT plot:

In Matlab itself I used the following code to generate a sine wave with 1kHz.
%%Time specifications
Fs = 70000; % samples per second
dt = 1/Fs; % seconds per sample
StopTime = 0.1; % seconds
zeit_matlab = (0:dt:StopTime-dt)'; % seconds
%%Sinus wave
Fc = 1000; %frequency
x = sin(2*pi*Fc*zeit_matlab);
% Plot the signal versus time:
figure;
plot(zeit_matlab,x);
figure;
To be honest I dont really have experience performing a FFT and for that I used the following code from (https://dadorran.wordpress.com/2014/02/20/plotting-frequency-spectrum-using-matlab/#9):
signal = x;
N = length(signal);
fs = 70000; % samples per second
fnyquist = fs/2; %Nyquist frequency
X_mags = abs(fft(signal));
bin_vals = [0 : N-1];
fax_Hz = bin_vals*fs/N;
N_2 = ceil(N/2);
plot(fax_Hz(1:N_2), 10*log10(X_mags(1:N_2)))
xlabel('Frequency (Hz)')
ylabel('Magnitude (dB)');
title('Single-sided Magnitude spectrum (Hertz)');
axis tight
The plot which I get from Matlab is the following with the peak at 1kHz:

And now my question is how can I match them, because when we look at the y-axis the have there different values. I hope this makes sense to someone =)
Best Regards!
0 Comments
Answers (0)
See Also
Categories
Find more on Spectral Measurements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!