Aly
02/02/2023, 10:49 AMclear all;
close all;
clc;
path = "D:\studies\SHA.raw";
[signals, signals_values] = parse_tran_ngspice(path);
time = signals_values(find(strcmp(signals, "time")),:);
y = signals_values(find(strcmp(signals, "v(hold)")),:);
plot(time,y);
N = length(y);
s = abs(fft(y,N))
%s=s(1:N/2);
f= (0:length(s)-1)/N;
sdb = 20*log10(s);
plot(f, sdb);
xlabel('Frequency [ f / f_s ]');
ylabel('Amplitude [ dBFS ]');
Manuel M
02/02/2023, 11:28 AMplot(y)
. Transient has no constant timestep and fft(y,N)
doesn't know about the time
vectorAly
02/02/2023, 11:29 AMAly
02/02/2023, 11:29 AMAly
02/02/2023, 11:30 AMManuel M
02/02/2023, 11:44 AMtime
does not have constant timesteps, if confirmed rebase y with interp1()Aly
02/02/2023, 11:49 AMManuel M
02/02/2023, 11:49 AMAly
02/02/2023, 11:49 AMAly
02/02/2023, 11:53 AMAly
02/02/2023, 11:53 AMKarimeldeen
02/02/2023, 12:08 PMAly
02/02/2023, 12:38 PMStefan Schippers
02/02/2023, 5:56 PMlinearize
command that transforms tran vectors to constant timestep: section in ngspice manual: 17.5.40 Linea`rize*: Interpolate to a linear scale.` This should be done before processing data for fft.Aly
02/02/2023, 9:56 PMAly
02/02/2023, 9:56 PMStefan Schippers
02/02/2023, 10:30 PMtran
command.
Example: in my simulation I have a vector generated with a tran 0.05u 1m
that is 25852
points long.
Applying the linearize command i get a 20001
points vector, which is exactly a vector running from 0 to 1m with 50ns increments.
Voltage values are interpolated if no exact X-value is present (I guess taking the point before and the point following and doing linear interpolation, but I have not checked that).Aly
02/02/2023, 10:51 PMy
values exist for the `x`(linearised) values will affect the spectrum assuming that the input signal is a sine wave. I wouldn’t say that it’ll be affected if the input is a ramp. Do you agree?Stefan Schippers
02/02/2023, 10:59 PMAly
02/02/2023, 11:04 PMStefan Schippers
02/02/2023, 11:10 PMStefan Schippers
02/02/2023, 11:13 PMtran tstep tstop tstart tmax
tstart
tells where to start saving in the raw file. (simulation will always start from zero but no data is stored).
tstop
is the end point
tmax
limits the maximum time step.Aly
02/02/2023, 11:52 PM