# Filtering of data in simulink

9 views (last 30 days)
Andreas Volden on 24 Nov 2014
Commented: Andreas Volden on 26 Nov 2014
Hi! I have a matlab script which solves an LSE problem of the standard form: z = theta'*phi.
Since the equation have a derivative, I filter it using a first order filter. I've implemented the filters in Simulink, and the script calls this model to obtain filtered variables. Filters has to be identical. The model uses variables from the script and is supposed to return the filtered variables. Time vector for this simulation is t=[1:3597]; The samples in delta_q_t and p_c_t are the same size(1:3597).
Problem is that my returned values don't match desired output(1x3597), they depend on the second denominator value(which is 5 is this pic). In the script i use the command: sim('model name',[1 n]); where n=3597.
Anyone who can help me? Another possibility is to add the filters straight into the script, but I'm not sure how to do this. Any help would be appreciated!
##### 2 CommentsShowHide 1 older comment
Andreas Volden on 25 Nov 2014
Edited: Andreas Volden on 25 Nov 2014
Yes, my sample time is 1s. Problem is these are given, my known data for the problem; phi and z is given from an external file.
As stated in the question, I wan't my phi and z samples to be filtered using a first order stable filter. It could be as easy as 1/1+s. Is there an easy way to implement this directly in my script? Without using Simulink at all...

John Petersen on 26 Nov 2014
A simple low pass filter (for scalar inputs - easily modified for vectors) is
y(i) = (alpha)* y(i-1) + (1-alpha)*x(i);
where alpha is between 0-1 depending on how much you want to filter. e.g. alpha = 0.99 is heavily filtered. If using an M-function block then you need to persist y or add a unit delay of y as another input. You could also do this with simulink blocks and not use a matlab function.
Andreas Volden on 26 Nov 2014
I'm not quite sure what you mean. Let me rephrase my problem if you bear with me here.
It is a least squares problem: I've got the equation k*p_dot = delta_q. Re-written into the linear parameter form of z = theta'*phi(z is p_dot, phi is delta_q and k is theta').
k is my unknown constant, I have samples for both p(not p_dot - to use derivative on p leads nowhere as the result is impossible to interpret) and delta_q. In order to get rid off p_dot I try to filter the equation by a stable filter lambda(s). The equation after laplace transform:
k(s)*p(s)*s=delta_q(s). The filter is lambda(s) and is simply set to s+1. The question is how do I implement this filter(s+1) in my equation?
All variables are vectors and sampling is [1:3597]
Thanks for your help either way!