Android Open Source - CopresenceDataCollector Cross Correlation






From Project

Back to project page CopresenceDataCollector.

License

The source code is released under:

Copyright (c) 2014, Xiang Gao All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Re...

If you think the Android project CopresenceDataCollector listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package org.sesy.coco.datacollector.audio;
/**//ww  w .  j a v  a 2 s. c  o  m
 *      This class serves for computing the cross correlation function (CCF).
 *      The computing is done using the FFT.
 *
 *      @author siniwitt 
 */
public class CrossCorrelation {

        /** Convolution object*/
        private Convolution conv;
        
        /** array containing the lags (x-axis of the CCF)*/
        private int[] lags;
        
        /** signal 2 in reverse order*/
        private double[] sig2Reverse;
        
        /** length of the correlation*/
        private int corrLength;
        
        /** length of the signal, if the signals are of equal lengths*/
        private int sigLength = 0;
        
        /** are the signals of equal lengths*/
        private boolean isEqualLength;
        
        /**
         * Construct a CrossCorrelation object, which
         * does the cross-correlation between two input signals
         * 
         * @param sig1 first signal
         * @param sig2 second signal
         */
        public CrossCorrelation(double[] sig1, double[] sig2) {
                sig2Reverse = new double[sig2.length];
                for(int i = 0; i < sig2.length; i++){
                        sig2Reverse[i] = sig2[sig2.length - 1 - i];
                }
                
                // the computing is done using fast convolution
                conv = new Convolution(sig1, sig2Reverse);
                lags = new int[conv.getFrameSize()];
                int sig1Length = sig1.length;
                int sig2Length = sig2.length;
                corrLength = sig1Length+sig2Length-1;
                
                if(sig1Length == sig2Length){
                        isEqualLength = true;
                        sigLength = sig1Length;
                }else{
                        isEqualLength = false;
                }
                
                if(!isEqualLength){
                        int diffLength = sig1Length - sig2Length;
                        for(int i = 0; i < (sig1Length+sig2Length-1); i++)
                                lags[i] = i - sig1Length + 2 + diffLength;
                }else{
                        for(int i = 0; i < corrLength; i++)
                                lags[i] = i - sig1Length + 1;
                }
        }
        
        /**
         * @return returns the framesize of the resulting cross-correlation
         */
        public int getFrameSize() {
                return conv.getFrameSize();
        }
        
        /**
         * @return returns the lags corresponding to the resulting
         * cross-correlation 
         */
        public int[] getLags(){
                return lags;
        }

        /**
         * Computes the Crosscorrelation using the FFT
         */
        public void getCCF(double[] ccf) {
                conv.computeResult(ccf);
                
                /*if(isEqualLength){
                        //normalizing like MATLABs xcorr 'unbiased' option
                        for(int i = 0; i < ccf.length; i++)
                                ccf[i] /= (double)(sigLength - Math.abs(lags[i]));
                } */
        }
        
}




Java Source Code List

org.sesy.coco.datacollector.ARPWorker.java
org.sesy.coco.datacollector.AlarmService.java
org.sesy.coco.datacollector.AppLauncher.java
org.sesy.coco.datacollector.AudioProc.java
org.sesy.coco.datacollector.AudioWorker.java
org.sesy.coco.datacollector.BindActivity.java
org.sesy.coco.datacollector.BluetoothWorker.java
org.sesy.coco.datacollector.CellWorker.java
org.sesy.coco.datacollector.Constants.java
org.sesy.coco.datacollector.DaemonService.java
org.sesy.coco.datacollector.DataMonitor.java
org.sesy.coco.datacollector.GpsWorker.java
org.sesy.coco.datacollector.HelpActivity.java
org.sesy.coco.datacollector.MainActivity.java
org.sesy.coco.datacollector.MyPreference.java
org.sesy.coco.datacollector.MyWidgetProvider.java
org.sesy.coco.datacollector.PluginManager.java
org.sesy.coco.datacollector.PrefManager.java
org.sesy.coco.datacollector.ReportErrActivity.java
org.sesy.coco.datacollector.SDSetupActivity.java
org.sesy.coco.datacollector.SensorActivity.java
org.sesy.coco.datacollector.SensorListener.java
org.sesy.coco.datacollector.SensordroneWorker.java
org.sesy.coco.datacollector.SettingActivity.java
org.sesy.coco.datacollector.StatusActivity.java
org.sesy.coco.datacollector.StatusManager.java
org.sesy.coco.datacollector.TriggerService.java
org.sesy.coco.datacollector.UpdateWidgetService.java
org.sesy.coco.datacollector.WifiWorker.java
org.sesy.coco.datacollector.WorkerService.java
org.sesy.coco.datacollector.audio.Convolution.java
org.sesy.coco.datacollector.audio.CrossCorrelation.java
org.sesy.coco.datacollector.audio.ExtAudioRecorder.java
org.sesy.coco.datacollector.audio.XCorrAndDistFromWav.java
org.sesy.coco.datacollector.communication.HttpFileUploader.java
org.sesy.coco.datacollector.database.Entry.java
org.sesy.coco.datacollector.file.FileHelper.java
org.sesy.coco.datacollector.log.ConfigureLog4J.java
org.sesy.coco.datacollector.net.NetInfo.java
org.sesy.coco.datacollector.plugin.PlugInterface.java
wei.mark.standout.StandOutWindow.java
wei.mark.standout.Utils.java
wei.mark.standout.WindowCache.java
wei.mark.standout.constants.StandOutFlags.java
wei.mark.standout.ui.TouchInfo.java
wei.mark.standout.ui.Window.java