Clear Filters
Clear Filters

frequency shift in fft from circuit simulator data

6 views (last 30 days)
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
AndresVar
AndresVar on 10 Mar 2022
Edited: AndresVar on 10 Mar 2022
strange, upload the data file.
what about pspectrum(RF,Fs), try without removing the distortion.
is Vout(:,1) the time? you can try psectrum(RF,times) just in case there was some missing samples.
Brian DeHority
Brian DeHority on 10 Mar 2022
Thanks for your quick response! I'm attaching the data file to this comment as a zip file as the original was too large.
I tried both of the pspectrum lines you put down and neither of them worked. The result of it is below, which is even further trom what it is supposed to be.
Any other ideas?

Sign in to comment.

Answers (1)

Neelanshu
Neelanshu 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

Products


Release

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!