Diferencia entre revisiones de «Taller de distorsión»
Sin resumen de edición |
|||
| Línea 4: | Línea 4: | ||
=clip= | =clip= | ||
v1 es | v1 es una fuente voltaje independiente. Consulta el capítulo en el manual de Ngspice: | ||
* 4.1 Independent Sources for Voltage or Current | * 4.1 Independent Sources for Voltage or Current | ||
v1 tiene | v1 tiene una onda de voltaje sinusoidal. Los parámetros se explican aqui: | ||
* 4.1.2 Sinusoidal | * 4.1.2 Sinusoidal | ||
d1 es un diodo de modelo 1N4148, algo común. El diodo necesita un comando ".model" para especificar sus parámetros. Podés ponerlo en un archivo se llama 1n4148.lib y incluir ese archivo. El contenido del archivo debe ser esto: | d1 es un diodo de modelo 1N4148, algo común. El diodo (y varios otros componentes) necesita un comando ".model" para especificar sus parámetros. Podés ponerlo en un archivo se llama 1n4148.lib y incluir ese archivo. El contenido del archivo debe ser esto: | ||
<pre> | <pre> | ||
.model 1n4148 D(IS=2.5n N=1.9 BV=100 RS=1) | .model 1n4148 D(IS=2.5n N=1.9 BV=100 RS=1) | ||
Revisión del 14:50 30 ago 2026
Podemos usar Ngspice para simular la distorsión en circuitos.
Ten en cuenta si estás introduciendo un comando de shell o un comando de ngspice, y también si estás dando órdenes al shell o a ngspice. Para salir de ngspice, escribe "quit". Se recomienda colocar todos los archivos en un único directorio y utilizarlo para ejecutar la simulación.
clip
v1 es una fuente voltaje independiente. Consulta el capítulo en el manual de Ngspice:
- 4.1 Independent Sources for Voltage or Current
v1 tiene una onda de voltaje sinusoidal. Los parámetros se explican aqui:
- 4.1.2 Sinusoidal
d1 es un diodo de modelo 1N4148, algo común. El diodo (y varios otros componentes) necesita un comando ".model" para especificar sus parámetros. Podés ponerlo en un archivo se llama 1n4148.lib y incluir ese archivo. El contenido del archivo debe ser esto:
.model 1n4148 D(IS=2.5n N=1.9 BV=100 RS=1)
Archivo SPICE (clip.cir)
.title clip .include 1n4148.lib v1 sig 0 sin 0 3v 300 r1 sig out 1k d1 out 0 1n4148
comandos
- ngspice clip.cir (en el shell)
- tran 10us 3s (en ngspice)
- plot v(sig) v(out) xlimit 0 10m (en ngspice)
- plot v(sig) v(out)+1 xlimit 0 10m (en ngspice)
- plot v(sig) v(out) 1000*-1*v1#branch xlimit 0 10m (en ngspice)
amp 1
Archivo SPICE (amp1.cir)
.title amp1 .include TL072.mod x1 ninv inv cc ee out TL072 vcc cc 0 15 vee ee 0 -15 v1 sig 0 sin 0 3v 1 r1 sig inv 10k rfb out inv 10k rninv ninv 0 1 .control tran 1ms 30s .endc .end
comandos
- ngspice amp1.cir (en shell)
- plot v(sig) v(out) xlimit 0 3 (en ngspice)
- fft v(out) (en ngspice)
- plot mag(v(out)) xlimit 0 10 (en ngspice)
dist 1
Archivo SPICE (dist1.cir)
.title dist1 .include TL072.mod .include 1n4148.lib x1 ninv inv cc ee out TL072 vcc cc 0 15 vee ee 0 -15 v1 sig 0 sin 0 3v 1 r1 sig inv 10k rfb out inv 10k d1 inv out 1n4148 d2 out inv 1n4148 rninv ninv 0 1 .control tran 1ms 30s .endc .end
comandos
- ngspice dist1.cir
- plot v(sig) v(out) xlimit 0 3
- fft v(out)
- plot mag(v(out)) xlimit 0 10
amp 2
Vamos a correr una simulación y escuchar a la salida del circuito. Para hacerlo, generamos un archivo que contiene una grabación de los voltages durante la simulación. Convertiramos ese archivo a un archivo de audio, en formato WAV. Para eso, usamos los programas de Spice Audio Tools.
Archivo SPICE (amp2.cir)
.title amp2 .include TL072.mod x1 ninv inv cc ee out TL072 vcc cc 0 15 vee ee 0 -15 v1 sig 0 sin 0 3v 300 r1 sig inv 10k rfb out inv 10k rninv ninv 0 1 .control tran 3us 3s wrdata out.dat v(out) .endc .end
comandos
- ngspice amp2.cir
- python spicetowav.py out.dat out.wav (spicetowav.py)
dist 2
Archivo SPICE
.title dist2 .include TL072.mod .include 1n4148.lib x1 ninv inv cc ee out TL072 vcc cc 0 15 vee ee 0 -15 v1 sig 0 sin 0 3v 300 r1 sig inv 10k rfb out inv 10k d1 inv out 1n4148 d2 out inv 1n4148 rninv ninv 0 1 .control tran 3us 3s wrdata out.dat v(out) .endc .end
comandos
- ngspice dist2.cir
- python spicetowav.py out.dat distout.wav
1n4148.cir
.model 1n4148 D(IS=2.5n N=1.9 BV=100 RS=1)
TL072.mod
* TL072 OPERATIONAL AMPLIFIER "MACROMODEL" SUBCIRCUIT * CREATED USING PARTS RELEASE 4.01 ON 06/16/89 AT 13:08 * (REV N/A) SUPPLY VOLTAGE: +/-15V * CONNECTIONS: NON-INVERTING INPUT * | INVERTING INPUT * | | POSITIVE POWER SUPPLY * | | | NEGATIVE POWER SUPPLY * | | | | OUTPUT * | | | | | .SUBCKT TL072 1 2 3 4 5 * C1 11 12 3.498E-12 C2 6 7 15.00E-12 DC 5 53 DX DE 54 5 DX DLP 90 91 DX DLN 92 90 DX DP 4 3 DX EGND 99 0 POLY(2) (3,0) (4,0) 0 .5 .5 FB 7 99 POLY(5) VB VC VE VLP VLN 0 4.715E6 -5E6 5E6 5E6 -5E6 GA 6 0 11 12 282.8E-6 GCM 0 6 10 99 8.942E-9 ISS 3 10 DC 195.0E-6 HLIM 90 0 VLIM 1K J1 11 2 10 JX J2 12 1 10 JX R2 6 9 100.0E3 RD1 4 11 3.536E3 RD2 4 12 3.536E3 RO1 8 5 150 RO2 7 99 150 RP 3 4 2.143E3 RSS 10 99 1.026E6 VB 9 0 DC 0 VC 3 53 DC 2.200 VE 54 4 DC 2.200 VLIM 7 8 DC 0 VLP 91 0 DC 25 VLN 0 92 DC 25 .MODEL DX D(IS=800.0E-18) .MODEL JX PJF(IS=15.00E-12 BETA=270.1E-6 VTO=-1) .ENDS
Archivo de WAV de entrada, WAV de salida
Esta simulación consume el contenido de un archivo se llama clean.wav. Genera un archivo se llama out.wav.
Consulte en el manual de Ngspice
- 8.2.9 Filesource (PWL sourced from file)
- 8.1 Code Model Element
- 8.1.1 %v represents a single-ended voltage port
- 8.1.1 Square brackets ([ ]) are used to enclose vector input nodes.
- 13.5.78 General Form: Shell: Call the command interpreter
- 13.5.56 General Form: Pre_<command>: execute commands prior to parsing the circuit
Necesitas esos archivos en el mismo directorio con el archivo SPICE (wav_in.cir):
Archivo SPICE (wav_in.cir)
.title wave input a1 %v([in]) filesrc .model filesrc filesource (file="in.dat" amploffset=[0] amplscale=[100] timeoffset=0 timescale=1 timerelative=false amplstep=false) .model 1n4148 D(IS=2.5n N=1.9 BV=100 RS=1) r1 in out 1k d1 out 0 1n4148 d2 0 out 1n4148 .control pre_shell python3 wavtospice.py clean.wav in.dat tran 0.02m 10 wrdata out.dat v(out) shell python3 spicetowav.py out.dat out.wav .endc
comandos
Nota: Pasar la opción -b hace que se ejecute y luego finalice. Consulte "12.3 Command line options for starting ngspice" en el manual
- ngspice -b wav_in.cir
Ahora podés escuchar out.wav.