Problem with Karhunen-Loève expansion in matlab

• MATLAB
• confused_engineer
In summary, The conversation is about performing the KL expansion in Matlab and calculating the zero-mean uncorrelated random variables. The code from the official Matlab forums is being used and the results are being compared to the theoretical values. The eigenvectors and eigenvalues are also being checked for orthogonality. However, when calculating the means, they are not zero as expected. The speaker is seeking assistance in identifying the error in their process.
confused_engineer
TL;DR Summary
I want to perform the KL expansion in Matlab, but I cannot calculate the zero-mean uncorrelated random variables
I have copied the code of the accepted answer to this post in the official Matlab forums, since I am interested in performing the KL expansion myself.

Calculation of random variables:
clc

clear all

y=[1,2,4;2,3,10];

y=y' %Reasons for transposing will become clear when you will read the second point given below.

[V,D]=eig(cov(y))

KLT = V' * y';

As far as I understand, the vector defined in the last line, KLT are the uncorrelated random variables. The eigenvectors are certainly orthnormal since

orthonormal eigenvectors:
V(:,2)'* V(:,1) %Eigenvectors
returns zero and

orthonormal eigenvectors2:
V(:,2)'* V(:,2)
returns one.

Also,
orthogonal RV:
cov(KLT')

returns orthogonal results and

variance:
var(KLT')
are the eigenvalues. However, if I writethe means aren't zero, as the theory says.

Can someone please tell me what am I doing wrong?

Best regards.
Confused Engineer.

confused_engineer said:
However, if I writethe means aren't zero, as the theory says.

If you write... what? Exactly?

confused_engineer said:
Summary:: I want to perform the KL expansion in Matlab, but I cannot calculate the zero-mean uncorrelated random variables

I have copied the code of the accepted answer to this post in the official Matlab forums, since I am interested in performing the KL expansion myself.

Calculation of random variables:
clc

clear all

y=[1,2,4;2,3,10];

y=y' %Reasons for transposing will become clear when you will read the second point given below.

[V,D]=eig(cov(y))

KLT = V' * y';

As far as I understand, the vector defined in the last line, KLT are the uncorrelated random variables. The eigenvectors are certainly orthnormal since

orthonormal eigenvectors:
V(:,2)'* V(:,1) %Eigenvectors
returns zero and

orthonormal eigenvectors2:
V(:,2)'* V(:,2)
returns one.

Also,
orthogonal RV:
cov(KLT')

returns orthogonal results and

variance:
var(KLT')
are the eigenvalues. However, if I writethe means aren't zero, as the theory says.

Can someone please tell me what am I doing wrong?

Best regards.
Confused Engineer.

Arjan82 said:
If you write... what? Exactly?
Sorry, if I write mean(KLT')

What is Karhunen-Loève expansion?

Karhunen-Loève expansion is a mathematical technique that is used to approximate a function or signal by projecting it onto a set of orthogonal basis functions. It is commonly used in signal processing and data analysis.

Why is there a problem with using Karhunen-Loève expansion in Matlab?

The main problem with using Karhunen-Loève expansion in Matlab is that it requires a large amount of computational resources and can be computationally expensive. This is because the expansion involves calculating eigenvalues and eigenvectors, which can be time-consuming for large datasets.

How can I overcome the problem with Karhunen-Loève expansion in Matlab?

One way to overcome the problem is to use parallel computing techniques, such as using multiple processors or GPUs, to speed up the calculations. Another approach is to use a more efficient implementation of the algorithm, such as the SVD-based method.

Can I use other software or programming languages for Karhunen-Loève expansion instead of Matlab?

Yes, there are other software and programming languages that can be used for Karhunen-Loève expansion, such as Python, R, and Julia. These languages may have more efficient implementations of the algorithm or offer better parallel computing capabilities.

Is Karhunen-Loève expansion the best method for signal processing and data analysis?

Karhunen-Loève expansion is a widely used method for signal processing and data analysis, but it may not always be the best choice for every situation. It is important to consider the specific characteristics of your data and the goals of your analysis before deciding on the most suitable method.

Replies
1
Views
1K
Replies
2
Views
3K
Replies
2
Views
3K
Replies
6
Views
3K
Replies
1
Views
860
Replies
1
Views
2K
Replies
1
Views
848
Replies
1
Views
1K
Replies
1
Views
1K
Replies
1
Views
4K