?
Solved

Nomalize and convert Float to Integer

Posted on 2013-05-13
3
Medium Priority
?
444 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
[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
3 Comments
 
LVL 27

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 27

Accepted Solution

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

Open in new window

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses

777 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