
Home  Forums  Rules  Articles  The diyAudio Store  Gallery  Blogs  Register  Donations  FAQ  Calendar  Search  Today's Posts  Mark Forums Read  Search 
Software Tools SPICE, PCB CAD, speaker design and measurement software, calculators 

Please consider donating to help us continue to serve you.
Ads on/off / Custom Title / More PMs / More album space / Advanced printing & mass image saving 

Thread Tools  Search this Thread 
13th November 2011, 01:56 PM  #1 
diyAudio Member
Join Date: Feb 2008
Location: Seattle

Modeling analog circuits in DSP?
It's easy to transcribe an analog circuit into SPICE and get a plot of the frequency response, impulse response, distortion or other useful measurements. What I would like to do is model a particular analog circuit in DSP for real time processing of audio.
Are there any textbooks or articles which describe this technique in tutorial fashion? I see many web sites geared towards designing a filter, but none for analysis of an existing filter or translation of an existing circuit into a software DSP model. Case in point: I'm looking at a discrete FM transmitter schematic based on transistors and passives. There is a 15 kHz lowpass and a 19 kHz notch filter that I would like to emulate exactly in software. The 15 kHz LP is a series of 'pi' filters with shunt capacitors and series inductors. In total, there are 4 capacitors and 3 inductors (plus a series input resistor and a shunt output resistor). Quick searches online led me to determine that this is a 7thorder filter, presumably 42 dB/octave. Analog filter design calculators even produce very similar capacitor and inductor values when asked to create a 7thorder low pass, but the pattern isn't quite the same. I'm sure this is because I found a Chebyshev design calculator and the schematic I have was probably designed using a different method. Rather than continuing to search for new methods until I find a match, I'd rather just model each passive component in software and duplicate the exact filter, as is. There is also a 19 kHz notch as a parallel combination of an inductor and capacitor in the signal path. I'd like to model that, too. SPICE doesn't give me DSP source, just graphs, and certainly not on real time audio inputs. Looking back at my college texts, I've almost remembered how to calculate the frequency response of a random circuit. The resulting formula would reveal the poles and zeroes of the transfer function. At that point, I could probably use Direct Form I or II to translate the formula into code. I'm just wondering if there might be an easier way to go directly from discrete components to DSP code, perhaps without solving algebra and calculus problems. 
16th November 2011, 10:31 PM  #2 
diyAudio Member
Join Date: Apr 2008
Location: Carlisle, England

I would look up DSP techniques on the web or buy a good DSP book.
Look up Texas Instruments and Microchip DSP websites.
__________________
PCBCAD50 software. http://www.murtonpikesystems.co.uk 
16th November 2011, 11:01 PM  #3  
diyAudio Member
Join Date: Feb 2008
Location: Seattle

Quote:
I have several excellent DSP books. I have also designed and released four commercial products based on Microchip and Texas Instruments DSP chips. I have the DSP side of things fairly well sorted. What seems to be missing from the texts and the web is the translation of specific analog circuits into DSP code that accurately models what those circuits are doing. Here are the techniques that I see covered quite well: A) SPICE modeling of analog circuits, but not in real time and certainly not with live audio input B) Tools for designing new analog circuits based on filter specifications C) Tools for designing new DSP software based on filter specifications D) Math tools for analysis of analog circuits, including predicting the frequency response or impulse response E) FFT and other DSP tools for analysis of software plugins, showing frequency response or impulse response As I said, what seems to be missing are tools for translating an analog circuit directly into DSP that can model or emulate them in real time. What seems to be missing is that analog circuits deal in actual voltages, whereas DSP generally normalizes everything to +/1.0, modifying the constants to produce unity gain with every building block. When it comes to emulation, I would think that the DSP would need to simulate actual voltages so as to deal with potential nonlinearities, or at least so that standard capacitance values and standard resistor values can be plugged in rather than just using the "ideal" values. The nice thing about DSP is that you are not limited to standard values for passives, and thus you can get closer to your ideal frequency response, although there are limitations when you get close to Nyquist or when filter coefficient quantization causes the frequency response to shift away from the ideal. Although that flexibility of DSP is a great feature on its own, it's not useful for emulation, where the goal is to mimic the exact performance of some existing analog circuitry. My hypothesisinprogress is that I could use the mathematical tools to analyze a given analog circuit and come up with a matrix of simultaneous equations, then translate those equations into DSP code. The trick might be the optimization phase, where one of the simple Direct Form code patterns is preferred, i.e., FIR or IIR. But somehow this seems like going around my elbow to get to my ear. I think it should be possible to have an almost objectoriented DSP system where each capacitor, inductor, resistor, transistor, diode, etc. can be plugged in and emulated. The math would be isolated to each component, possibly without the need to manually analyze the entire circuit. Basically, what I am looking for is realtime SPICE that can output source code to be compiled into an efficient DSP plugin ... draw the circuit, press a button, compile the code. I'd be happy to find a technique that works even without the simplicity of pushing a button, but I'm not even close. 

16th November 2011, 11:08 PM  #4 
diyAudio Member
Join Date: Apr 2008
Location: Carlisle, England

Sounds a bit like designing FPGA's using a schematic rather than VHDL.
I found understanding schematics easy but the VHDL is a bit too abstract for me. I guess your only way to forward is to reverse engineer the hardware and convert it to software.
__________________
PCBCAD50 software. http://www.murtonpikesystems.co.uk 
16th November 2011, 11:24 PM  #5  
diyAudio Member
Join Date: Apr 2010

DSP filter algorithms are based on what's "easy" to do in DSPs, and fall into two categories: FIR and IIR. I think the second is "more analoglike" but neither is an exact copy of reallife analog filters. It's certainly possible to make such DSP filters approximate analog filters (or any arbitrary frequency response) to reasonable precision, and I might suggest you go in that direction.
If you're determined to do an exact simulation in the digital domain, you could start with LTspice  it won't run in realtime, but it can read and write .wav files as stimulus and response files in simulated circuits. Exact circuits CAN be simulated by computers/DSPs in real time, but I don't know of any examples of it being done, as it appears to be much easier both in computational efficiency and code development to use FIR and IIR (and now that I think if it, FFT, and there may be others that don't come to mind) filters, which are digitaldomainspecific techniques that have been developed over many decades to run on computers. Quote:
And of course there's a lot to both analog filter design and DSP filters. Here's a free online DSP book that may help: The Scientist and Engineer's Guide to Digital Signal Processing 

16th November 2011, 11:42 PM  #6  
diyAudio Member
Join Date: Apr 2010

And so now I see this post:
Quote:
I recall about 30 years ago writing a basic program on an Apple /// to draw the frequency response of a 3way speaker crossover. I used my AC circuit analysis knowledge to calculate the reactance of each capacitor and inductor at the frequency of interest, wrote the equations to do the complex number arithmetic, and plot the response at each driver on a loglog screen. Of course this was in the frequency domain, and you want to do this in the time domain, which is completely different. You're looking to write discretetime versions of equations such the second one here: RLC circuit  Wikipedia, the free encyclopedia A quick look with the right keywords finds there ARE such things on the Web, at least in their simplest forms. A Google search for discrete time capacitor simulation got me here: Lowpass filter  Wikipedia, the free encyclopedia The text goes through an algebraic simplification of the circuit to get to the code, but it's at least in the direction you want of code for realtime circuit simulation. Last edited by benb; 16th November 2011 at 11:43 PM. Reason: deleted redundant link 

17th November 2011, 12:05 AM  #7  
diyAudio Member
Join Date: Feb 2008
Location: Seattle

Quote:
Taking the simplest RC filter and looking at the formula for the Vo versus Vi, you end up with equations that look almost exactly like the DSP equivalent. In the digital realm you have "out = a * in + b * out" where you have to keep the old value of out around in a state variable. One interesting thing here is that a = 1  x and b = x, where x is a transcendental function of the filter corner frequency and the sample rate. But really, choosing 'a' and 'b' such that a = 1  b is merely a technique to get the gain of the filter as close to unity as possible. If you get rid of this normalization, and adjust for voltages versus arbitrary digital ranges, then what you have is the exact same mathematical formula in both the analog RC filter and the digital equivalent. The biggest difference is that the normalization in the digital version hides any passive losses that might occur in the analog version, and thus any simulation would need to take this into account. Also, whenever there are semiconductors in the signal path, you'll want to know actual voltages instead of normalizing to +/1.0 Quote:
Quote:
Another problem is that fixedpoint filter coefficients and sometimes even floatingpoint filter coefficients can cause the actual frequency response to deviate from the ideal due to quantization errors. This is particularly a problem with IIR filters. Then again, these two examples may actually be symptoms of the same fundamental problem. So, I'm not trying to say that digital is 'worse' than analog; I'm merely pointing out that both can be very sensitive to certain border values. At the very least, digital filters are perfectly repeatable, even if their response is not perfect. To the degree that you can tweak out any imperfections in the digital filter response, these tweaks can be duplicated precisely everywhere they're needed. One of the reasons I'm being particular is that the online analog filter design tools suggested slightly different capacitor values, and I'd like to emulate the exact response. Also, I noticed that where the analog circuit reused the same capacitor values in a symmetric pattern, the filter design site showed a different pattern. I'll want to duplicate the actual pattern. Quote:


17th November 2011, 12:20 AM  #8 
diyAudio Member
Join Date: Jun 2011

Google bilinear transform. The bilinear transform is used for precisely this purpose if I understand your question correctly.
You have to write the transfer function of the (linear timeinvariant) filter in terms of the Laplace transform Ha(S) (which is comparatively straightforward) whence it can be transformed to a linear shiftinvariant filter of transfer function Hd(Z) There are facilities in Matlab to cope with this type of simulation IIRC, you might find that one of the opensource alternatives is useful. 
17th November 2011, 12:42 AM  #9  
diyAudio Member
Join Date: Feb 2008
Location: Seattle

Quote:
I guess I'm going to have to review my college texts again. I don't even remember using Laplace transforms, but I'm sure we covered it and then I forgot it due to lack of application. In my day, computers could not process audio in real time, but we still studied impulse responses and convolution. Beautiful math, and at the time I never dreamed that it would be possible in real time. I think you may be right that this is what I need. I just have to study those chapters in every text, and put some time into practicing the math. By the way, when you say "opensource alternatives," do you mean alternatives to Matlab (which I don't have due to its expense), or merely alternatives to the bilinear transform facilities alone? 

17th November 2011, 01:03 AM  #10 
diyAudio Member
Join Date: Jun 2011

I was referring to Scilab or Octave which are alternatives to Matlab. I think you need the supporting environment to make use of the filters in a simulation without a lot of effort. I believe Octave is closest in terms of interoperability of code, but I haven't had the need to explore either.

Thread Tools  Search this Thread 


Similar Threads  
Thread  Thread Starter  Forum  Replies  Last Post 
DSP and vacuum tubes (from Analog Devices)  jackinnj  Tubes / Valves  8  13th November 2011 03:03 PM 
HDMI to analog, or multiple analog channel mixer  TAYLOR1337  Digital Source  1  12th September 2011 09:17 PM 
RS232 cable for DSPAmp Digisynthetic DSP1400  Sabbelbacke  Parts  0  9th May 2009 09:33 AM 
Research on tubes and circuits simple circuits  Cazcotty  Tubes / Valves  6  16th June 2006 12:50 PM 
85 powersupply circuits 58 charge circuits  gev  Power Supplies  0  31st July 2005 11:27 AM 
New To Site?  Need Help? 