"FFT analysis with Calcpad
#rad
'Sampling frequency -'Fs = 1024Hz
'Number of sampling points - 'N = 1024
'Time step -'Δt = 1/Fs
'Times of sampling points -'t = range_hp(0; N - 1; 1)*Δt
'Frequencies and amplitudes
f_1 = 10Hz','f_2 = 30Hz
X_1 = 20mm','X_2 = 20mm
t_0 = 0.5*N*Δt
f(t) = f_1*(t < t_0) + f_2*(t ≥ t_0)
X(t) = X_1*(t < t_0) + X_2*(t ≥ t_0)
'Input signal -'x(t) = X(t)*sin(2*π*f(t)*t)
x = hp([x(t)|0])
'Solution -'f = fft(x)
'Squared magnitude -'S = row(f; 1)^2 + row(f; 2)^2
'Power spectral density -'PSD = S/(N*Fs)
'Amplitude spectral density -'ASD = sqrt(PSD)
'<!--'PlotWidth = 600','PlotHeight = 150','PlotAdaptive = 0'-->
'Input signal plot
$Plot{line(i; row(x; 1)) & spline(i; row(x; 2)) @ i = 1 : N}
'Power spectral density plot
$Plot{spline(i; PSD) @ i = 1 : N/2}