Can't get better interpolation at some points

조회 수: 2 (최근 30일)
Azam
Azam 2024년 8월 15일
답변: nick 2024년 8월 16일
Hi all,
I would be grateful if someone could help with the following matter:
I have a set of complex data called [a2norm_real and a2norm_imag (as per attached)], and another set of complex data was generated as shown in the code. I tried to achieve better interpolation for the Gain, but it fails at certain points (as per attached). No matter how many points I generate, it fails at the same place each time. I have tried different 1D and 2D interpolation methods (including the one below), but this was the best one I could achieve. Thanks!
Here is the code:
data2 = readtable('System Gain.xlsx', 'VariableNamingRule', 'preserve');
% Process the second file
a2norm_real = data2{:, 5};
a2norm_imag = data2{:, 6};
a2norm_complx = complex(a2norm_real,a2norm_imag);
Gain = complex(data2{:, 1}, data2{:, 2});
a21_mag = linspace(min(abs(a2norm_complx)),max(abs(a2norm_complx)),31).';
a21_ph = linspace(0,0,31).';
a21_complx = a21_mag.*exp(1i*pi/180.*a21_ph);
% Perform the interpolation
Interp = griddata(a2norm_real, a2norm_imag, Gain, real(a21_complx), imag(a21_complx), 'nearest');
figure;
plot(abs(a2norm_complx), Gain, 'o', 'DisplayName', 'System gain');
Warning: Imaginary parts of complex X and/or Y arguments ignored.
hold on;
plot(abs(a21_complx), Gain, ':*', 'DisplayName', 'System\_Gain\_Selected');
Warning: Imaginary parts of complex X and/or Y arguments ignored.
legend('show'); % Displays the legend with the DisplayName labels
title('(Default) Linear Interpolation');
grid on;
legend('Location', 'best')
  댓글 수: 4
Azam
Azam 2024년 8월 15일
이동: John D'Errico 2024년 8월 15일
Sorry for this oversight, the code has been updated.
Walter Roberson
Walter Roberson 2024년 8월 15일
Gain = complex(data2{:, 1}, data2{:, 2});
Inherently complex-valued.
plot(abs(a2norm_complx), Gain, 'o', 'DisplayName', 'System gain');
You are trying to plot the inherently complex value.

댓글을 달려면 로그인하십시오.

답변 (1개)

nick
nick 2024년 8월 16일
Hello Azam,
I understand that you want to interpolate the 'Gain' variable.
As @Walter Roberson mentioned, the 'plot' function is incorrectly used with the complex valued variable 'Gain'. For interpolating the 'Gain', you can use the function 'interp1' for 1-D data interpolation, as shown below :
data2 = readtable('System Gain.xlsx', 'VariableNamingRule', 'preserve');
% Process the second file
a2norm_real = data2{:, 5};
a2norm_imag = data2{:, 6};
a2norm_complx = complex(a2norm_real,a2norm_imag);
Gain = complex(data2{:, 1}, data2{:, 2});
a21_mag = linspace(min(abs(a2norm_complx)),max(abs(a2norm_complx)),31).';
a21_ph = linspace(0,0,31).';
a21_complx = a21_mag.*exp(1i*pi/180.*a21_ph);
% Perform the interpolation
InterpolatedData = interp1(abs(a2norm_complx),abs(Gain),a21_mag);
figure;
plot(abs(a2norm_complx), abs(Gain), 'o', 'DisplayName', 'System gain');
hold on;
plot(abs(a21_complx), InterpolatedData, ':*', 'DisplayName', 'System\_Gain\_Selected');
legend('show'); % Displays the legend with the DisplayName labels
title('(Default) Linear Interpolation');
grid on;
legend('Location', 'best')
It fits the 'Gain' well, as can be seen in the plot :
You may refer to the following documentation of 'interp1' function to learn more about it :
Hope this helps!

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by