frequency shift in fft from circuit simulator data
5 views (last 30 days)
Show older comments
Hello! I have run into an issue that seems trivial but I cant figure it out. So I am simulating a mixer in virtuoso using spectre (a circuit simulator). The output is a time-series data set that has voltages at equally spaced time points (Fs = 1MHz). When taking the fft within virtuoso, everything works. I get data points at exactly the right locations. The problem is that when I import the data to matlab and take the fft (using the example code from the website), the consequential frequencies are shifted by 100-200 Hz. I have put my code below:
The output from the circuit simulator is:
And the output of the matlab code is:
I am quite confident in the fft from virtuoso, but I will need to do more complicated functions in matlab soon, so I need to get the fft up and running. Mostly I am worried about that 500 Hz peak that has moved to 404 Hz. Any ideas on how to fix my code or any other insights?
%clear; close all; clc;
Vout = table2array(VIFoutmar9535);
%%
Fs = 1e6;
T = 1/Fs;
L = 2^17; %closest power of 2 below data length
RF = Vout(end-L:end,2); %removing some distortion at the beginning
Y = abs(fft(RF));
P2 = abs(Y/L);
P1 = P2(1:L/2+1);
P1(2:end-1) = 2*P1(2:end-1);
f = Fs*(0:(L/2))/L;
figure;
%subplot(2,1,1);
plot(f(1:100),P1(1:100))
title('FFT of Vout')
xlabel('f (Hz)')
ylabel('|P1(f)|')
title('FFT of Vin');
2 Comments
Answers (1)
nick
on 7 Feb 2024
Hi Andres,
I understand from your query that you are interested in finding out why the peak has shifted to 404 Hz in the FFT obtained using MATLAB.
Upon reviewing the data file you shared, it appears that there is inconsistent sampling. There are occasional instances where the time step size between two consecutive data points, which is effectively 1/sampling rate, goes down to 10^-14 seconds. This inconsistency can lead to errors in the FFT analysis. The following image illustrates the variation in time step size during sampling :
To ensure accurate frequency representation in the FFT, the sampling frequency (Fs) used in MATLAB must match the actual sampling rate used during the simulation. Any discrepancy between these values could result in a frequency scale mismatch, which might explain the unexpected shift in the peak frequency.
Hope this helps
0 Comments
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!