Can't get better interpolation at some points
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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');
hold on;
plot(abs(a21_complx), Gain, ':*', 'DisplayName', 'System\_Gain\_Selected');
legend('show'); % Displays the legend with the DisplayName labels
title('(Default) Linear Interpolation');
grid on;
legend('Location', 'best')
4 Kommentare
Walter Roberson
am 15 Aug. 2024
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.
Antworten (1)
nick
am 16 Aug. 2024
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!
0 Kommentare
Siehe auch
Kategorien
Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!