Solved

Nomalize and convert Float to Integer

Posted on 2013-05-13
3
415 Views
Last Modified: 2013-05-21
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;

Open in new window


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);

Open in new window


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
Comment
Question by:chmichael
  • 2
3 Comments
 
LVL 25

Expert Comment

by:Sinisa Vuk
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;

Open in new window

0
 

Author Comment

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

Thank you
0
 
LVL 25

Accepted Solution

by:
Sinisa Vuk earned 500 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;

Open in new window

0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

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 my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

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

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

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now