Multiplying complex vector with its complex conjugate results in complex vector

30 visualizaciones (últimos 30 días)
Hi,
Within a scrip I am multiplying a complex vector (added in dataset.mat) with its complex conjugate.
I.idmPSD_LT=idmLSD_LT.*conj(idmLSD_LT);
Now I expect my result to be real, as it is in for example
A=(1+2i)*(1-2i);
gives real 5. However the resulting vector is partly purely real(idx65:299968) and partly real and complex (and partly stuffed with NaN). For the complex part, Matlab displays x+0i. I can offcourse solve this by taking the real part of the vector, but I am wondering if anyone knows what causes this resulting vector to be complex. Does someone know this?
  1 comentario
Mathieu NOE
Mathieu NOE el 7 de Mayo de 2021
hello
this is simply because your data vector contains NaN complex values - that will not give a "real" NaN output
remove first the NaN, do the product and then you get a real output
all the best

Iniciar sesión para comentar.

Respuesta aceptada

Abhishek
Abhishek el 2 de Sept. de 2025 a las 4:10
Hello @DdeR,
The output is complex because the input vector idmLSD_LT contains NaN values. Any calculation involving a complex NaN (of the form “NaN + NaNi”) will produce a complex NaN as a result. Such entries should be removed before performing the calculation.
In MATLAB, you can remove the NaNs with the help ofisnan()” function and “~” operator. Create a new vector that would only contain non-NaN elements.
idmLSD_LT_clean = idmLSD_LT(~isnan(idmLSD_LT));
Then perform the operation on the new vector:
I.idmPSD_LT=idmLSD_LT_clean.*conj(idmLSD_LT_clean);
I tried this approach on the data posted in the question on MATLAB R2025a and got the expected results.
You can refer to the official documentation by MATLAB on “isnan()” function: https://mathworks.com/help/releases/R2025a/matlab/ref/double.isnan.html
I hope this helps.

Más respuestas (0)

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Productos


Versión

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by