logo
down
shadow

Calculating Cross Correlation


Calculating Cross Correlation

By : Rafa Ballesteros
Date : November 21 2020, 11:01 PM
around this issue I am trying to calculate cross-correlation between two signals in time and frequency domain.I got a different result for both cases. , This is caused by aliasing. Please try below code.
code :
clear;
  clc;
  N=4000;
  Fs=1000; 
  a1_normalized_frequency=0.1; 
  b1_normalized_frequency=0.3; 
  a1_amplitude=1;
  b1_amplitude=0.5;
  time=0:1/Fs:4;
  a1_frequency=Fs*a1_normalized_frequency;
  b1_frequency=Fs*b1_normalized_frequency;
  A=[zeros(1,length(time)) a1_amplitude*sin(2*pi*a1_frequency*time)+b1_amplitude*sin(2*pi*b1_frequency*time) zeros(1,length(time))];
  Y=randn(1,length(A))+A;
  Cross_Correlation_Time_domain=xcorr(A,Y);
  figure(1)
  plot(Cross_Correlation_Time_domain); 
  FFT_A=fft(A);
  FFT_Y=fft(Y);
  Multiply_FFT_A_Y=FFT_A.*FFT_Y;
  cross_correlation_frequency_domain=ifft(Multiply_FFT_A_Y);
  figure(2)
  plot(fftshift(real(cross_correlation_frequency_domain)));


Share : facebook icon twitter icon
Matlab Cross correlation vs Correlation Coefficient question

Matlab Cross correlation vs Correlation Coefficient question


By : user3163707
Date : March 29 2020, 07:55 AM
wish helps you In Matlab xcorr(x,x) gives auto-correlation of signal x. It is not scaled, it's simply a vector of inner products of the signal with shifted versions of itself. In order to scale it, use xcorr(x,x,'coeff'). This command will scale your auto-correlation by signal's energy (in other words it will divide each coefficient by value of coefficient at zero lag). Note that when you're doing cross-correlation, xcorr(x,y'coeff'), you will not get a value of 1 and zero lag, because the scaling is performed differently. It will only be 1 if you're correlating a signal with itself (I wish SO supported math formulas so that I could write it out for you).
Calculating Correlation Coefficient Between Two Files - Hex Value Histogram Correlation

Calculating Correlation Coefficient Between Two Files - Hex Value Histogram Correlation


By : P Green
Date : March 29 2020, 07:55 AM
I hope this helps you . An histogram is a graphic representation of a distribution.
A [discrete] distribution is an ordered series of the count of the number of samples of a particular value or in the case of a probability distribution, of probabilty values: the probability that a sample taken at random would have this particular value.
Computing the correlation between the auto-correlation and cross-correlation for each pair of rows in a matrix

Computing the correlation between the auto-correlation and cross-correlation for each pair of rows in a matrix


By : Kris Cochrane
Date : March 29 2020, 07:55 AM
this one helps. Make sure you set plot to FALSE for acf, ccf. Then, you can just wrap your code in a call to outer to provide every pair of i and j values. Note that since outer expects a vectorized FUN (e.g. *), we need to vectorize your function:
code :
set.seed(1)
m <- 4
n <- 10
mat <- matrix(rnorm(m*n), nrow = m, ncol=n)
lag <- 5

outer(1:nrow(mat), 1:nrow(mat),
  Vectorize(
    function(i, j) {
      acf.i <- acf(mat[i,],lag.max=lag, plot=F)
      ccf.i.j <- ccf(mat[i,],mat[j,],lag.max=lag, plot=F)    
      cor(acf.i$acf,ccf.i.j$acf[(lag+1):(2*lag+1)])
} ) )
#            [,1]        [,2]         [,3]        [,4]
# [1,]  1.0000000  0.47035200 -0.006371955 -0.85880247
# [2,]  0.4133899  1.00000000 -0.462744858 -0.13327111
# [3,] -0.3573965  0.01882691  1.000000000  0.09358042
# [4,] -0.8570117 -0.58359258  0.249930947  1.00000000
How to create a function calculating correlation/correlation matrix using J?

How to create a function calculating correlation/correlation matrix using J?


By : GreatEmperorAca
Date : March 29 2020, 07:55 AM
around this issue For practical purposes, @EelVex is right, you should use the libraries shipped with J, as they encapsulate "best practice" as JSoftware perceives it.
However, for pedagogical, intellectual, and aesthetic reasons, I am a big fan of Oleg Kobchenko's triumph:
code :
 corr =: (+/@:* % *&(+/)&.:*:)&(- +/%#) 
   c=:+/@:* % *&(+/)

   5!:4<'c'
         +- / --- +
  +- @: -+- *      
  +- %             
--+      +- *      
  +- & --+- / --- +
Cr=: +/@:*&(% +/&.:*:)&(- +/ % #)
sum             =:  +/         
of              =:  @          
the_product     =:  *          
after           =:  &          
scaling         =:  % +/&.:*:
after           =:  &          
standardizing   =:  - +/%#


corr =: sum of the_product after scaling after standardizing
   CR=: (+/@:* % *&(+/)&.:*:)&(- +/ % #)

  0j20":CR/900000000(+,:-)1+i.1000000
_1.00000000000000000000

  COR f.
(+/ % #)@:*&(- (+/ % #)) % *&(%:@(+/ % #)@:*:@:- (+/ % #))

  0j20":COR/900000000(+,:-)1+i.1000000
_1.00000000000000000000

  0j20":c/900000000(+,:-)1+i.1000000
1.00000229430253350000

  load'stats'
  0j20":corr/900000000(+,:-)1+i.1000000
_0.99999999999619615000
Calculating cross-correlation with fft returning backwards output

Calculating cross-correlation with fft returning backwards output


By : Akhil Krazzymuddlehe
Date : March 29 2020, 07:55 AM
should help you out The documentation to numpy.correlate explains this:
code :
c_{av}[k] = sum_n a[n+k] * conj(v[n])
c'_{av}[k] = sum_n a[n] conj(v[n+k])
Related Posts Related Posts :
  • Close Stateflow editor programmatically
  • Give certain values specific color in matrix with imagesc
  • Matlab: can not simplify a symbolic scalar function use subs() in a simple case
  • MATLAB copyobj reverses the order of objects?
  • matlab using evalin in parfor
  • How to show a zoomed part of a graph within a MATLAB plot?
  • Matlab replace value with zero from matrix
  • Matlab Vectorized implementation of sequence of dates and times, using a vector of dates
  • Vectorize plotting multiple lines with different colors in MATLAB?
  • Speed up coloring segments of a spline curve?
  • SVM matlab example
  • Interfacing my MATLAB R2013a with Arduino
  • MATLAB: Find all values on one date, then filter down to an hour and find average
  • MATLAB / SIMULINK: Simulate filling and emptying of a river
  • How to plot several function calls in one figure
  • MATLAB - concatenation of 3rd matrix dimension
  • How do I add documentation to a matlab package?
  • Storing/passing semi-large data in GUIDE, Matlab
  • Why doesn't Matlab `fopen` throw an exception?
  • Why does Matlab dbf-reader read certain integers wrong?
  • How to multiply a frequency in histogram by scalar
  • How to generate accurate FFT plot of guitar harmonics with only 256 data points @ 44.1khz Fs ?[Matlab]
  • Normalize each slice of a 3D matrix
  • Fast alternative to find out locations of an array using ismember in MATLAB
  • How to return answers from Matlab function in form of Symbols
  • using imfuse in Matlab to alpha blend grayscale images
  • How can I divide an interval into increasing/decreasing chirp-like lengths (MatlabR2014b)?
  • filling a zero matrix corresponding to row and column numbers
  • Pick a random one among every N elements in a vector
  • Why I got a big MSE when I try to verify convolution theorem in matlab?
  • matlab find() indices of cells for particle, 4-D double
  • Any Machine Learning Toolbox in Matlab that are Computationally Effective?
  • How to change the Value of a struct with a function in Matlab?
  • shadow
    Privacy Policy - Terms - Contact Us © soohba.com