Can't get better interpolation at some points

2 次查看(过去 30 天)
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