  C RUBY-ON-RAILS MYSQL ASP.NET DEVELOPMENT RUBY .NET LINUX SQL-SERVER REGEX WINDOWS ALGORITHM ECLIPSE VISUAL-STUDIO STRING SVN PERFORMANCE APACHE-FLEX UNIT-TESTING SECURITY LINQ UNIX MATH EMAIL OOP LANGUAGE-AGNOSTIC VB6 MSBUILD # Calculating Cross Correlation  » matlab » 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)));
`````` ## 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

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

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?

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

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

By : Akhil Krazzymuddlehe
Date : March 29 2020, 07:55 AM
``````c_{av}[k] = sum_n a[n+k] * conj(v[n])
``````c'_{av}[k] = sum_n a[n] conj(v[n+k]) 