diff options
author | rahulp13 | 2020-02-28 11:38:58 +0530 |
---|---|---|
committer | rahulp13 | 2020-02-28 11:38:58 +0530 |
commit | 246319682f60293b132fca1ce6e24689c6682617 (patch) | |
tree | 6871b758a17869efecfd617f5513e31f9a933f4a /Windows/spice/examples/various/FFT_Leakage.cir | |
parent | d9ab84106cac311d953f344386fef1c1e2bca1cf (diff) | |
download | eSim-246319682f60293b132fca1ce6e24689c6682617.tar.gz eSim-246319682f60293b132fca1ce6e24689c6682617.tar.bz2 eSim-246319682f60293b132fca1ce6e24689c6682617.zip |
initial commit
Diffstat (limited to 'Windows/spice/examples/various/FFT_Leakage.cir')
-rw-r--r-- | Windows/spice/examples/various/FFT_Leakage.cir | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/Windows/spice/examples/various/FFT_Leakage.cir b/Windows/spice/examples/various/FFT_Leakage.cir new file mode 100644 index 00000000..b2bcfb7d --- /dev/null +++ b/Windows/spice/examples/various/FFT_Leakage.cir @@ -0,0 +1,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 |