Signal smoothing

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

Signal smoothing

Blaz
Hello again

This time I have a problem of signal smoothing. I have an input signal (x)
which I import from a .cvs file. It is in principle the combination of sine
wave with added exponential decay. However I would like to smooth the signal
with an exponential function (T is a time constant which is a setting) fro
mlocal tops. These tops are not always the same so simply max (x) does not
work. This is my attempt below, but it does not work properly. Any advise
appreciated.


function [xs] = smooth (t,x,T)
 
  if nargin <3
    T =0.064;                    % konstanta za glajenje Stab toka (Siemens
7SS52 Manual, str 94)
  end
  temp=0;
  f=1;
  AX=max(x);
  m=length(x);
  xs=zeros(m,1);
  lookback=10;
 
  for i = 1 : m
    u(i) = exp(-(t(i))/T);
  end
  xs(1:lookback) = x(1:lookback);
 
  for j = lookback : m
   
    if AX*u(f) < x(j)
      xs(j) = x(j);
      f=1;
    end
   
    if AX*u(f) > x(j)
      xs(j) = AX*u(f);
      f++;
    end
           
  end
 
 plot(t,x,t,xs)
endfunction

 


ex.png <https://octave.1599824.n4.nabble.com/file/t373917/ex.png>  



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


Reply | Threaded
Open this post in threaded view
|

Re: Signal smoothing

Doug Stewart-4


On Wed, Dec 30, 2020 at 1:42 AM Blaz <[hidden email]> wrote:
Hello again

This time I have a problem of signal smoothing. I have an input signal (x)
which I import from a .cvs file. It is in principle the combination of sine
wave with added exponential decay. However I would like to smooth the signal
with an exponential function (T is a time constant which is a setting) fro
mlocal tops. These tops are not always the same so simply max (x) does not
work. This is my attempt below, but it does not work properly. Any advise
appreciated.


function [xs] = smooth (t,x,T)

  if nargin <3
    T =0.064;                    % konstanta za glajenje Stab toka (Siemens
7SS52 Manual, str 94)
  end
  temp=0;
  f=1;
  AX=max(x);
  m=length(x);
  xs=zeros(m,1);
  lookback=10;

  for i = 1 : m
    u(i) = exp(-(t(i))/T);
  end
  xs(1:lookback) = x(1:lookback);

  for j = lookback : m

    if AX*u(f) < x(j)
      xs(j) = x(j);
      f=1;
    end

    if AX*u(f) > x(j)
      xs(j) = AX*u(f);
      f++;
    end

  end

 plot(t,x,t,xs)
endfunction




ex.png <https://octave.1599824.n4.nabble.com/file/t373917/ex.png



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



Are you trying to overcome noise?

--
DASCertificate for 206392



Reply | Threaded
Open this post in threaded view
|

Re: Signal smoothing

Blaz
No, but unwanted operation of the function that is based on this signal.
There are several approaches for this, one is to smooth this value.



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


Reply | Threaded
Open this post in threaded view
|

Re: Signal smoothing

Doug Stewart-4


On Wed, Dec 30, 2020 at 6:06 AM Blaz <[hidden email]> wrote:
No, but unwanted operation of the function that is based on this signal.
There are several approaches for this, one is to smooth this value.



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


A low pass filter usually is used to "smooth out" a signal.


--
DASCertificate for 206392



Reply | Threaded
Open this post in threaded view
|

Re: Signal smoothing

Blaz
Well I forgot the details, but as far as I know a Low pass filter is a
frequency domain filter. My input signal frequency is fixed though (with
minor deviations + some DC offset), yet it is important that there is no
drop to zero, nor that it restarts at local max values only.



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


Reply | Threaded
Open this post in threaded view
|

Re: Signal smoothing

Doug Stewart-4


On Wed, Dec 30, 2020 at 7:00 AM Blaz <[hidden email]> wrote:
Well I forgot the details, but as far as I know a Low pass filter is a
frequency domain filter. My input signal frequency is fixed though (with
minor deviations + some DC offset), yet it is important that there is no
drop to zero, nor that it restarts at local max values only.



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


Unless you can explain it better as to what you want, I still think a low pass filter is what you want.
A low pass filter is like doing a running average. You can do a short running average , or any length of running average.
But if you don't want a running average, then explain what you do want. :-)


--
DASCertificate for 206392



Reply | Threaded
Open this post in threaded view
|

Re: Signal smoothing

Blaz
Sure. I will try it. In the first post I have enclosed the picture of the
wanted result. I have an input vector x. (which can also have a shape of
ordinary sine wave). What I need to do is create a result signal y which
picks up local max values (peaks) and from there the value of y exponentialy
decays with the T as a time constant until the input signal x value is
smaller than y. If the input x is greater again than the exponential decayed
signal, then the resulting y takes the shape of X again. However, it is
important that the y never drops to 0 or gets lower than x and that it
strictly follows local peaks of x. Perhaps an low pass filter would do this
task or also some kind of averaging. I am enclosing the picture again.

ex.png <https://octave.1599824.n4.nabble.com/file/t373917/ex.png>  



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


Reply | Threaded
Open this post in threaded view
|

Re: Signal smoothing

Doug Stewart-4


On Wed, Dec 30, 2020 at 10:10 AM Blaz <[hidden email]> wrote:
Sure. I will try it. In the first post I have enclosed the picture of the
wanted result. I have an input vector x. (which can also have a shape of
ordinary sine wave). What I need to do is create a result signal y which
picks up local max values (peaks) and from there the value of y exponentialy
decays with the T as a time constant until the input signal x value is
smaller than y. If the input x is greater again than the exponential decayed
signal, then the resulting y takes the shape of X again. However, it is
important that the y never drops to 0 or gets lower than x and that it
strictly follows local peaks of x. Perhaps an low pass filter would do this
task or also some kind of averaging. I am enclosing the picture again.

ex.png <https://octave.1599824.n4.nabble.com/file/t373917/ex.png



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


I now understand!!
You want to model a half wave rectified signal with a decay on the held voltage to model the slope from the load current.
You have to do some "if" statements similar to what you did in the other question.



--
DASCertificate for 206392



Reply | Threaded
Open this post in threaded view
|

Re: Signal smoothing

Blaz
This post was updated on .
Here is the proper code that a Stack Overflow Member Howard Rudd proposed
(with my small update) if anyone will find it useful. Kudos Howard...

function [y] = decay(t,x,tau)
 
  if nargin <3
    tau =0.064;                          
  end
  y = zeros(1, length(t));
  y(1) = x(1);
    for i = 2:length(t)
        y(i) = max(x(i), y(i-1)*exp(-(t(i)-t(i-1))/tau));
    endfor

clf
plot(t,x,'b',t, y, 'k','linewidth',2)

endfunction



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