Author Topic: normalization and Remove DC Offset  (Read 96 times)

devid_88

  • Posts: 7
normalization and Remove DC Offset
« on: 6 Jun '21 - 08:03 »

Hello
    These steps are for normalization

Code: [Select]
procedure DSPNormalize(handle : HDSP; channel : DWORD; buffer : Pointer; length : DWORD; user: Pointer); stdcall;
 var
 a: Int64;
 d: PSingle;
 amp,n,l,p: Single;
begin
  d := buffer;
  a := 0;
  amp := Power(10.0, NORMALIZER_GAIN /20.0);
  l := 1.0;
  p := MulDiv(100, NORMALIZER_PEAKS ,32767) / 100;
  n := amp * l / (p);
  while (a < (length div 4)) do
   begin
     d^ := d^ * n;
     inc(d);
     a := a + 1;
   end
end;


how to removing DC offset  ???

thanks for all




Ian @ un4seen

  • Administrator
  • Posts: 23619
Re: normalization and Remove DC Offset
« Reply #1 on: 7 Jun '21 - 15:08 »
Do you already have the DC offset value and just want to remove it? If so, you should subtract it from each sample. I'm not a Delphi user myself, but perhaps like this:

Code: [Select]
     d^ := (d^ - dc) * n;

Note doing that will probably change the peak sample value and so the required normalization gain. You can handle that by scanning the min and max sample values (rather than absolute peak), then subtract the DC offset from both values and use the greater absolute value in the normalization.

devid_88

  • Posts: 7
Re: normalization and Remove DC Offset
« Reply #2 on: 8 Jun '21 - 07:03 »
Do you already have the DC offset value and just want to remove it? If so, you should subtract it from each sample. I'm not a Delphi user myself, but perhaps like this:

Code: [Select]
     d^ := (d^ - dc) * n;

Note doing that will probably change the peak sample value and so the required normalization gain. You can handle that by scanning the min and max sample values (rather than absolute peak), then subtract the DC offset from both values and use the greater absolute value in the normalization.



Mr. Ian, do you have full code by (C or C++) ??

 :) :) :) :) :)
Thank you Mr. Ian, you helped me
Thank you very much thank you
« Last Edit: 8 Jun '21 - 08:20 by devid_88 »

Ian @ un4seen

  • Administrator
  • Posts: 23619
Re: normalization and Remove DC Offset
« Reply #3 on: 9 Jun '21 - 15:58 »
You can get the min/max values and DC offset from a block/array of sample data something like this:

Code: [Select]
float min = data[0], max = data[0];
double dc = 0;
for (int a = 0; a < datalen; a++) {
if (min > data[a]) min = data[a]; // found new min value
if (max < data[a]) max = data[a]; // found new max value
dc += data[a]; // DC sum
}
dc /= datalen; // DC offset
min -= dc; // subtract DC offset from min value
max -= dc; // subtract DC offset from max value
float peak = (abs(min) > abs(max) ? abs(min) : abs(max)); // new peak value

devid_88

  • Posts: 7
Re: normalization and Remove DC Offset
« Reply #4 on: 9 Jun '21 - 23:16 »
You can get the min/max values and DC offset from a block/array of sample data something like this:

Code: [Select]
float min = data[0], max = data[0];
double dc = 0;
for (int a = 0; a < datalen; a++) {
if (min > data[a]) min = data[a]; // found new min value
if (max < data[a]) max = data[a]; // found new max value
dc += data[a]; // DC sum
}
dc /= datalen; // DC offset
min -= dc; // subtract DC offset from min value
max -= dc; // subtract DC offset from max value
float peak = (abs(min) > abs(max) ? abs(min) : abs(max)); // new peak value


Thanks Ian the code is very good
The problem was solved by you

Thank
 :) :) :)