Circuit modeled filter, how to?

DSP, Plugin and Host development discussion.
Post Reply New Topic
RELATED
PRODUCTS

Post

Also in my previous post I left out the type of waveshaper which was meant to be the voltage to voltage diode transfer function.

Andrew

Post

i'm not sure why a beginner would ever be able to implement that while not implementing the diode equation, as the voltage-to-voltage function requires a whole lot of extra steps to take into account entrance/exit currents and so on.

a beginner would be able to implement what i did, exactly in the way i did. i looked at the current going into the whole circuit through R, i looked at the charge of the capacitor, i looked at the current through the clamp. i came to the conclusion immediately that the clamp draws current at the peak of the waveform, and that the inverse of that would be that the charing of the capacitor follows a logarithm. the only knowledge i have in excess of a beginner is, i know that a diode conducts current with a exponential relationship to voltage. this only aided me in confirming that my first impression was correct.

i could see all this simply glancing at the schematic you posted, however as i've pointed out a beginner should try using a spice simulator in order to view these waveforms directly, not having to use their imagination to see them.

..i also very strongly disagree that the code i have posted does not qualify as the utmost example of "basic dsp". this is preschooler stuff.

i know this for a fact, as i was doing this stuff a decade ago in qbasic before i had ever spent any time in dsp or programming in general. my first attempts at a digital filter were based upon an ideal spring and ideal newtonian mass, which i would still advise is a good place to fiddle about and learn the basics of these systems.

Post

andy_FX wrote: The particular placement of the waveshaper shows a level of circuit knowledge beyond what a beginner in dsp would have. How is a beginner meant to derive what you have posted? Given a new circuit they are looking at how do they solve the problem for themselves? I am all about learning and giving people the correct references to learn for themselves and I will answer any questions people have.
And this is exactly the thing I'd wanted to know when I first considered analyzing any circuit in hopes of implementing something similar in software.

The thing is, there is very little if any tutorials or documents anywhere that would teach how non-linearities affect circuits and how to model such things in DSP. Or even how non-linearities affect DSP systems for that matter. Sure if you understand enough about the circuits that you can analyze the stuff yourself, it might not be exactly rocket science (though I don't understand what's so hard about rockets in the first place.. put lotsa fuel into a tube and light it up, and if you manage to keep it moving in the desired direction you have a rocket).

Anyway, what I'm trying to say, is that there's TONS of information about LTI systems whether analog or DSP, how to design them, how to get DSP out of the analog, how to order pizza with 'em...

And mm.. non-linear? Not really. Some academic papers about special cases. Some EE stuff about things you need in EE like how to get DC from AC or whatever. Some really basic stuff too, but mostly so basic you'll have to work it all out yourself anyway.

For time-varying? Gimme a break. Even the Stilson et al. papers about Moog filter basicly say "this behaves nicely in analog in time-varying case so we guess the same should happen when we model this." Some transient suppression stuff exists in academic papers (which mostly seem to consider discrete changes once in a while). Ok, there's some random papers about special cases again, but...


I would be kinda cool if somebody bothered to get together some basic information about all this stuff that each of us has to learn more or less for themselves, and published it as a basic tutorial. Things like how filters structure affects it's response to cutoff changes and what can be done about it, or what sort of effects can you get with saturations in non-obvious places and what kind of circuits would those correspond to.

But I guess everyone with that information is too damn busy utilizing it themselves (like I unfortunately would have to claim about myself), and/or unwilling to give out trade secrets.

Post

mystran wrote: I would be kinda cool if somebody bothered to get together some basic information about all this stuff that each of us has to learn more or less for themselves, and published it as a basic tutorial. Things like how filters structure affects it's response to cutoff changes and what can be done about it, or what sort of effects can you get with saturations in non-obvious places and what kind of circuits would those correspond to.
oh yes. that would be really great. i have no background in circuit modeling and would be happy to learn something more about that business. from page 3 (yeah, i've been lurking for a while but didn't dare to comment anything), i remember this:
andy_FX wrote:I have loads of algorithms that I will be sharing in the future about SVF corrections, x-pander filter taps, the ms-20 filter and more. I'll be writing these papers as soon as some products are out the door and I have some time to dedicate to adding to the shared knowledge base.
so andy, are you going to educate us non EEs about circuit modeling? if so, i'm already looking forward to this. but what you wrote next, was a bit baffling to me:
I have posted code before about the svf code, but I think it did more harm than good. People just copy and paste it without any understanding or furthering of dsp, there are now just millions of crappy sounding filter plugins is all. Great.
mmmhhh...people use your filter-code as is and it suddenly begins to sound crappy just because they do not know how it works internally? i mean, even if one does not know how it works - it's still your code and should still sound the same, no? no offense intended here - i'm also more of the kind who wants to understand what's going on in some reasonable detail. but having working code around is on the other hand great as well. be it as reference against which one can compare the own code or as point of departure, or ...well O.K. sometimes also as black box when one is short with time.
My website: rs-met.com, My presences on: YouTube, GitHub, Facebook

Post

mystran wrote:The thing is, there is very little if any tutorials or documents anywhere that would teach how non-linearities affect circuits and how to model such things in DSP.
I personally think you should not care about that. All you need to do is define a system of non-linear equations.

In many cases 'circuit modeling' can be cheated a bit by using higher oversampling instead of a 'non-linear eq systems solver'. Otherwise you can't cheat a non-linear system that way, or it will be very approximate or incorrect at all (e.g. you can unroll a system of equations into a linear set of calculations, but your last equation will give you a wrong result in some variable). While at high oversampling rate, the whole system becomes a non-linear solver since system's input changes slowly and any "last variable error" becomes small. But still you have to use some kind of error propagation which can be performed by capacitances.

***

Thinking out loud and theoretically, you may need to place a virtual capacitor near every electrical component, including resistors (actually, virtual capacitors should be attached to variables these electrical components present to the schematic, not to the actual components), tuned to a Nyquist frequency - probably such approach could be used to unroll and linearize any system of equations; such capacitor should be charged with 'error' value found after backtracing the calculations, and discharged (added to the variable in question) on the next sample frame. By 'Nyquist frequency' I mean Nyquist frequency before oversampling.

So, this may work this way:

1. You select variables that define schematic to your liking (these are usually voltages and currents between components).
2. For each variable: allocate a "double" value storage plus a "double" storage for 1st order low-pass filter that will store error; init to zero.
3. For each component you have in your schematic, build an expression that ties variables selected on step 1 together.
4. Perform a calculation of all expressions.
5. Perform a calculation of all expressions again, and take the differences between values produced on step 4 and step 5, store these differences in the low-pass filter storage for each variable.
6. Copy all error values to value storages (some will be reset back to 0, some will store a higher/a lower value).
7. Advance the sample frame and go to step 4.

This is an algorithm out of my head, and it may be wrong. :) What it does require is a great deal of oversampling (at least 4x) to be stable.

For best results you may need to rearrange expressions and select more appropriate variables. You just do not have to worry if your expression uses variable not seemingly defined yet: it should be treated as defined, in the worst case it will be zero, and all basic electric components behave well with zero.

In this algorithm a capacitor can be considered to be a non-linear component: you should not mix scheme's capacitors with 1st order low-pass error filters used in algorithm: you'll need an additional state storage for each capacitor.

Expressions should probably look this way (this is just an example):
Ua=Ia*Ra
V2=Ua+V1
Ub=V3-V2
Ib=cap(Ub)
V3=0
V1=Vin

If you evaluate equations in random order, and then calculuate error corrections in random order, it can't be wrong (you just have to be sure your expressions carry as much connection information as the original schematic). :) But I'm probably very very wrong with such approach. Just an idea. ;)
Image

Post

aciddose wrote:a beginner would be able to implement what i did, exactly in the way i did.
This is my point, they don't have any understanding, they can only copy what you did. All code in the end is just a bunch of multiplies and additions etc, this doesn't meant that the meaning behind the code is any less complex. Understanding the meaning behind the code is what is important.
aciddose wrote:i could see all this simply glancing at the schematic you posted, however as i've pointed out a beginner should try using a spice simulator in order to view these waveforms directly, not having to use their imagination to see them.
So now you agree to my final point, although I would recommend qucs as the circuit simulator to use to get to know what the hell is going on since I think it's easier to learn and has more functionality that is practical to people like us and it's free and cross platform. Also one major major major cool feature: you can type in your own equations! That's right, your VI low order poly you can type in to qucs and check out how good it works! I'll post an example of this to show how your model works in qucs if you like.

Andrew

Post

Aleksey Vaneev wrote: In many cases 'circuit modeling' can be cheated a bit by using higher oversampling instead of a 'non-linear eq systems solver'. Otherwise you can't cheat a non-linear system that way, or it will be very approximate or incorrect at all (e.g. you can unroll a system of equations into a linear set of calculations, but your last equation will give you a wrong result in some variable). While at high oversampling rate, the whole system becomes a non-linear solver since system's input changes slowly and any "last variable error" becomes small. But still you have to use some kind of error propagation which can be performed by capacitances.
I can understand part where you oversample and then feedback errors and possibly the part where you do things in random order (I guess that basically translates to dithering and noise-shaping in time-axis? I've actually been wondering whether time dithering with noise-shaping would be a workable approach to avoid excess oversampling, but haven't had time to start working on that yet..) but I still can't see how that would get of any "strong" non-linearities? I mean isn't the point of non-linearities (and modeling and/or designing them) that they cause harmonic and (often more interestingly) inter-modulation distortions that color the sound in ways that a linear system in unable to do? Basically, we do have theory of polynomials giving specific harmonics when you feed a unity-gain sine-wave to a given polynomial, but that doesn't take us very far if we are to process complex signals and/or what stateful non-linearities (such as the diodes in the opamp's feedback loop or whatever).

Or are you proposing that by oversampling and randomizing order, we can just calculate instant voltages and currents and apply non-linearities to those and the problem of correctly placing the non-linearities somehow disappears? (Though I admit that once one understands the voltages and currents relevant to the circuit it isn't necessarily hard to place non-linearities anymore.)

That also doesn't address the fact that ordering of a DSP algorithm (eg. whether you place a zero or pole first) can have an effect on the systems response in the time-varying case, and there seems to close to no information about analyzing or designing such things whether circuit-modeling or just messing with DSP in general.

Post

mystran wrote:The thing is, there is very little if any tutorials or documents anywhere that would teach how non-linearities affect circuits and how to model such things in DSP.
First up I would recommend getting to grips with linear circuit theory. Schaum's outlines are good for this:

Basic Circuit Anaysis

But there are loads of links of the web that also cover this stuff.

This page runs through a simplified version of how circuit simulators compute stuff:

Spice Topics

You can download a circuit simulator from one of the links below:

Qucs Hompage
eCircuit Center (Spice)

The models that spice/qucs uses can get quite involved, but the qucs documentation goes through all the parameters pretty well so you know which ones to leave to save cpu when you do a dsp version. Once you have sorted out the main parts of the model you need you can start simplifying and optimising them using either table lookups, low order polys or whatever other optimisation methods you so choose:

Qucs Technical Papers

Feel free to ask any questions if you want.

Andrew

Post

mystran wrote: Or are you proposing that by oversampling and randomizing order, we can just calculate instant voltages and currents and apply non-linearities to those and the problem of correctly placing the non-linearities somehow disappears?

That also doesn't address the fact that ordering of a DSP algorithm (eg. whether you place a zero or pole first) can have an effect on the systems response in the time-varying case, and there seems to close to no information about analyzing or designing such things whether circuit-modeling or just messing with DSP in general.
Electric scheme is a SYSTEM of components. So, there is no such thing as 'ordering of components'. That's why calculating components in random order will work.

The approach I've proposed does not magically solve non-linearities problem (no solver will do it in one step), it may just probably help to solve the circuit faster and won't require differentials( but this is just my wishful thinking - have to check this approach). Just do not forget that non-linear components are already expressed via non-linear functions. What is really problematic is solving them as a part of a system.

As far as polynomials are concerned, you may build an internal bandlimiting easily. x^2 means that the same signal is multiplied by itself. During multiplication, each frequency of signal A shifts each frequency of signal B to the right (to the higher frequencies). So, if you have 10 Hz in signal A, and two frequencies (50 and 90) in signal B, you'll get 60 Hz and 100 Hz components & 40 and 80 Hz that rise from the negative frequencies side (it's -50 and -90 Hz shifted to the right). But as far as bandlimiting is concerned, you do not have to care about negative frequencies specially.

So, to be safe you just have to be sure you do not multiply two frequencies that when summed appear above the Nyquist frequency. And that's the toughtest thing. Cutting both signals above Nyquist/2 won't work well. What you should do is split signals into bands and perform multiplication of bands whose frequencies do not go over Nyquist when summed. Then you can sum the multiplication results and that will be close to oversampled multiplication.

But really it is not more efficient than oversampling. It's much easier to perform 2x oversampling and then perform x^2 multiplication, and then do low-pass filtering: you can iterate this process and reach any polynomial order without having any aliasing. (in order to reduce group delay of higher order elements you may multiply the already calculated x^2 by x^2 to get x^4, the same applies to other orders).
Last edited by Aleksey Vaneev on Thu Feb 21, 2008 11:54 am, edited 4 times in total.
Image

Post

I didn't know QUCS, looks quite interesting :love: I'm using LTSpice, which is free and can import/export WAV files, this is possible with QUCS too ?

Post

Wolfen666 wrote:I didn't know QUCS, looks quite interesting :love: I'm using LTSpice, which is free and can import/export WAV files, this is possible with QUCS too ?
Yes it's possible since it's open source, but there is not wav or aif processing module currently written. I am keen to get one done, and some automation graphs as well to make qucs into a little circuit modeling sequencer that could render amazing results.

Andrew

Post

and some automation graphs
:love: :love: :love: With something like that, it would be possible to control a synth, and get a render from something which looks like a midi file :love:

Post

andy_FX wrote:
mystran wrote:The thing is, there is very little if any tutorials or documents anywhere that would teach how non-linearities affect circuits and how to model such things in DSP.
First up I would recommend getting to grips with linear circuit theory. Schaum's outlines are good for this:
Thank you for comprehending your reading just as well as aciddose (no offense thought, please). I was specifically talking about non-linearities. Also, I wasn't saying I wouldn't understand the basics already. I was instead stating that there's little information available in form that would be useful for a signal processing newbie (digital or not) that would rather stand on the shoulders of giants than start from scratch.

Maybe I just failed to search the right places back when I was figuring out such things. But the links you give are:

- linear stuff.. that's explained everywhere, both for analog and digital, like I think I quite explicitly stated already
- useful for experimentation, but that's not exactly the way you want to go if you want to understand what is happening

Well, qucs docs I don't know about. Gonna check if there's something, but other than that you are just listing stuff that I didn't claim was missing.

Post

Aleksey Vaneev wrote: Electric scheme is a SYSTEM of components. So, there is no such thing as 'ordering of components'. That's why calculating components in random order will work.
Please practice reading comprehension. I said order of DSP algorithm. What you are proposing is a DSP algorithm with non-deterministic order, but causality in a discreet system requires some sort of ordering.
As far as polynomials are concerned, you may build an internal bandlimiting easily. [...]
Thank you for educating us about the only useful (non-trivial) piece of information explained in practically every DSP tutorial concerning non-linearities.

Isn't it quite surprising that you can also multiply two completely unrelated (band-limited) signal and you'll only ever get bandwidth worth the sum of the bandwidths of the original signals, such that oversampling by 2 is sufficient to guarantee no aliasing (up to the quality of the oversampling filter), especially considering the elementary relation ship between convolution and multiplication such that one in time-domain corresponds to the another in transfer-domain (and vice versa if you like).

Post

mystran wrote:I was specifically talking about non-linearities. Also, I wasn't saying I wouldn't understand the basics already. I was instead stating that there's little information available in form that would be useful for a signal processing newbie (digital or not) that would rather stand on the shoulders of giants than start from scratch.

Maybe I just failed to search the right places back when I was figuring out such things. But the links you give are:
Yes you didn't look in the right place. You want the sub link on the eCircuit Center page:
Non-Linear Anaysis

Andrew

Post Reply

Return to “DSP and Plugin Development”