some problem in combine smoothing of different parameter?

I have 4 matrix x=latitude, y=longitude, t=time and M= result of 1024*966 dimension want to smooth result across latitude using polynomial fit, then again want to smooth across time using cosine fit, can you please tell me how can I do?

Answers (1)

What is a cosine fit? You mean like a Fourier series?
If you want a global polynomial fit, you can take row by row and use polyfit() to smooth it. For each row (untested)
orderOfPolynomial = 4; % Whatever order you want.
M_smoothed = M; % Initialize
for rowNumber = 1 : rows
oneRow = M(rowNumber, :);
coeffs = polyfit(1:columns, oneRow, orderOfPolynomial);
smoothedData = polyval(coeffs, 1:columns);
M_smoothed(rowNumber, :) = smoothedData;
end
imshow(M_smoothed, []);
If you want a localized sliding window fit, you can use a Savitzky-Golay filter, which is done by the sgolay() function in the Signal Processing Toolbox. If you don't have that toolbox, then you'll have to write it yourself using polyfit() over short sequences inside the window at each position, or see this. I also have a demo for sgolay() if you (or anyone else) have the Signal Processing Toolbox and want a demo.

6 Comments

In polyfit at 76
Warning: Polynomial is badly conditioned. Add points with distinct X values, reduce
the degree of the polynomial, or try centering and scaling as described in HELP
POLYFIT.
> In polyfit at 76
Error using imageDisplayValidateParams
Expected input number 2, [LOW HIGH], to be non-NaN.
Error in checkDisplayRange (line 11)
validateattributes(display_range, {'numeric'},...
Error in imageDisplayValidateParams (line 57)
common_args.DisplayRange = checkDisplayRange(common_args.DisplayRange,mfilename);
Error in imageDisplayParseInputs (line 79)
common_args = imageDisplayValidateParams(common_args);
Error in imshow (line 220)
[common_args,specific_args] = ...
several errors are coming now I am not able to remove How can I ? Please tell me?
Did you look at the help for polyfit like it directed you to? See the mu and S? When it says that error, you need to use mu and S.
for k=1:4:columns
x1=A(:,k+1);
y1=A(:,k);
xx=find(y1);
xxx=max(xx);
[p S mu]= polyfit(x1(1:xxx),y2,5);
f=polyval(p,x1(1:xxx));
for l=1:xxx
A(l,k)=A(l,k)-f(l);
end
end
I have also tried this, result is coming again with the same error?
Please please please read the help. Notice that you DID NOT use S and mu when you called polyfit the second time, nor did you use S and mu when you called polyval. The help will tell you these things. That's how I learned, so I'm sure you can learn that way too.
for k=1:4:columns
x1=A(:,k+1);
y1=A(:,k);
xx=find(y1);
xxx=max(xx);
[p S mu]= polyfit(x1(1:xxx),y2,5);
f=polyval(p,x1(1:xxx));
for l=1:xxx
A(l,k)=A(l,k)-f(l);
end
end
I have also tried this and also check for less number of degree mean 3 , result is coming again with the same error?
Explain what you're doing with x1, y1, xx, and xxx. And again, you need to pass S and mu into polyval().

Sign in to comment.

Asked:

RS
on 29 Aug 2013

Community Treasure Hunt

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

Start Hunting!