It is currently Sat Dec 16, 2017 8:10 am

All times are UTC - 7 hours





Post new topic Reply to topic  [ 98 posts ]  Go to page Previous  1 ... 3, 4, 5, 6, 7
Author Message
PostPosted: Tue Jul 07, 2015 12:46 pm 
Offline
User avatar

Joined: Tue Dec 21, 2004 8:35 pm
Posts: 600
Location: Argentina
You are right, i clampled to [-32768, 32767] and now volume works great.
Thank you.

Edit: Sorry, im still learning. :-)

_________________
ANes


Top
 Profile  
 
PostPosted: Tue Jul 07, 2015 2:43 pm 
Offline
User avatar

Joined: Mon Dec 29, 2014 1:46 pm
Posts: 751
Location: New York, NY
Anes wrote:
You are right, i clampled to [-32768, 32767] and now volume works great.
Thank you.

Edit: Sorry, im still learning. :-)


Excellent.

Anes wrote:
Anyway i still don't understand what it's refered with "weights": can somebody explain me please??


A weight is a constant used in a sum to give some elements more or less influence on the total than others. For example, an average of 4 numbers could be expressed as (a + b + c + d) / 4, which is equivalent to 0.25 * a + 0.25 * b + 0.25 * c + 0.25 * d. Each 0.25 value is a separate weight and in a weighted-average, the values do not have to all be equal, but they still must add up to 1. Most of these filters can be expressed as weighted-averages of certain values. For instance, see the code for the simplest discrete low-pass filter here. The filter line of code is:

Code:
y[i] = a * x[i] + (1-a) * y[i-1];


a and (1-a) are the weights, which total to 1. x[i] is the latest sample, y[i] is the filtered result and y[i-1] is the prior filtered result.

For the biquad cascade IIR filters, this was used.

Code:
y[n] = b0 * x[n] + d1;       
d1 = b1 * x[n] - a1 * y[n] + d2;       
d2 = b2 * x[n] - a2 * y[n];


In this case, a1, a2, b0, b1 and b2 are the weights. y[n] is the filtered result, x[n] is the latest sample value and d1 and d2 are intermediate values that are maintained. By repeating those 3 lines above in a loop with different weights, any IIR filter can be realized. And applications like Matlab and GNU Octave can be used to compute the necessary weight values.


Top
 Profile  
 
PostPosted: Tue Jul 07, 2015 6:30 pm 
Offline
User avatar

Joined: Tue Dec 21, 2004 8:35 pm
Posts: 600
Location: Argentina
Im trying to understand and im getting closer i think, but the wiki exposes:

Code:
// Return RC low-pass filter output samples, given input samples,
 // time interval dt, and time constant RC
 function lowpass(real[0..n] x, real dt, real RC)
   var real[0..n] y
   var real α := dt / (RC + dt)
   y[0] := x[0]
   for i from 1 to n
       y[i] := α * x[i] + (1-α) * y[i-1]
   return y


It calculates "α" in the line:

Code:
   var real α := dt / (RC + dt)


RC and dt what are those values?? Searching with google it seems to be a hz value. In that case what hz values should i use??
I don't understand why it returns a "y", i tought the propouse of this pseudo-code was filling an output buffer given an input buffer.
if i have 48 float "x" array samples i should get 48 float "y" arrays.

As you can see im kinda lost.

_________________
ANes


Top
 Profile  
 
PostPosted: Tue Jul 07, 2015 6:55 pm 
Offline
User avatar

Joined: Mon Dec 29, 2014 1:46 pm
Posts: 751
Location: New York, NY
Anes wrote:
RC and dt what are those values?? Searching with google it seems to be a hz value. In that case what hz values should i use??
I don't understand why it returns a "y", i tought the propouse of this pseudo-code was filling an output buffer given an input buffer.
if i have 48 float "x" array samples i should get 48 float "y" arrays.


In the pseudocode snippet, the variable x is the input array of samples and the variable y is the output array of samples. The code does not modify the input array values. And, the input and output arrays will be the same length.

The for-loop does the filtering using 2 weights. Note that it uses y[i-1], a prior computed output sample. In the youtube video, this concept was demonstrated using time-delay blocks and taps.

Directly above the pseudocode snippet in the wiki link are some formulas you need. dt appears as delta T in those formulas. The cutoff frequency in Hz is defined as fc = 1/(2 * Pi * RC), which can be rearranged to RC = 1 / (2 * Pi * fc). Also, alpha = (2 * Pi * dt * fc) / (2 * Pi * dt * fc + 1) and fc = alpha / ((1 - alpha) * 2 * Pi * dt).

dt is the time between samples, the reciprocal of the sampling frequency (in Hz). This is just filtering code, not decimating code; as mentioned, the input and output sampling arrays are the same lengths.

Using the above formulas and definitions, the function could be rewritten to accept the input samples, the input sampling frequency and the cutoff frequency, instead of dt and RC.

Also, the function could be modified to process one sample at a time instead of array of input samples. From the input sampling frequency and the cutoff frequency, alpha can be computed ahead of time. The formula within the for-loop would be applied only once to transform a single input sample into an output sample. And, the computed output sample would have to be stored for the next time the function is called (substituted in place of y[i-1]).


Top
 Profile  
 
PostPosted: Tue Jul 07, 2015 7:17 pm 
Offline
User avatar

Joined: Tue Dec 21, 2004 8:35 pm
Posts: 600
Location: Argentina
Code:
for i from 1 to n
    y[i] := α * x[i] + (1-α) * y[i-1]


so taking into account the filter part, how to i get α?

_________________
ANes


Top
 Profile  
 
PostPosted: Tue Jul 07, 2015 7:39 pm 
Offline
User avatar

Joined: Mon Dec 29, 2014 1:46 pm
Posts: 751
Location: New York, NY
zeroone wrote:
so taking into account the filter part, how to i get α?


That's alpha. See the formulas in my prior response.


Top
 Profile  
 
PostPosted: Wed Jul 08, 2015 12:13 am 
Offline
User avatar

Joined: Tue Dec 21, 2004 8:35 pm
Posts: 600
Location: Argentina
zeroone wrote:
Using the above formulas and definitions, the function could be rewritten to accept the input samples, the input sampling frequency and the cutoff frequency, instead of dt and RC.


Sorry, i don't know how to do it. It would be better to have more knowladge to make clever questions.
I preciate the time you wasted trying to make me understand this thing, but it really goes out of my "spectrum".

thxs.

_________________
ANes


Top
 Profile  
 
PostPosted: Sat Jul 11, 2015 5:05 pm 
Offline
User avatar

Joined: Mon Dec 29, 2014 1:46 pm
Posts: 751
Location: New York, NY
While testing, I ran into performance issues with denormal numbers in Java. This was resolved by setting ultra tiny values to 0. I am mentioning this to aid anyone who stumbles upon the filtering code that I posted earlier in this thread.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 98 posts ]  Go to page Previous  1 ... 3, 4, 5, 6, 7

All times are UTC - 7 hours


Who is online

Users browsing this forum: sdm and 10 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group