Solved

Nomalize and convert Float to Integer

Posted on 2013-05-13
3
417 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 26

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 26

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Concerto provides fully managed cloud services and the expertise to provide an easy and reliable route to the cloud. Our best-in-class solutions help you address the toughest IT challenges, find new efficiencies and deliver the best application expe…
Delivering innovative fully-managed cloud services for mission-critical applications requires expertise in multiple areas plus vision and commitment. Meet a few of the people behind the quality services of Concerto.

914 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

23 Experts available now in Live!

Get 1:1 Help Now