Go Down

### Topic: Control Voltage Quantizer (Read 10320 times)previous topic - next topic

#### pro424

##### Jul 30, 2018, 05:06 pm
Hi,

I've did some small Arduino project few years ago and have recently programmed a bit in Python but I'd say I'm a beginner at programming. Now however I'd like to pick up Arduino again for some music projects and the first project I'm aiming for is a voltage quantizer. Basically it should:
2. Quantize the value to the nearest value in an array.
3. Output the quantized value to a DAC.

Reading the input value is not to hard and outputting the value using a MCP4921 should probably be fine too, but I'm not entirely sure how to actually quantize the value.

So in the end I want to have a few different arrays to quantize against but, the first step would be to quantize it to 61 evenly distributed values. Here I'm thinking I could simply read the input value, divide it by the range (1024?), multiply it by 60, and rounding it to the closest integer using the math.h function round(). This value could than be divided by 60 and multiplied by the range of the DAC and directly outputted as a crude quantized value. Would you consider this a bad idea or can you suggest improvements?
My idea further was to compare this rounded value to the values of one of the arrays to find the closest value. Here I'm unsure how to proceed. Do you have suggestions?

Best regards
Max

#### Grumpy_Mike

#1
##### Sep 27, 2018, 12:36 pmLast Edit: Sep 27, 2018, 12:37 pm by Grumpy_Mike
Quote
Would you consider this a bad idea
Yes.
There is way too much processing going on for so little effect. Forget rounding because you are messing with the signal you will not perceive any diferance.

A simple shift to the right in your sample is all you need. So for a 64 level quantisation you just need to shift right four places:-
Code: [Select]
`output = sample >> 4;`

Go Up