[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
Solved

# Nomalize and convert Float to Integer

Posted on 2013-05-13
Medium Priority
454 Views
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
0
Question by:chmichael
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• Learn & ask questions
• 2

LVL 28

Expert Comment

ID: 39163176
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;
``````
0

Author Comment

ID: 39167465
It doesn't work with negative numbers! Can you take a look ?

Thank you
0

LVL 28

Accepted Solution

Sinisa Vuk earned 2000 total points
ID: 39177624
Try this modification:
``````//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 Abs(MyDoubleArray[Channel, Samples])>Abs(ScaleValue[Channel]) then
ScaleValue[Channel] := MyDoubleArray[Channel, Samples];
end;
if Abs(ScaleValue[Channel])>Abs(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] * Abs(AllMaxValue) / Abs(ScaleValue[Channel])) * GlobalScale);
end;
``````
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
###### Suggested Courses
Course of the Month13 days, 8 hours left to enroll

#### 656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.