Tuesday, 25 November 2008

Dirty Pascall done

This is a very dirty pascal program that just shows what I intend to do is actually possible. The input word is (equivalent to) 5bits 2's compliment with D5 the sign bit; as this program is a model I have only got base 10 input so values from -16 to 16 are acceptable. The more iterations the higher the sample rate and so the lower the noise of the modulator.
So for example if you input 0 and perform 10 iterations the output is:
0101010101
Therefore the mean is 0.5, taking into account that 0 is actually 1/2 full scale (as the modulator accepts negative inputs) this means the mean output is 0.

//This simulates a digital delta sigma modulator with a 5bit input
program deltasigma;

var
input, sum, int, comp, QN: double;
loop, endeth: integer;

begin
writeln('Input the base 10 value of the input voltage (max 16) (min -16): ');
read(input);
writeln('Itarations? ');
read(endeth);

//intial conditions
comp := 0;
QN := 0;
int := 0;
sum := 0;

for loop := 1 to endeth do begin
sum := (input + QN);
int := (int + sum);
if int > 0 then
comp := 1;
if int < 0 then
comp := 0;
if int = 0 then
comp := 0;
if comp = 0 then
QN := 16;
if comp = 1 then
QN := -16;
writeln(comp);
end;
end.

No comments: