playMaker

Author Topic: Float low pass filter  (Read 3052 times)

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 12342
  • Official Playmaker Support
    • View Profile
Float low pass filter
« on: December 24, 2012, 02:19:29 AM »
Hi,

 After a request, please find a float low pass filter action.

you can download it here or directly from the Ecosystem


bye,

 Jean
« Last Edit: November 11, 2016, 02:19:11 AM by jeanfabre »

dasbin

  • Junior Playmaker
  • **
  • Posts: 92
    • View Profile
Re: Float low pass filter
« Reply #1 on: January 05, 2013, 12:51:51 PM »
Hey, this is cool, I'm glad I found this and thanks for doing it!

Technically I think this could be called "time compression" or some such thing rather than a low-pass filter (which I believe would simply cut off values above the threshold rather than compressing them based on previous values).

Anyway, I hadn't even thought of doing this, but I can already see where it would come in handy.
« Last Edit: January 05, 2013, 12:54:17 PM by dasbin »

lh2009

  • Playmaker Newbie
  • *
  • Posts: 12
    • View Profile
Re: Float low pass filter
« Reply #2 on: March 30, 2014, 04:48:30 PM »
How is this action used, I am looking to fade from heavy low pass filtering at the beginning of a scene. I would also like to use it in a pause menu.

Thanks

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 12342
  • Official Playmaker Support
    • View Profile
Re: Float low pass filter
« Reply #3 on: March 31, 2014, 05:40:15 AM »
Hi,

 Float low pass filter is not what you want here, you need to animate a float instead.

Can you explain more about your use of the low pass filter action?

bye,

 Jean

 

lh2009

  • Playmaker Newbie
  • *
  • Posts: 12
    • View Profile
Re: Float low pass filter
« Reply #4 on: March 31, 2014, 09:55:03 AM »
Hi Jean

I have a plane with a building sitting on it. When outside the building, there is an outdoor ambience tone playing, inside the building there is a different, indoor tone.
When the players character is just inside of the building, some of the outside tone spills through.
I would like to use the low pass filter at this point, possibly gradually increasing the further inside the building the player is, to make the environment more realistic.

I hope that makes sense, thanks for your help

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 12342
  • Official Playmaker Support
    • View Profile
Re: Float low pass filter
« Reply #5 on: April 02, 2014, 04:01:15 AM »
Hi,

 not really :) how come you need the low pass filter here?
 In what way do you see the low pass filtering helping you in this situation?

 I would simply use curves and sample values on it, use the center of the building as the 0 and 1 as when outside, and the curve will be set to low the tone appropriatly.


 Bye,

 Jean

FritsLyn

  • Full Member
  • ***
  • Posts: 191
    • View Profile
Re: Float low pass filter
« Reply #6 on: July 09, 2014, 12:51:42 PM »
Hmm as far as I can tell this is not working: No matter what it just sets my float to a value of zero!

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 12342
  • Official Playmaker Support
    • View Profile
Re: Float low pass filter
« Reply #7 on: July 10, 2014, 04:52:29 AM »
Hi,

 low pass filters is only noticeable when using real data, if you try to just move a float by hand you won't really notice anything. It's meant to attenuate float hight frequency changes, typically used with accelerometer value or value coming from devices sensors.

 Bye,

 Jean

FritsLyn

  • Full Member
  • ***
  • Posts: 191
    • View Profile
Re: Float low pass filter
« Reply #8 on: July 11, 2014, 01:19:00 AM »
Thank you, I understand.

In my case I have a live data stream from an action that is 'cheating' to some data to do a fast rendering job.

This means I'm getting a float that is more or less fluidly flowing up and down with no major changes. All the sudden however the 'bad code' made to skip corners is spitting out a very different number.

Yet, I cannot get this action to spit out anything but the value zero.

So it's not that it is not noticeable - it is just setting anything and everything to 0, null, zero, nothing, false, empty.. nothing!
« Last Edit: July 11, 2014, 01:21:45 AM by FritsLyn »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 12342
  • Official Playmaker Support
    • View Profile
Re: Float low pass filter
« Reply #9 on: July 14, 2014, 04:29:48 AM »
Hi,

 I think this is the intended behavior, as your raw data doesn't have high frequency changes to iron out to begin with.

 I think you need to look at a lerp action not a low pass filter. Lerping will smooth out your value without killing the first order frequency ( your slow modulation over higher frequency around your slow modulation).

I think you should research the right math formula for your need, if you have a formula ( provided it's not using crazy derivates and integrals and all that), I can make it as an action for you.


Bye,

 Jean

tropical

  • Playmaker Newbie
  • *
  • Posts: 16
    • View Profile
Re: Float low pass filter
« Reply #10 on: November 09, 2016, 02:02:02 PM »
Hi,

_____________________

EDIT:
I think I've found it:

My question was:
Why doesn't this action work whereas the Vector3LowPassFilter-action works perfectly?

My answer:
There's a bug in the code.

Here's a line of the Vector3LowPassFilter-action (working):
Code: [Select]
filteredVector.x = (vector3Variable.Value.x * filteringFactor.Value) + (filteredVector.x * (1.0f - filteringFactor.Value));

And here the respective line of the FloatLowPassFilter-action (not working):
Code: [Select]
filteredFloat = (floatVariable.Value * filteringFactor.Value) + (floatVariable.Value * (1.0f - filteringFactor.Value));

I think 'floatVariable.Value' after the '+'-operator has to be replaced with 'filteredFloat'.
So the code should be:
Code: [Select]
filteredFloat = (floatVariable.Value * filteringFactor.Value) + (filteredFloat * (1.0f - filteringFactor.Value));

Tried and...it works.

@Jean: If I'm not wrong with this diagnosis, the action should be updated.

END EDIT
_________________


ORIGINAL POST:

although this is an old topic I'd like to ask if anyone can explain why this action brings about completely different results compared to the Vector3LowPassFilter-action. The Vector3LowPassFilter-action does its job perfectly while this FloatLowPassFilter-action doesn't seem to have any effect.

Setup 1:
I store the acceleration of my mobile device (using Unity Remote) in a Vector3-Variable with the GetDeviceAcceleration-action, then use the Vector3LowPassFilter (filtering factor 0.1), then store the y-axis as a float using GetVector3XYZ, then update the pitch of a looped AudioSource with the SetAudioPitch-action using the float variable. 'Every Frame' is checked in all actions.
Result:
The natural sudden 'jumping' value changes of the device acceleration are filtered perfectly by the vector3 low pass filter resulting in smooth audio pitch changes. Fine! (without the filter the audio pitch seems to jump between float steps)

But now...
Setup 2:
Everything the same as in Setup 1, except there is no Vector3LowPassFilter before the GetVector3XYZ-action, but a FloatLowPassFilter after it (applied to the float of the Vector3's y-axis), with the same filtering factor. So one should assume there is a similar smoothing effect.
But:
The float filter doesn't seem to have any effect. The changes of the devices accelerometer are not filtered, the audio pitch jumps between different steps - exactly the same as unfiltered.

If you look at the code of the two actions (Vector3LowPassFilter vs. FloatLowPassFilter), nothing seems to explain the different results. Correct me if I'm wrong. EDIT: Well, there is something... ;)

I tried different filtering factors, I also tried changing the FloatLowPassFilter-action using a second Float Variable to store the filtered values and apply this new float to the audio pitch. Doesn't help.

I know this is a very special issue no-one might be interested in but can anyone reproduce and explain this strange difference?

Thanks
Jojo
« Last Edit: November 10, 2016, 04:21:10 AM by tropical »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 12342
  • Official Playmaker Support
    • View Profile
Re: Float low pass filter
« Reply #11 on: November 11, 2016, 02:17:11 AM »
Hi,

 Thanks for your contribution and effort, it is totally appreciated, don't worry!  It's just very difficult to keep with it :)

updated and pushed on the Ecosystem, so now it's fixed.

Bye,

 Jean

tropical

  • Playmaker Newbie
  • *
  • Posts: 16
    • View Profile
Re: Float low pass filter
« Reply #12 on: November 12, 2016, 03:50:03 AM »
Thanks, Jean!  :)