How to decrease matrix dimension and keep maximum details by using interp1 or other functions?
4 views (last 30 days)
Show older comments
Hello all,
I'm currently being stuck on an interpolation problem which is a small part of bigger program. I have a matrix of Lar which has size of [1*46] and another matrix (call it airgap) with [1*360] points. I must multiply these two matrixes and put it in a bigger matrix which only accept a matrix with a dimension of [1*46]. My problem is here, I can use interp1 and change the size of Lar from [1*46] to [1*360] but I need to have matrix with a dimension of [1*46]. When again use interp1 to change the dimension to [1*46] since airgap matrix has many details, interp1 doesn’t work at all. Any idea how can I solve this problem?
This is matrix Lar:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/149770/image.jpeg)
This is matrix airgap:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/149771/image.jpeg)
shift=0:2*pi/45:2*pi;
phi = 0:2*pi/359:2*pi;
new_Lar_points = interp1(shift,Lar,phi);
a=new_Lar_points.*airgap;
a:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/149772/image.jpeg)
Using the interp1 for second time to return the matrix to [1*46] dimension:
Lar2 = interp1(phi,a,shift);
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/149774/image.jpeg)
2 Comments
Walter Roberson
on 5 May 2015
Note that as your Lar and phi are periodic, you should adjust to avoid transients at the boundary. Copy the last element before the first, and copy the first element after the last, do the work giving you a 1+46+1 long result, and then discard the first and last.
Walter Roberson
on 5 May 2015
This is not my area of study, but I wonder whether what you are doing is equivalent to a circular convolution?
Answers (2)
Walter Roberson
on 6 May 2015
Edited: Walter Roberson
on 6 May 2015
The desired output is not well defined.
You have a very jumpy vector, "a", and you are asking to interpolate it. But what should that look like?
The call you are using to interp1() is doing linear interpolation. You are effectively getting subsampling or weighted average of adjacent samples that might be very different: that is what leads to the ragged edges in the output.
You might do better if you use 'pchip' or 'spline' interpolation, but again you are going to end up being grossly affected by local features, I suspect.
Is your airgap really a high frequency sine wave? I cannot tell from the plot whether it is "flat" on top and bottom as a drawing artifact or if there are samples very close together there, such as if you are representing a comb filter. And if there are deliberately little differences in the amplitudes, if the matrix is not representing a periodic waveform, then I cannot see that visually in that plot.
I have a suspicion that the fft approach would fit your problem well, at least on a theoretical standpoint. There might be discrete convolution such as FIR that produces the same results, but I suspect that with the fft you will feel more comfortable that you are getting out "the best results possible under the circumstances". But using the fft representation does carry with it the implication that your Lar matrix is intended to represent a periodic condition.
Once you have the fft representation of the convolution, to get your output Lar2 you would use ifft() with length(Lar) as the second parameter to achieve the interpolation back to a vector the same size as Lar.
0 Comments
Babak
on 6 May 2015
1 Comment
Walter Roberson
on 6 May 2015
Edited: Walter Roberson
on 6 May 2015
With both the airgap and Lar being periodic, circular convolution should be appropriate. The theoretic foundation at http://www.mathworks.com/help/signal/ug/linear-and-circular-convolution.html for two vectors of different lengths should do. You could use the fft approach, see wikipedia or you could use the FIR approach as given on the Mathworks page; they should be equivalent.
I expect that you will still end up pretty unhappy with the result, but at least you would have used a theoretic approach that assures you that you really can't do any better. If nothing else that will stop you from trying to find "more accurate" ways.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!