Smoothing a roughly sinusoidal signal

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

Smoothing a roughly sinusoidal signal

llrjt100
Hi,

I have position data coming from a high resolution angular position sensor
and I need to improve the accuracy of the data by removing a regular
sinusoid from it.

The below graph shows three plots of angular position error against time:
<https://octave.1599824.n4.nabble.com/file/t373550/Forum.jpg>

1. The brown plot is the position error which needs to be corrected (ideal
is a zero error horizontal line).
2. The blue plot is the position error of a very high accuracy reference
angular position sensor (for testing only and not present in the deployed
application).
3. The green plot is the difference between the brown and blue plots.

Common to both the brown and blue plot is a fast in phase ~2 sec error which
can be ignored.
In the brown plot there's a ~24 sec error which I need to remove (the green
difference plot more clearly shows this as it removes the faster ~2 sec
error). The solution algorithm eventually needs to be deployed to run in
realtime on a 32 bit microcontroller.

The dataset is in .csv format which I can post for analysis.

I've Googled various examples which lead me to believe a solution to this
problem should be possible. The issue  is I don't have sufficient signal
processing experience to know how to implement a solution and would be very
grateful for any help in solving this problem.

Best wishes,
Richard




--
Sent from: https://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


Reply | Threaded
Open this post in threaded view
|

Re: Smoothing a roughly sinusoidal signal

Doug Stewart-4


On Thu, Nov 7, 2019 at 8:55 AM llrjt100 <[hidden email]> wrote:
Hi,

I have position data coming from a high resolution angular position sensor
and I need to improve the accuracy of the data by removing a regular
sinusoid from it.

The below graph shows three plots of angular position error against time:
<https://octave.1599824.n4.nabble.com/file/t373550/Forum.jpg>

1. The brown plot is the position error which needs to be corrected (ideal
is a zero error horizontal line).
2. The blue plot is the position error of a very high accuracy reference
angular position sensor (for testing only and not present in the deployed
application).
3. The green plot is the difference between the brown and blue plots.

Common to both the brown and blue plot is a fast in phase ~2 sec error which
can be ignored.
In the brown plot there's a ~24 sec error which I need to remove (the green
difference plot more clearly shows this as it removes the faster ~2 sec
error). The solution algorithm eventually needs to be deployed to run in
realtime on a 32 bit microcontroller.

The dataset is in .csv format which I can post for analysis.

I've Googled various examples which lead me to believe a solution to this
problem should be possible. The issue  is I don't have sufficient signal
processing experience to know how to implement a solution and would be very
grateful for any help in solving this problem.

Best wishes,
Richard




--
Sent from: https://octave.1599824.n4.nabble.com/Octave-General-f1599825.html





If you post your data , then I will write up a filter.


--
DASCertificate for 206392



Reply | Threaded
Open this post in threaded view
|

Re: Smoothing a roughly sinusoidal signal

llrjt100
Thank you Doug - much appreciated :-)

I've uploaded  data.csv
<https://octave.1599824.n4.nabble.com/file/t373550/data.csv>  . The data
format is as follows (only the first 6 values are relevant):

time, pos1, posErr1, pos2, posErr2, (posErr2 - posErr1), ignore, ignore

In the graph I posted, I plotted the following against time:

posErr1 (brown plot)

posErr2 (blue plot)

posErr2 - posErr1 (green plot)



--
Sent from: https://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


Reply | Threaded
Open this post in threaded view
|

RE: Smoothing a roughly sinusoidal signal

Windhorn, Allen E [ACIM/LSA/MKT]
> -----Original Message-----
> From: Help-octave <help-octave-
>
> I've uploaded  data.csv
> <https://octave.1599824.n4.nabble.com/file/t373550/data.csv>  . The data
> format is as follows (only the first 6 values are relevant):
>
> time, pos1, posErr1, pos2, posErr2, (posErr2 - posErr1), ignore, ignore

Moving average seems to work well.  There is one in the financial package, but I
found it did not suit my needs, so wrote my own:
---------------------------------------------------------------------------------------
function ym = mavg(y,m)
%MAVG Moving average of m points of y
% mavg(y,m) -- Compute moving average of y over m points
# (works better if m is odd).  For first and last m/2 points
# uses linear fit.
% At the moment, y must be a column vector of one dimension.
%
% Allen Windhorn, ECE504, Summer 1999
%
n = length(y);
if m <= 1 | n < 3                   %Pathological cases
   ym = y;                           %Return same array
   return;
end
%
if m > n,m = n;end                   %Array too short for m
mh = fix(m/2+0.01);                  %Half length of array, rounded down
mh1 = m-mh;
%Compute the end regions
ym(1) = (2*y(1)+y(2))/3;
ym(n) = (2*y(n)+y(n-1))/3;
for k = 2:mh
   ym(k) = sum(y(1:(2*k-1)))/(2*k-1);
   ym(n-k+1) = sum(y((n-2*k+2):n))/(2*k-1);
end
%
%Now compute the points in between using moving average
for k = mh+1:n-mh1+1
   ym(k) = sum(y(k-mh:k+mh1-1))/m;
end
-------------------------------------------------------------------------------------------
With the above on your path, you can do:

t = data(:,1);
u = data(:,3);
plot(t, u, t, mavg(u, 2400));  %Average over 24 seconds

Regards,
Allen


Reply | Threaded
Open this post in threaded view
|

Re: Smoothing a roughly sinusoidal signal

Doug Stewart-4
In reply to this post by llrjt100


On Thu, Nov 7, 2019 at 1:18 PM llrjt100 <[hidden email]> wrote:
Thank you Doug - much appreciated :-)

I've uploaded  data.csv
<https://octave.1599824.n4.nabble.com/file/t373550/data.csv>  . The data
format is as follows (only the first 6 values are relevant):

time, pos1, posErr1, pos2, posErr2, (posErr2 - posErr1), ignore, ignore


should pos1 and pos2 look the same? because no amount of filtering will make them the same.
Is pos1 from your equipment and pos2  the very accurate one?

 
In the graph I posted, I plotted the following against time:

posErr1 (brown plot)

posErr2 (blue plot)

posErr2 - posErr1 (green plot)



--
Sent from: https://octave.1599824.n4.nabble.com/Octave-General-f1599825.html




--
DASCertificate for 206392



Reply | Threaded
Open this post in threaded view
|

Re: Smoothing a roughly sinusoidal signal

llrjt100
pos1 and pos2 should ideally be horizontal lines through zero representing
zero position error at perfect constant velocity.

pos1 is from the equipment, and pos2 is from a high accuracy reference.



--
Sent from: https://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


Reply | Threaded
Open this post in threaded view
|

Re: Smoothing a roughly sinusoidal signal

Ian McCallion
On Fri, 8 Nov 2019 at 09:22, llrjt100 <[hidden email]> wrote:
>
> pos1 and pos2 should ideally be horizontal lines through zero representing
> zero position error at perfect constant velocity.
>
> pos1 is from the equipment, and pos2 is from a high accuracy reference.

As people have said you need a model of the system, including its
sources of error. The model state would adjust based on prior data
only and would the include frequency and phase of the cyclic
modelled-in error components, and thus would contain the needed
information to correct the data.

A Kalman filter does exactly this, and the step to step processing to
update the model is not compute-intensive (depending on model
complexity I suppose!) and because using prior data only there is no
time lag. This is why it is used in many real-time control and
monitoring situations. And incidentally, although you haven't said
what you want to do with the corrected output, if you intend to use if
in a control feedback loop the Kalman filter can help there too.

Designing a Kalman filter is tricky and I've never done it, only used
someone else's efforts. But I am pretty sure that is the place to
start.

Cheers... Ian


Reply | Threaded
Open this post in threaded view
|

Re: Smoothing a roughly sinusoidal signal

llrjt100
Thanks Ian - I had a look at Kalman filters and it's a bit scary with my
practically zero knowledge of this sort of thing. I think I'd definitely
need some help to sort it out. Do you have any idea where I could find an
engineer with suitable experience to help me out on a paid basis? (I hope
this is an appropriate question to post here - please let me know if not!)



--
Sent from: https://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


Reply | Threaded
Open this post in threaded view
|

Re: Smoothing a roughly sinusoidal signal

Ian McCallion
On Friday, 8 November 2019, llrjt100 <[hidden email]> wrote:
Thanks Ian - I had a look at Kalman filters and it's a bit scary with my
practically zero knowledge of this sort of thing. I think I'd definitely
need some help to sort it out. Do you have any idea where I could find an
engineer with suitable experience to help me out on a paid basis? (I hope
this is an appropriate question to post here - please let me know if not!)

Hi Robert,

I don't know anyone who could help.

Maybe you have already received an offer as a result of your post to this list but if not I'd go through the normal job market channels. From a quick google of astrotrac it sounds like there might be an ongoing requirement for a control systems engineer anyway. Good luck!

Ian