HISE Logo Forum
    • Categories
    • Register
    • Login

    Correlation

    Scheduled Pinned Locked Moved General Questions
    5 Posts 3 Posters 252 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • U
      udalilprofile
      last edited by

      Снимок экрана 2024-10-30 в 10.28.05.png

      Hi. I made a stereo expander. Now I need a correlator. How to make it?

      orangeO 1 Reply Last reply Reply Quote 0
      • orangeO
        orange @udalilprofile
        last edited by orange

        @udalilprofile

        This is the basic formula for the phase

        Phase = arctan(L/R)
        

        So if the phase is 45 or 225 = 1, and phase of 135 and 315 (-45) is -1.

        For your correlation meter, you need to normalize this value:

        Correlation = Phase * Magnitude
        
        Magnitude = (L^2 + R^2)^1/2
        

        So the final formula is:

        Correlation = arctan(L/R) * ((L^2 + R^2)^1/2)
        

        develop Branch / XCode 13.1
        macOS Monterey / M1 Max

        U 2 Replies Last reply Reply Quote 6
        • U
          udalilprofile @orange
          last edited by

          @оранжевый

          I want to put a correlator in my plugin. How to do this?)

          1 Reply Last reply Reply Quote 0
          • U
            udalilprofile @orange
            last edited by

            @orange
            I want to put a correlator in my plugin. How to do this?)

            M 1 Reply Last reply Reply Quote 0
            • M
              Mighty23 @udalilprofile
              last edited by

              @udalilprofile
              I tried to do it in FAUST, then the value in the UI must be made with a global_cable and draw its value in a panel.

              import("stdfaust.lib");
              
              //==============================================================================
              // CORRELATION METER
              // 
              // A stereo phase correlation meter that outputs a value between -1 and +1
              // indicating the phase relationship between left and right channels.
              //
              // +1 = fully correlated (mono)
              //  0 = fully decorrelated (wide stereo)
              // -1 = fully anti-correlated (out of phase)
              //==============================================================================
              
              // Integration time constant (in seconds) - typical range 10-100ms
              integration_time = hslider("Integration Time", 0.05, 0.01, 0.2, 0.001);
              
              // Small constant to prevent division by zero
              epsilon = 1e-10; // FAUST has a function for this but I'm lost and would like to close the implementation -.-'
              
              // Low-pass filter cutoff frequency based on integration time
              lpf_freq = 1.0 / (2.0 * ma.PI * integration_time);
              
              // Basic correlation meter implementation
              correlation_meter = _ , _ : correlation_calc
              with {
                  correlation_calc(l, r) = lr_filtered / (sqrt(l2_filtered * r2_filtered) + epsilon)
                  with {
                      // Cross-correlation term (L * R)
                      lr_filtered = (l * r) : fi.lowpass(1, lpf_freq);
                      
                      // Auto-correlation terms (L² and R²)
                      l2_filtered = (l * l) : fi.lowpass(1, lpf_freq);
                      r2_filtered = (r * r) : fi.lowpass(1, lpf_freq);
                  };
              };
              
              // Alternative implementation using sum/difference method
              correlation_meter_alt = _ , _ : correlation_calc_alt
              with {
                  correlation_calc_alt(l, r) = (sum_power - diff_power) / (sum_power + diff_power + epsilon)
                  with {
                      sum_sig = (l + r) * 0.5;
                      diff_sig = (l - r) * 0.5;
                      sum_power = (sum_sig * sum_sig) : fi.lowpass(1, lpf_freq);
                      diff_power = (diff_sig * diff_sig) : fi.lowpass(1, lpf_freq);
                  };
              };
              
              // Algorithm selector
              algorithm = nentry("Algorithm", 0, 0, 1, 1);
              
              // Main correlation calculation with algorithm selection
              correlation_calc = _ , _ <: (correlation_meter, correlation_meter_alt) : select2(algorithm);
              
              // Correlation meter with UI elements - following the vumeter pattern
              cmeter(l, r) = attach(l, correlation_calc(l, r) : hbargraph("Correlation", -1, 1)), r;
              
              // Process function - stereo input, stereo passthrough with correlation display
              process = cmeter;
              
              
              1. Two different correlation calculation:

                • Direct method using L*R / sqrt(L² * R²)
                • Sum/difference method using (S² - D²) / (S² + D²)
              2. Adjustable parameters:

                • Integration time (10ms to 200ms)
                • Algorithm selection
              3. Real-time display:

                • Horizontal bargraph showing correlation value

              As for the implementation in HISE (UI) you need to connect the hbargraph in a
              global_cable scriptnode and draw the "bar" in a panel - this is more complicated for me 😧

              Since I'm still a newbie, it would be a good idea to properly test the implementation before putting it "into production"

              Free Party, Free Tekno & Free Software too

              1 Reply Last reply Reply Quote 1
              • First post
                Last post

              26

              Online

              1.9k

              Users

              12.5k

              Topics

              108.6k

              Posts