# How to build and use a LowPass (or HighPass) Filter in real-time in a time domain simulation?

7 visualizzazioni (ultimi 30 giorni)
Jake il 20 Feb 2024
Commentato: 영준 il 21 Feb 2024
I'm new to control aspects and have not worked with filters before. I've been reading up on the documentation provided by Matlab regarding the filters but I'm not sure if I can or know enough to implement a filter to get the desired outcome. The problem is as follows.
I'm simulating motion of a body in time-domain, where I solve ODEs in a for loop at every time step (using rk4 approach). Within the for loop at each time step, I calculate certain coefficients and use them as inputs in solving the ODEs in my rk4 scheme. One of these coefficients (say alpa) turned out to be very oscillatory with more than one frequency. Following is an illustration of that parameter.
I suppose using a filter to get rid of the noise would be the solution here. However, I don't know how to read the value of alpha at each time step, filter the noise and use the filtered alpha as an input to the ODE system. How can I go around this?
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Risposta accettata

영준 il 21 Feb 2024
Modificato: 영준 il 21 Feb 2024
The transfer function for the first LPF is represented as follows
Where, is the cut-off frequency, and S is the variable in the Laplace transform. In real-time systems, this needs to be converted to discrete time. The first-order LPF at discrete time can be simply expressed in the following form
where x[n] is the current input value,
y[n] is the current output value,
where y[n-1] is the previous output value,
α is a factor that determines the strength of the filter, and the time constant
τ and the sampling period
T to calculate it.
I think you can continue to get new inputs in this way and filter them by inputting the measured alpha value into the LPF according to the above formula. And if you adjust the cutoff frequency appropriately while simulating, you should be able to see the filtered signal with a slight delay.
I've never used latex before, so my answers may be terrible, sorry.
##### 7 CommentiMostra 5 commenti meno recentiNascondi 5 commenti meno recenti
영준 il 21 Feb 2024
I see, I see, but since we are using the results from the previous iteration, will there be a delay or phase lag in the system? -> Yes
영준 il 21 Feb 2024
The earliest filters were circuits, but even then LPFs used capacitors, meaning they had a capacitor component.

Accedi per commentare.

### Categorie

Scopri di più su Single-Rate Filters in Help Center e File Exchange

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by