3rd or 4th order Polynomial Fitting
12 views (last 30 days)
Show older comments
Tazen Moushumi
on 12 Mar 2021
Answered: Walter Roberson
on 13 Mar 2021
How can I solve Polynomial Fitting problem? [Input>polynomial Fitting>LMS(noise cancellation)>DCT]
x=zeros (N , 1);
d=zeros (N , 1);
for n = 1 : N
x(n) = (iTaidou_wave(n+1) .* (qTaidou_wave(n+1)-qTaidou_wave(n))- (iTaidou_wave(n+1)-iTaidou_wave(n)).* qTaidou_wave(n+1)) ./ (iTaidou_wave(n+1) + qTaidou_wave(n+1));
d0 = 1.5;
c = 3 * 10^8;
fc = 24 * 10^9;
lambda = c/fc;
% Entire movement
d(n) = ((x(n) .* lambda) ./ 4*pi) - d0;
end
% Polynomial Fitting
%Time vector
for x1 =1:0.5:5
y = d(n) * x1 ;
p = polyfit(x1,y,3);
y_fit = polyval(p,x1);
plot(x1,y,'ro',x1,y_fit)
grid on
%LMS
mu = 0.2;
lms = dsp.LMSFilter('StepSize',mu);
[y,err,wts] = lms(x1,y_fit);
1 Comment
Accepted Answer
Walter Roberson
on 13 Mar 2021
for n = 1 : N
Your n is a scalar
for x1 =1:0.5:5
Your x1 is a scalar.
y = d(n) * x1 ;
With n being a scalar, your d(n) is a scalar. And your x1 is a scalar. So your y is a scalar.
p = polyfit(x1,y,3);
Your x1 and y are scalars. So you are asking to polyfit() a single point, with a polynomial of degree 3. You cannot use polyfit() asking for degree 3 unless you are fitting at least 4 points at a time.
y_fit = polyval(p,x1);
You then ask for the value of the polynomial at the exact one point that you used for fitting data. If the polyfit worked at all, it would give the same output as you had input. That would not necessarily be the case, though, if you were fitting 5 or more points at a time, as then the coefficients found would not necessarily reconstruct the original data exactly as-is.
Perhaps what you need is
x1 = (0:N-1)/fc; %cyles divided by cycles per second gives seconds
y = d;
p = polyfit(x1,y,3);
y_fit = polyval(p,x1);
plot(x1,y,'ro',x1,y_fit)
grid on
%no loop
I do not understand the part of your code where you multiply d by a value that increases 0.5 per step. Perhaps you want
y = d .* (1:N)*0.5;
though I cannot think of any good reason you might want that.
The number of entries in your for x1 =1:0.5:5 has no relationship to the number of input points, N, so I do not understand what you are doing.
There is no point in fitting once with y=1*d then with y=1.5*d then with y=2*d and so on, as a linear multiplier would not affect the shape of your curve.
0 Comments
More Answers (0)
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!