1. IMPORTANT:
    We launched a new online community and this space is now closed. This community will be available as a read-only resources until further notice.
    JOIN US HERE

Trying to build a biquad filter from c?

Discussion in 'Building With Reaktor' started by markjwiggins, Mar 4, 2008.

Thread Status:
Not open for further replies.
  1. markjwiggins

    markjwiggins New Member

    Messages:
    3
    Hi!

    I am experimenting with reaktor core for a module at uni and wanted to make a low pass filter.
    I have read about digital filtering in various DSP books etc but could not get my head completely around how to translate it to core. So i looked at getting a C example and translating but still am having loads of trouble.

    I am looking at using the guide located here:
    http://music.ucsd.edu/~tre/biquad.pdf
    And trying the C example at the bottom, a shortened version:

    Code:
    // first set the coefficients based on the kind of filter and its parameters: 
    // m_fgain = gain in dB 
    // m_freq = freq of interest 
    // m_fq = Q 
    // m_ type is the filter type 
    
    w = 2.0 * PI * ((double)m_freq/(double)m_SampleRate); 
    cosw = float(cos(w)); 
    alpha = sinw/(2.0F*m_fq); 
    
    switch (m_type) {
    	case LP: // lowpass 
    	b0 = (1.0F - cosw) * 0.5F; 
    	b1 = 1.0F - cosw; 
    	b2 = (1.0F - cosw) * 0.5F; 
    	a0 = 1.0F + alpha; 
    	a1 = 2.0F * cosw; 
    	a2 = alpha - 1.0F; 
    	break; 
    }
    
    m_fa = m_foverallgain * b0/a0; 
    m_fb = m_foverallgain * b1/a0; 
    m_fc = m_foverallgain * b2/a0; 
    m_fd = a1/a0; 
    m_fe = a2/a0; 
    // now the realtime loop: 
    // fin = input sample 
    // fout = output sample 
    for (I = 0; I<buffersize; I++) 
    { 
    fin = input_buffer[I]; 
    fout = (m_fa*fin) + (m_fb*m_a1) + (m_fc*m_a2) + (m_fd*m_b1) + (m_fe*m_b2); 
    m_a2 = m_a1; 
    m_a1 = r_inr; 
    m_b2 = m_b1; 
    m_b1 = fout; 
    output_buffer[I] = fout; 
    }
    Any help where i am going wrong or how to translate this to reaktor core would be most appreciated. I have attached a core cell which i have attempted at but no luck?
    Thanks!

    //Mark
     

    Attached Files:

  2. lxint

    lxint NI Product Owner

    Messages:
    764
    your missing delays for the input, in fact its missing most of the fir part

    I am too lazy look at your structure in more detail, you can find a general biquad in the core eqs, and for another way to wire it up, ( which I prefer ) see the image attached


    for uni stuff its recommended to ask your tutors or confrates for tutoring, not folks on mailing lists- or, to consider changing courses
     

    Attached Files:

  3. kid_sputnik

    kid_sputnik NI Product Owner

    Messages:
    3,552
    take a look in the core macros. check out the filter and eq macros. if i remember correctly many are labelled as biquad filters. not that i can tell outside of the labels of the macro, my DSP skills are a few notches below minimal.

    EDIT - sorry, i see lxint mentioned the core eqs as well.
     
  4. kid_sputnik

    kid_sputnik NI Product Owner

    Messages:
    3,552
    another thing, which is just an observation, is that if you do not understand fully the DSP in the C code you are trying to recreate, you will have a very hard time porting it to core (that applies to me, i am very comfortable reading C syntax but not at all understanding how the code makes a filter).

    one particularly annoying thing to recreate in a graphical language is the for-loop. in primary mode events you can use an iterator, combined with an accumulator you can get pretty far. or, you can use recursion (event loops). for audio, you always have the unit delay inserted. this makes looped calculations in the same sample impossible. for small amounts of iterations, you can just duplicate the 'code'/modules. see the older threads floating around here about oversampling for an example.
     
Thread Status:
Not open for further replies.