Simple A/D model...

    Jun 01 2011 | 6:31 am
    Hi, I'd like to make a simple example, having Max 'sample' its own sine wave (complete with aliasing). Seems like it would be as simple as: [cycle~] > [snapshot~] > [~number] > [dac~]
    But I'm getting all kinds of odd results. One issue is that [snapshot] won't take float for an interval, so I'm limited to 1 ms for a 'sampling rate' (I did try fooling with an interval of samples, as well). Basically, just wanted to be pointed in the right direction in Max, if this isn't it, or be alerted to other things that might keep things from working as-expected. I've got a vector size of 64, and overdrive + in audio interrupt are on.
    Thanks, Brian

    • Jun 01 2011 | 11:33 am
      I don't think you can use snapshot for this as its output is relegated to the timing constriants of the Max scheduler, rather than the dsp scheduler. Even if you convert snapshot's output back into a signal, the result is dependent on Max scheduler settings.
      Maybe use sah~ and a control signal like train~ to get your sampling interval-- the example below aliases very well indeed...
    • Jun 02 2011 | 7:07 am
      Wow, you're right-on Terry, thanks! I read a little more, so I now I think I see that snapshot~ is really useful to get out of the signal-rate domain, but that's not quite what I want to do here. I didn't know about sah~, which is much more on-target. I am finding that- particularly as the input freq gets beyond the midrange- I'm hearing aliasing (or at least artifacting) well below where I would expect to (Nyquist). For example, even a freq as low as 90 hz will sound much different at 44.1 kHz vs. 1000 hz sample rates. Am I missing some particular theory here (I'm sure I am, which is part of the point), or is this more about massaging Max?
      Thanks again, brian
    • Jun 02 2011 | 8:42 am
      Hi Brian
      If you want to emulate a digital to analogue converter using his approach in Max you'll also need a low pass filter (after the sah~ output) that has a cutoff frequency a little below half the sampling rate (the sah~ rate) with a steep rolloff-- then you'll get the 'correct" kind of aliasing. maybe cascade a whole bunch of low pass filters. This will smooth the waveform from its stepped appearance. HTH T
    • Jun 02 2011 | 4:56 pm
      Hmm...would this be anti-aliasing filter(s) stage of an A/D you're referring to? Or is it a different one I can look into? I haven't put the anti-aliasing filter in, because AFAIK there should be no aliasing below 1/2 the sample rate with a sine wave. And that filter would need to be *before* sah~, correct? I'm actually aiming for a model A/D (as opposed to D/A), generating a tone at whatever the system sample rate it (44.1) and getting Max to re-samples it at 8 kHz or 1 kHz or whatever. Just want to be sure I'm understanding you correctly, thanks again!
    • Jun 02 2011 | 10:31 pm
      in audio sampling, you have two LP filters-- the antialiasing filter for signals coming in (a to d) and the smoothing filter for signals going out (d to a)-- you will need an emulated smoothing filter because your actual sampling rate is much higher than your emulated rate, and you need to smooth out the discontinuities in your waveform.
      I thought the point of your patch was to actually create aliasing, but if you don't want that then put a filter in before the sah~ , with a cutoff freq at half the sample-hold rate. T
    • Nov 01 2013 | 5:18 am
      Actually coming back to play with this again. So, is this in the right direction? It's surprising to me that the smoothing filter would need to be this steep. Even with this, there is clear aliasing within about 1/2 an octave of the Nyquist freq. But maybe that's the deal…?
      Thanks, Brian
    • Nov 01 2013 | 8:03 am
      This isn't really aliasing - this is more like heterodyning or creating sidebands.
      You'll see this in analog synths and especially in radios too, so it's not caused by "nyquist-bumping", from what I can tell.
      I was amused by how *well* this patch does sidebands, actually.
    • Nov 08 2013 | 5:17 am
      Well, that's certainly irritating to know. :/ I don't get it, I thought this would be a (relatively) simple & straightforward undertaking in Max, and it's been the complete opposite. I'm no DSP engineer, but I do feel like I get the most basic guts of an ADC, and that's all I'm looking to accomplish. Can anyone fill-in a blind spot?
      Thanks, Brian
    • Nov 09 2013 | 2:13 pm
      the blind spot may be that D/A and A/D conversion is done on dedicated chips, and it's because of this that it works.
      So I don't think you can ever get that sound without actually going out of the d/a and then back into the computer - that's simple enough.
      Now, from a pedagogical standpoint snapshot might actually work fine, just run the cycle~ at a much slower rate (like, 0.1 hertz, for instance), and then run it into a scope~ or something, so you can see the steps. *see*, mind you.
      Then you can use the original cycle~ and the resulting resampling to *modulate* a second cycle~, letting you hear what's going on inside the waveform, even though it's below audiorate.
    • Nov 09 2013 | 6:59 pm
      I see your point, but I'm a little fuzzy on the concrete problem. Are you saying it's a pure speed problem? I got the idea that might the case with the Max scheduler (1 ms), so I moved it all to signal-rate (which is probably should have been in the first place). I have tried much lower freq (not 0.01 hz) and it sort of works, just not anywhere near what I'm expecting. Even at 1/2 of the Max scheduler rate, surely it's accurate enough to re-sample well-below the (re-sampled) Nyquist freq? I've certainly pushed MSP much harder before…
      Thanks, Brian