gnucap-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gnucap-devel] Patch for generator command to read ASCII input files


From: Telford Tendys
Subject: [Gnucap-devel] Patch for generator command to read ASCII input files
Date: Wed, 29 Dec 2004 04:49:24 +1100
User-agent: Mutt/1.5.6i

Here is another patch, this one against v0.34 which gets the generator
command to be able to read input files.

  http://www.triode.net.au/~telford/gnucap/gnucap-0.34-infile.patch.gz

For example you can use sox to do something like:

  sox audio.ogg audio.dat

Then run a circuit like so:

----------------------- test.ckt --------------------------
TEST FOR GENERATOR INPUT FILE

* Input an audio file, filter it with a first order low-pass filter and output
* Of course, this is a very slow way to implement a first order low-pass and sox
* provides filtering anyhow but the point is that you can implement complex 
filters
* in a circuit design, test them with audio samples, listen to the result,
* then build the circuit.

V1 1 0 GENERATOR(2)
* 1.5kHz first order low pass (even my ears can hear this)
R1 1 2 1k
C1 0 2 0.1u

* File generated by sox has one header line which we ignore
* In this case the rate is 16000 so choose a transient analysis
* that matches the given rate
.generator file=audio.dat fileskip=1

.print tran V(2)
.tran 0 60 .0000625 > output.dat
--------------------------------------------------------------

Then you have to edit a "sample rate" header onto output.dat
and replace the normal gnucap header (the gnucap header screws up sox,
even if you force the sample rate with a command line option).
Having done that, you can play the filtered sample and compare to
the original.

Note the with the "fileskip=xx" option, you can handle files
with various headers (but one header line is most common).

Lines that it doesn't understand will generate an error.
Maybe this should be a warning?

If the file runs out before the transient simulation is complete
then it will pad the tail of the file with zeros.

Some of the other generator options are compatible, for example
the amplitude will multiply up the values from the file.
I haven't fully nutted out all the permutations, some of them
might give strange results.

The generator does linear interpolation between sample values
of the input file so all time values are supported cleanly, even
when sample times are not equal spaced, etc. I know that linear
interpolation is not ideal, but it is easy to achieve.
If you want to input digital data, encode both sides of each
transition:

1000E-6   0
1010E-6   0
1010E-6   5
1050E-6   5
1050E-6   0
1060E-6   0
1060E-6   5

... etc ...

This makes it easier to handle unusual waveforms with the generator
(because you can knock up a quick perl/python/bash program to 
calculate your special waveform) and makes it easier to feed "real
world" data into gnucap (from whatever sample source you like).

Quite a few digital oscilloscopes will give an ASCII file so you
can measure a signal, then design and optimise a filter.

        - Tel




reply via email to

[Prev in Thread] Current Thread [Next in Thread]