blob: b2bcfb7dcfec67e8fb1553c5c2b8ebebb893a875 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
FFT_Leakage_tests http://www.idea2ic.com/
*=========Create_Signal==================
VTime VTime 0 DC 0 PWL( 0 0 1 1)
Vfreq Vfreq 0 DC 5.5k
BVAC IN 0 V = sin( 6.283185307179586*V(VFreq)*V(VTime))
.control
*TRAN TSTEP TSTOP TSTART TMAX ?UIC?
tran 1u .999m 0 1u
set pensize = 2
linearize
let numb2 = length(in)
print numb2
*=========Do_FFT_and_Plot_As_dB_Freq==================
let ac = in +j(0)
let ac_fft=fft(ac)
let numb_f2 = (numb2)/2 -1
compose freq start = 1 stop = $&numb_f2 step =1
compose vreal start = 1 stop = $&numb_f2 step =1
compose vimag start = 1 stop = $&numb_f2 step =1
let j = 0
repeat $&numb_f2
let freq[j] = freq[j]
let vreal[j] = 2*real(ac_fft[j+1])
let vimag[j] = 2*imag(ac_fft[j+1])
let j = j +1
end
plot dB(abs(vreal+1f)) dB(abs(vimag+1f)) vs freq xlog
*=========Extract_Error_Signal=========================
let funBin = 5k/1000
let unvect = unitvec(numb2)
let fundspec = unvect*0 +j(0)
let fundspec[funBin] = real(ac_fft[funBin]) +j(imag(ac_fft[funBin] ))
let fundspec[numb2-funBin] = real(ac_fft[numb2-funBin]) +j(imag(ac_fft[numb2-funBin] ))
let fund = ifft(fundspec)
let dc_ofset = real(ac_fft[0])
let thdspec = ac_fft
let thdspec[0] = 0 +j(0)
let thdspec[funBin] = 0 +j(0)
let thdspec[numb2-funBin] = 0 +j(0)
let thd = ifft(thdspec)
plot norm(in) norm(fund) norm(thd)/2
*=========Calc_Values=========================
let rms_Fund = sqrt(mean(fund*fund))
let rms_THD = sqrt(mean(thd*thd))
let THD_percent = 100*rms_THD/rms_Fund
let FREQ_Hz = VFreq[0]
echo "Freq_Hz=$&FREQ_Hz THD_percent=$&THD_percent Fund_rms=$&rms_Fund THD_rms=$&rms_THD "
.endc
.end
|