Hello guys,
please read this and comment. It's about ways you can use to smooth analog process value.
I think it would be a good idea to write the filter's implemetation in Siemens STEP 7 and AB's programming software. I know there are a lot of gurus here. I myself can write STEP 7 SCL implementation, but don't think this can be very much efficient. I invite others to try to write more efficient implemetation in STL.
I'm looking forward to your feedbacks...
please read this and comment. It's about ways you can use to smooth analog process value.
I think it would be a good idea to write the filter's implemetation in Siemens STEP 7 and AB's programming software. I know there are a lot of gurus here. I myself can write STEP 7 SCL implementation, but don't think this can be very much efficient. I invite others to try to write more efficient implemetation in STL.
I'm looking forward to your feedbacks...
Code:
clear
clc
//Discrete implementation first order filter: y(n) = (Ts/T)*x(n-1) + (1-Ts/T)*y(n-1)
//Ts is sampling time
T = 2;//Filter's time constant (damping)
Ts = 0.01;//Sampling time
Tfinal = 10; //Final simulation time
N = Tfinal/Ts;
u(1 : 10) = 0;
u(11 : N) = 1;
x = u' + (rand(1,N)-0.5)/5.0; //adding scaled random values as noise
//Traditional approach assumes use of classical first order filter
//G(s)=1/(Ts+1), where T is so called damping constant
y(1) = x(1); //Initial condition
for n = 1 : (N-1)
y(n+1) = (1/T) * (Ts*x(n) + (T-Ts)*y(n));
end
t = 0 :Ts : (Tfinal-Ts);
//Plot step input and inut signal with noise added
subplot(3,1,1);
plot(t, x,'r');
xtitle('Signal with noise','Time','Magnitude');
//Plot output from the filter
subplot(3,1,2);
plot(t,y,'g');
xtitle('Classical filter','Time','Magnitude');
//Now, here is implementation of more advanced filter
Upper_limit = 0.5;
Lower_limit = 0.5;
for n = 1 : (N-1)
y(n+1) = (1/T) * (Ts*x(n) + (T-Ts)*y(n));
if (y(n+1) > x(n)+Upper_limit)
y(n+1) = x (n);
end
if (y(n+1) < x(n)-Lower_limit)
y(n+1) = x(n);
end
end
subplot(3,1,3);
plot(t,y);
xtitle('Advanced filter','Time','Magnitude');