# Nomalize and convert Float to Integer

Hello,
I have the following arrays:

``````const
cMaxSampleDuration = 420;

var
MyDoubleArray: array[0..5, 0..cMaxSampleDuration -1] of Double;
MyIntegerArray: array[0..5, 0..cMaxSampleDuration -1] of Integer;``````

with the following function i convert the float number to integers:

``````  for Channel := 0 to 6 -1 do
for Samples := 0 to cMaxSampleDuration -1 do
MyIntegerArray[Channel, Samples] := Round(Frac(MyDoubleArray[Channel, Samples]) * 200000);``````

Comment: Since it's a wave i care only for the  fractional part of the float not the integer.

Now, i want to normalize the array so the scale up every channel to be in the same range.
(Like normilizing a waveform, in this case 6 channels/waves)

Thank you
Sinisa Vuk

Must pre-scan all data and get maximum value for each channel. Then go upscale data.
``````const
cMaxSampleDuration = 420;

var
MyDoubleArray: array[0..5, 0..cMaxSampleDuration -1] of Double;
MyIntegerArray: array[0..5, 0..cMaxSampleDuration -1] of Integer;
Channel, Samples: Integer;

ScaleValue: array[0..5] of Double;
AllMaxValue, GlobalScale: Double;
....
//get scale values
AllMaxValue := 0;
for Channel := 0 to 6 -1 do
begin
ScaleValue[Channel] := 0;
for Samples := 0 to cMaxSampleDuration -1 do
begin
if MyDoubleArray[Channel, Samples]>ScaleValue[Channel] then
ScaleValue[Channel] := MyDoubleArray[Channel, Samples];
end;
if ScaleValue[Channel]>AllMaxValue then
AllMaxValue := ScaleValue[Channel];
end;

//scaling
GlobalScale := 200000;
for Channel := 0 to 6 -1 do
begin
for Samples := 0 to cMaxSampleDuration -1 do
MyIntegerArray[Channel, Samples] :=
Round(Frac(MyDoubleArray[Channel, Samples] * AllMaxValue / ScaleValue[Channel]) * GlobalScale);
end;``````
chmichael