Hi,
im trying to write a 1bit sigma-delta DAC in C, but I don´t really know where to start. I wrote this piece of code to try it, but I really have no idea how to correctly do the integration which i feel should be there somewhere. Basically i would like to get it to compute this http://upload.wikimedia.org/wikipedia/en/2/20/Pulse-density_modulation_1_period.gif, or actually the 16 bits that approximate the sine first quadrant.
Here is my code:
im trying to write a 1bit sigma-delta DAC in C, but I don´t really know where to start. I wrote this piece of code to try it, but I really have no idea how to correctly do the integration which i feel should be there somewhere. Basically i would like to get it to compute this http://upload.wikimedia.org/wikipedia/en/2/20/Pulse-density_modulation_1_period.gif, or actually the 16 bits that approximate the sine first quadrant.
Here is my code:
Rich (BB code):
#include <math.h>
#include <stdio.h>
#define PI 3.141592654
int main(int argc, char** argv) {
double sinv[16];
for(int i=0;i<16;i++){
sinv=sin(((double)i+1)*PI/32);
}
double val=0.25;
double delta, sum=0;
for(int i=0;i<16;i++){
//val=sinv;
delta=sum-val;
if(delta<=0){
sum=(sum*1.0+1.0/16)/1;
printf("1 %f %f\n",sum, val);
}
else {
sum=(sum*1.0-1.0/16)/1;
printf("0 %f %f\n", sum, val);
}
}
return 0;
}