MATLAB Answers

0

interpolation of scatter data

Asked by Solmaz Kahourzade on 10 Apr 2019
Latest activity Commented on by John D'Errico
on 11 Apr 2019
clc
clear all
close all
%find normalized loss using NL test
load effyTest;
I=(map.Id.^2+map.Iq.^2).^0.5;
E=100*map.Pmech./map.Pelt;
Loss=map.Pelt-map.Pmech;
Rs_hot=setup.R0*(1+0.004*(map.tempCu-20));
Copper_loss=3.*Rs_hot.*I.^2/2;
P_FE=Loss-Copper_loss;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Iron Loss
figure(1)
plot(map.n,map.T,'bx-','LineWidth',1);
[cc,hh] = contourf(map.n,map.T,P_FE);
clabel(cc,hh);
axis([0 6000 0 50]);
set(gca,'XTick',[0 1000 2000 3000 4000 5000 6000]);
set(gca,'XTickLabel',{'0','1','2','3','4','5','6'},'FontSize', 12);
set(gca,'YTick',[0:5:50],'FontSize', 12);
colorbar('FontSize', 12);
% caxis([75 100]);
grid on
xlabel('Speed [kr/min]', 'FontSize', 12);
ylabel('Torque [Nm]', 'FontSize', 12);
title('Measured Non-Copper Losses [W]', 'FontSize', 12);
colormap(figure(1),jet)
% %
%%%%%%%%%%%%%%%%%%%%increasing the matrix size to 256x256%%%%%%%%%%%%%%%%%%
for i=1:24
Speed1(:,i)= linspace(min(map.n(:,i)),max(map.n(:,i)), 256);
end
for j=1:256
Speed2(j,:)= linspace(min(Speed1(j,:)),max(Speed1(j,:)), 256);
end
%%%%%%%%%%%%%%%%%%%%%increasing the torque matrix size to 256x256%%%%%%%%%%%%%%%%%%%
for j=1:24
T1 (:,j)= linspace(min(map.T(:,j)),max(map.T(:,j)), 256);
end
for i=1:256
T2 (i,:)= interp1(Speed1(i,:),T1(i,:),Speed2(i,:)) ;
end
figure(3)
plot (Speed2,T2, 'r')
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for i=1:24
loss1(:,i)= linspace(min(P_FE(:,i)),max(P_FE(:,i)), 256);
end
F = clc
clear all
close all
%find normalized loss using NL test
load effyTest;
I=(map.Id.^2+map.Iq.^2).^0.5;
E=100*map.Pmech./map.Pelt;
Loss=map.Pelt-map.Pmech;
Rs_hot=setup.R0*(1+0.004*(map.tempCu-20));
Copper_loss=3.*Rs_hot.*I.^2/2;
P_FE=Loss-Copper_loss;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Iron Loss
figure(1)
plot(map.n,map.T,'bx-','LineWidth',1);
[cc,hh] = contourf(map.n,map.T,P_FE);
clabel(cc,hh);
axis([0 6000 0 50]);
set(gca,'XTick',[0 1000 2000 3000 4000 5000 6000]);
set(gca,'XTickLabel',{'0','1','2','3','4','5','6'},'FontSize', 12);
set(gca,'YTick',[0:5:50],'FontSize', 12);
colorbar('FontSize', 12);
% caxis([75 100]);
grid on
xlabel('Speed [kr/min]', 'FontSize', 12);
ylabel('Torque [Nm]', 'FontSize', 12);
title('Measured Non-Copper Losses [W]', 'FontSize', 12);
colormap(figure(1),jet)
% %
%%%%%%%%%%%%%%%%%%%%increasing the matrix size to 256x256%%%%%%%%%%%%%%%%%%
for i=1:24
Speed1(:,i)= linspace(min(map.n(:,i)),max(map.n(:,i)), 256);
end
for j=1:256
Speed2(j,:)= linspace(min(Speed1(j,:)),max(Speed1(j,:)), 256);
end
%%%%%%%%%%%%%%%%%%%%%increasing the torque matrix size to 256x256%%%%%%%%%%%%%%%%%%%
for j=1:24
T1 (:,j)= linspace(min(map.T(:,j)),max(map.T(:,j)), 256);
end
for i=1:256
T2 (i,:)= interp1(Speed1(i,:),T1(i,:),Speed2(i,:)) ;
end
figure(3)
plot (Speed2,T2, 'r')
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for i=1:24
loss1(:,i)= linspace(min(P_FE(:,i)),max(P_FE(:,i)), 256);
end
F = scatteredInterpolant(map.n(:),map.T(:),P_FE(:)) ;
Iron_loss_new= F(Speed2,T2) ;
% Iron Loss
figure(4)
plot(map.n,map.T,'bx-','LineWidth',1);
[cc,hh] = contourf(Speed2,T2,Iron_loss_new);
clabel(cc,hh);
axis([0 6000 0 50]);
set(gca,'XTick',[0 1000 2000 3000 4000 5000 6000]);
set(gca,'XTickLabel',{'0','1','2','3','4','5','6'},'FontSize', 12);
set(gca,'YTick',[0:5:50],'FontSize', 12);
colorbar('FontSize', 12);
% caxis([75 100]);
grid on
xlabel('Speed [kr/min]', 'FontSize', 12);
ylabel('Torque [Nm]', 'FontSize', 12);
title('Measured Non-Copper Losses [W]', 'FontSize', 12);
colormap(figure(4),jet)scatteredInterpolant(map.n(:),map.T(:),P_FE(:)) ;
Iron_loss_new= F(Speed2,T2) ;
% Iron Loss
figure(4)
plot(map.n,map.T,'bx-','LineWidth',1);
[cc,hh] = contourf(Speed2,T2,Iron_loss_new);
clabel(cc,hh);
axis([0 6000 0 50]);
set(gca,'XTick',[0 1000 2000 3000 4000 5000 6000]);
set(gca,'XTickLabel',{'0','1','2','3','4','5','6'},'FontSize', 12);
set(gca,'YTick',[0:5:50],'FontSize', 12);
colorbar('FontSize', 12);
% caxis([75 100]);
grid on
xlabel('Speed [kr/min]', 'FontSize', 12);
ylabel('Torque [Nm]', 'FontSize', 12);
title('Measured Non-Copper Losses [W]', 'FontSize', 12);
colormap(figure(4),jet)
Dear all;
I have three matrix with the size of 20x24. I need to get the equivalent 256x256 matrix of them. the map.n and map.T matrix are almost linear but P_FE is a function of them and non-linear. I think I am not using corrcet functions as the contourplots are not matching well. I attached my codes and I appreciate if you could correct me.
Thank you,

  0 Comments

Sign in to comment.

1 Answer

Answer by John D'Errico
on 10 Apr 2019
Edited by John D'Errico
on 10 Apr 2019
 Accepted Answer

First, your original contour plot.
Next, the interpolated one.
So much noisier. Interpolation does not necessarily make things smoother. If you interpolate noisy data, expect noise to show. But you have bigger problems than just the fact that you are interpolating noise. You are also interpolating using data that folds on top of itself.
I'll verify the set you are using to interpolate describes the same domain as the set you are pushing through that scatteredInterpolant.
plot(Speed2,T2,'y.')
hold on
plot(map.n(:),map.T(:),'bo')
The yellow dots appear to be contained within the region described by the blue dots. You could have generated that finer set more easily and efficiently instead of using big loops, but that is of absolutely no relevance to what you are doing.
An imporant thing to notice however, is there seem to be a lot of blue circles piled up on top of each other along that top edge. This will cause problems when you try to interpolate near that edge.
Trying to run the code you show however, requires repairing the bugs in it.
colormap(figure(4),jet)scatteredInterpolant(map.n(:),map.T(:),P_FE(:)) ;
Anyway...
First, look at the data you are using, in terms of the surface you never seem to have looked at.
surf(map.n,map.T,P_FE)
The z-axis is now P_FE. I've rotated it to show the surface is not that nasty looking, though it is not a flat surface. BUT that it is indeed noisy, and that it seems to roll over near that curved boundary. You can see the noise in the surface by looking at the extent the lines plotted are nice smooth curves. Along that bottom edge, for example, you can see the bumps. Then in the lower right hand corner, there is a rather massive joggle.
We can see where much of the noise arises however, by looking at your data arrays.
surf(diff(map.T))
Remember, this is a plot of the differences of the T array. I've rotated it around. The stuff on top in the yellow? Those are all roughly uniform differences of around 247. Bumpy, noisy, but essentially ok. It will cause joggles when you interpolate there though. The stuff in blue at the bottom however oscillates positive and negative, random garbage. This is the stuff that lies right along the top curved edge of my first plot. Those points are all piled on top of each other. However, when you use them to interpolate? Now you get random garbage anywhere near that edge, because you are intepolating random noise.
We can see the random noise in a different way, from the next figure I show.
surf(diff(map.n,[],1))
These differences tell us that along this axis of your data, that variable is essentially random noise, instead of being constant. However, that confuses the interpolation, since it is looking for information in your data.
Remember that a scatteredInterpolant takes in your data with absolutely NO information about connectivity. That is, when you create F, you do it as:
F = scatteredInterpolant(map.n(:),map.T(:),P_FE(:)) ;
so all it sees is a jumbled list of scattered points in space. The noise in that data means the data becomes folded upon itself in random ways.
Now, let me look at T. Look carefully at the stuff in that region where all of your data is rolled up tight along the edge.
surf(map.T)
That part in the right corner, where T rolls off nice and smoothly beyond the curved edge? Those points are now confused with the rest of the data, because those values of T are right in the middle of the "good" data. n is actually well behaved. Rotated similarly, lets look at n.
surf(map.n)
Perhaps now you see the issue. The surface is folded on top of itself. The data in that corner, where things seem to fall off a cliff causes problems. How might I try to fix this?
First, I would replace the junk in that corner with NaNs. We can locate that using a simple test.
diff(map.T,[],1) < 0.25
ans =
19×24 logical array
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1
0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1
0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1
0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1
0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1
0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1
0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Now do this:
badT = [false(1,24);diff(map.T,[],1) < 0.25];
Tnew = map.T;
Tnew(badT) = NaN;
surf(Tnew)
and recreate your scatteredInterpolant.
goodT = ~badT;
F = scatteredInterpolant(map.n(goodT),map.T(goodT),P_FE(goodT));
Now, if I recreate your filled contour plot, things get a little better, because I tossed a lot of the crap in the bit bucket.
Next, there is the issue of using noisy data to then be interpolated. Would a slightly smoother interpolat have helped?
F = scatteredInterpolant(map.n(goodT),map.T(goodT),P_FE(goodT),'natural') ;
The result gets rid of some of the worst junk andbumps, but creates at least one new bump.
I think perhaps you are interpolating your noisy data, thinking you would get a nice, smooth, well behaved thing? Interpolating noise just creates worse noise. It does not improve what you have. Information content is never increased in such an operation. Perhaps, if you tried to smooth your data FIRST, that might help, because a smooth uses local information in your data to reduce the noise, based on the assumption that the underlying relationship is a smooth one.

  1 Comment

John D'Errico
on 11 Apr 2019
Please use comments, not answers to make a comment. Moved to acomment:
"Dear John,
Thank you so much for the detailed and specific analysis. Your suggestion resolve the noise issue to a great extent.
The reason that I wanted to create the larger size matrix was not to remove the noise of the 20x24 matrix. The initial matrix is the test result and the input of my simulation program should be a matrix with the size of 256x256. It is impossible to test my system for these points so the only solution is interpolation of the measured data. As it is a real machine, the points near top should lay on top of each other and removing them is not an option. But I expected to get a smoother curve which I can see it is not possible.
I appreciate your time."

Sign in to comment.