looking for a basic DSP circuit

Started by aran.e666, May 31, 2017, 09:03:25 AM

Previous topic - Next topic

Digital Larry

I've read that Teensy audio board is noisy.  This may be down to the specific implementation rather than something inherently wrong with the concept.
Digital Larry
Want to quickly design your own effects patches for the Spin FV-1 DSP chip?
https://github.com/HolyCityAudio/SpinCAD-Designer

ElectricDruid

Maybe it is, I dunno.

In general, the principle is to keep the analog and digital parts as separate as you can, but the practice can get tricky..

T.

Transmogrifox

Quote
I'd be surprised if that were the case, specs notwithstanding. A PWM output is the lowest-fi of audio output solutions. Getting it and the DAC matched up well enough to say that you've really got 20 bits would be a very big ask.
What's the linearity on the 12-bit DAC, for example? It could well be a couple of bits out.
I think I mis-communicated what I meant by calling it a 20-bit DAC.  Clearly the noise will swamp anything below 14 or 15 bits, but that's all I need to get close to the ADC accuracy claims, and consequently audio shield performance.  The point is there is lots of dither built-in by using the PWM output for the last few MSB.

The main thing missing from the SAR ADC is the FIR anti-aliasing filter.  This isn't an issue as long as the signal source is reasonably quiet above 20 kHz  to around 100 kHz at which point reasonably good rejection can be had from analog filters.

The idea is to use the DAC as the MSB bits since the noise is clearly lower than a PWM output.  The noise on the PWM output is divided by 2^12 from the get-go (already at -72 dB).  A SPICE simulation shows me I can get the PWM noise down to <90 dB with a 4rth-order analog reconstruction filter.  This also is adequate to take off a good bit of the the 12-bit DAC digital noise.

What I'm hoping to do is get to something near 14-bit ENOB, which is on par with the audio shield.  This will get SNR and distortion down near stompbox quality audio and arguably noise from other parts of the system will dominate, making it not sound "digital".

If DAC accuracy turns out to be a significant issue then can output 10 bits DAC and increase weighting on the PWM.

This is what I'm starting with.  This is just 12-bit DAC output wired to ADC input, and used Audacity to send a sine wave via the USB audio function and record it back.  I don't think dropping the noise floor another 10 dB is entirely unreasonable, and this would get performance comparable to the audio shield.


QuoteI wouldn't sweat the latency. Assume you sample at 48KHz and process a block of 16 samples each time. This is a good idea since block processing is much more efficient than doing one single sample everytime. How bad's the latency? 16/48000 = 33usecs, a 1/3rd of a millisecond. That's so far below perceptible you'll never know.
The thought about latency is more for being able to put digital gain & filter blocks in feedback loops with other analog circuits.  Single-sample latency is fast enough to incur small enough phase shift at the <5 kHz range that one might reasonably use it (with some caution) as if it were an analog IC.  This is another draw-back to an audio CODEC -- they have significant latency built-in to the resampling filters (significant in the sense of phase-shift concerning integration with audio-frequency feedback loops).

As for most things a processing block of 64 samples is fine.  Remember the latency isn't 1.45 ms, it's double that, which is 2.9 ms.

I find the 5.8 ms latency fine for a single device.  The problem is something like a Teensy lends itself well to single-purpose stompboxes.  Add up a few of these at 5.8ms and now you're getting into the perceptible range.

With a 64 sample block you can have a few of these before it gets into the perceptible range.  I think a 32-sample block would be totally fine for 5 or 6, and 16-sample would be overkill.

So yes, I agree with your point about latency when it comes to perceptible delay.  It's just a completely different matter if making the unit into an analog circuit building-block if you ever want to apply feedback.

Quote from: Digital Larry on August 05, 2017, 01:12:03 PM
I've read that Teensy audio board is noisy.  This may be down to the specific implementation rather than something inherently wrong with the concept.
I also read that the internal high-pass filter is the culprit.  Apparently much of the irritating high-pitched whine goes away when this filter is disabled.

As for any reports about the built-in ADC being noisy, I have identified the culprit for that one, which is also the DC removal function.
https://forum.pjrc.com/threads/45770-DC-offset-removal-noise-distortion-in-input_adc-cpp-input_adcs-cpp

The DC removal function bins 128-sample averages into a 16-element delay line, and runs a moving average on that.  This is simply down-sampling followed by a moving-average filter.  The down-sampling "anti-aliasing" filter is an integrator, which doesn't have very good rejection.  The end result is significant aliasing on the input signal:

trans·mog·ri·fy
tr.v. trans·mog·ri·fied, trans·mog·ri·fy·ing, trans·mog·ri·fies To change into a different shape or form, especially one that is fantastic or bizarre.

ElectricDruid

Ok, I understand and agree with your points about the latency. If you start putting feedback around anything digital, all bets are off, for sure. If that digital thing has a 64-sample latency, the bets that are off are off!

I'm still not sure about the DAC+PWM though. Ok, you've measured the performance of the DAC - feed sine wave out, read sine wave in, analyse data, get results. Nice. Some facts are good to have, and it's too easy not to bother and just wing it (I'm guilty as hell of this...) But measurable data is the gold standard and we should stick to it.
But the problem here is that the DAC's output isn't entirely linear, in which case, adding a PWM signal to it at low level isn't necessarily going to help. I imagine it like this:
The main DAC output is a rising staircase, with fairly big steps. The PWM output is another staircase, but with very fine steps. So fine, in fact, that we'll imagine it as a rising ramp waveform. Now, if we get the ramp waveform the same height as the steps and add it onto our staircase waveform, we get a lovely smooth ramp wave rising all the way to the top. Woowee!

But now think what happens if our DAC staircase is out by a couple of bits. Some of the stairs are taller than others. Some are shorter. When we add the PWM ramp on, the flat stairs become slopes, but we still have abrupt jumps where the stairs are too short or too tall, and those jumps *are just as tall as the errors they represent*. E.g. The addition of the PWM does nothing to remove the errors. You might increase the resolution, but you don't reduce the errors. Say the errors are in the last two bits of the 12-bit DAC. Instead of a 12-bit ADC accurate to 10-bits, now you've got a 16/18/20-bit DAC accurate to 10-bits. It's not a huge improvement.
Presumably some kind of compensation algorithm could be worked out that would allow the PWM to compensate for the ADC errors, but that's a bit more involved...

This is theoretical for me since I've never tried it, and I'm always extremely wary of theoretical "it'll never work"s over "actually, I tried it and it's not bad", so I'm not trying to put you off at all. I'm just trying to explain my thinking. If it was me, I'd go ahead and do it and see what it looks like. All the theories in the world are spot-on correct until someone does an experiment that proves that they're not.

Tom


Digital Larry

Quote from: ElectricDruid on September 04, 2017, 05:44:59 PM
Ok, I understand and agree with your points about the latency. If you start putting feedback around anything digital, all bets are off, for sure. If that digital thing has a 64-sample latency, the bets that are off are off!

For longer delays and even reverb, I would not get too worked up about 64 samples of latency.  For a flanger or resonant filter, yes.  As time goes on (maybe it's just my brain starting to fall apart) I worry a little less about theoretical stuff and sometimes I just try crazy stuff to see what will happen.
Digital Larry
Want to quickly design your own effects patches for the Spin FV-1 DSP chip?
https://github.com/HolyCityAudio/SpinCAD-Designer

ElectricDruid

Absolutely agree, Larry. It's nearly always worth giving it try, even for the "crazy" stuff. After all, what's the worst that can happen? It blows up, burns your house down? pfft...

T.

Transmogrifox

Quote from: Digital Larry on September 05, 2017, 06:25:30 AM
For longer delays and even reverb, I would not get too worked up about 64 samples of latency.  For a flanger or resonant filter, yes.  As time goes on (maybe it's just my brain starting to fall apart) I worry a little less about theoretical stuff and sometimes I just try crazy stuff to see what will happen.

Agreed.  One thing I have in mind is once I made a thing I called a "haw-wah", where I put a Crybaby in a feedback loop and it turned it into a sort of a swooshy vibey thing.  One might think, why not just do it in DSP?  It can be done, but when considering the Teensy as a basic building-block, then it is nice to be able to mix analog and digital techniques.

Whether I can make it actually work is another question altogether :).

This is also true for the case of extending the DAC resolution by using PWM.  I understand your point about DAC accuracy, but it's going to be accurate to a certain number of LSB, and that is where I shift the bits in the PWM.

In either case, I agree it may not turn out as simple as combining a 12-bit DAC with 8-bits PWM and getting a 20 bit converter.

However, I do hope I can get the noise floor to <80 dB and then the performance will probably be comparable to the SGTL5000 (except for rejection of aliasing), and ultimately going for noise and distortion performance comparable to a typical stompbox.

Whatever the opinions I'm working toward that and I will report on how it turns out. 

In the mean-time I'm trying to port my floating point inductor wah model to fixed point processing.  The ultimate goal is to turn this into my "Wahd Blahk", which will be a proximity-controlled wah (like Zvex Wah Probe), but with a really broad range of wah pedal models to choose from.

I still contend the built-in ADC and DAC can be caudled into having specs not far short of the SGTL5000 minus the anti-aliasing filter that is typically built-in with these sigma delta codecs.  For that I anticipate the input source is sufficiently bandwidth-limited so (hopefully) the main contributor to aliasing will be the high frequency noise floor.
trans·mog·ri·fy
tr.v. trans·mog·ri·fied, trans·mog·ri·fy·ing, trans·mog·ri·fies To change into a different shape or form, especially one that is fantastic or bizarre.