Cave Story Tribute Site Forums

Wedge of Cheese
Wedge of Cheese
A 6 chord is just a major chord with an extra note added a major 6th above the root. So G6 would be G-B-D-E. And nao for sum postathon.
Wedge of Cheese
Wedge of Cheese
Unless there's some really obvious slick mathematical trick I'm missing, it turns out to be easier to prove that S is distributive over addition using the discrete representation rather than the continuous one. For our purposes, we'll consider the two interchangeable, since the only real different is whether delta t is infinitely small or just very small but not infinitely so.

Recall that the discrete formulation of S is:
<span rel='lightbox'><img src='http://latex.codecogs.com/gif.latex?S(f)(t)=S(f)(t-\Delta t)+(f(t)-S(f)(t-\Delta t))\cdot k' alt='Posted Image' class='bbc_img' /></span>
Wedge of Cheese
Wedge of Cheese
Yay, the LaTeX worked! <img src='http://www.cavestory.org/forums/public/style_emoticons/<#EMO_DIR#>/grin2.gif' class='bbc_emoticon' alt=':D' />

Anyways, we can now inductively prove that S is distributive over addition.

Suppose f, g, and h are functions over the real numbers where f(x)=g(x)+h(x) and let's just assume that S(f)(0)=S(g)(0)+S(h)(0) (we can do this since S is basically an indefinite integral, so it can start wherever we want it to). Now, we must simply prove that, if S(f)(t-delta_t)=S(g)(t-delta_t)+S(h)(t-delta_t), then S(f)(t)=S(g)(t)+S(h)(t). This turns out to be very simple. We start with the equation in the image in the previous comment, substitute each f(t) and S(f)(t-delta_t) with its respective sum, distribute the multiplication by k, rearrange the terms a bit (so all the gs are together and all the hs are together), and, by applying the definition of S in reverse, we get S(f)(t)=S(g)(t)+S(h)(t).

Now we must also prove that the transformation of a sine wave is a sine wave with the same frequency. This time, we'll use the continuous formulation of S:
<span rel='lightbox'><img src='http://latex.codecogs.com/gif.latex?\frac{\mathrm{d} }{\mathrm{d} t}S(f)(t)=(f(t)-S(f)(t))\cdot K' alt='Posted Image' class='bbc_img' /></span>

let f(t)=a*sin(w*t+p)

I'm going to replace f(t) with that formula and also replace all "S(f)(t)" with just S for the sake of brevity.

<span rel='lightbox'><img src='http://latex.codecogs.com/gif.latex?\frac{\mathrm{dS}}{\mathrm{d}t}=(a\cdot sin(\omega\cdot t+p)-S)\cdot K' alt='Posted Image' class='bbc_img' /></span>
Wedge of Cheese
Wedge of Cheese
Oops, I probably shouldn't have put that S inside that mathrm, in fact I could have just omitted the mathrm entirely, but whatevs.

Anyway, we solve the diffEQ by separating the variables and integrating, but first, recall when I said:<p class='citation'>Quote</p><div class="blockquote"><div class='quote'>Let's define K to equal k/delta_t</div></div> and plug that in for K:

<span rel='lightbox'><img src='http://latex.codecogs.com/gif.latex?\frac{dS}{dt}=\frac{(a\cdot sin(\omega\cdot t+p))\cdot k}{dt}' alt='Posted Image' class='bbc_img' /></span>
Wedge of Cheese
Wedge of Cheese
Oh shit, I left out the S. That was supposed to say:
<span rel='lightbox'><img src='http://latex.codecogs.com/gif.latex?\frac{dS}{dt}=\frac{(a\cdot sin(\omega\cdot t+p)+S)\cdot k}{dt}' alt='Posted Image' class='bbc_img' /></span>
Wedge of Cheese
Wedge of Cheese
Actually scratch all that, I have solved that diffeq by hand before, but I can't remember how I did it. Wolfram says the solution is:

<span rel='lightbox'><img src='http://latex.codecogs.com/gif.latex?S=C\cdot e^{K\cdot t}-\frac{a\cdot K\cdot (K\cdot sin(\omega\cdot t+p)+\omega\cdot cos(\omega\cdot t+p))}{K^{2}+\omega^{2}}' alt='Posted Image' class='bbc_img' /></span>
Wedge of Cheese
Wedge of Cheese
Actually, that's also incorrect, I typed a plus instead of a minus into wolfram. The correct answer is:

<span rel='lightbox'><img src='http://latex.codecogs.com/gif.latex?S=C\cdot e^{-K\cdot t}+\frac{a\cdot K\cdot (K\cdot sin(\omega\cdot t+p)-\omega\cdot cos(\omega\cdot t+p))}{K^{2}+\omega^{2}}' alt='Posted Image' class='bbc_img' /></span>
Wedge of Cheese
Wedge of Cheese
Anyway, we'll assume that C is zero, since, as I pointed out before, we can start wherever we want. In practice, this isn't completely true, but even so, notice that as t gets larger, the C term approaches zero anyway (that was my main tipoff for the first one being wrong).

The rest of the solution boils down to a sine wave with the same frequency as the original, but a different phase and amplitude, just as we were trying to prove. Let's look at what the new phase and amplitude are relative to the original:

We have a sine wave with amplitude a*K*K/(K^2+w^2) and phase p
We have a cosine wave with amplitude -a*K*w/(K^2+w^2) and phase p
A cosine wave with negative amplitude a and phase p is the same as a sine wave with amplitude |a| and phase p-pi/2, so the sine/cosine combination can be rewritten as 2 sine waves:

one has amplitude a*K*K/(K^2+w^2) and phase p
the other has amplitude a*K*w/(K^2+w^2) and phase p-pi/2

Now, let's think of these as being relative to the original rather than absolute (which amounts to dividing the amplitude by that of the original (a) and subtract from the phase that of the original (p)):

the first is K*K/(K^2+w^2) times the amp of the original and in phase with the original
the second is K*w/(K^2+w^2) times the amp of the original and -pi/2 radians out of phase with the original

Since the two are 90 degrees out of phase with each other, their combined amplitude is simply the square root of the sum of the squares of their individual amplitudes:

sqrt((K*K/(K^2+w^2))^2+(K*w/(K^2+w^2))^2)
K*sqrt(K^2+w^2)/(K^2+w^2)
K/sqrt(K^2+w^2)

So, to summarize S is a filter, and, if f is a sine wave with angular velocity w (frequency w/(2*pi)), then S(f) has K/sqrt(K^2+w^2) times the amplitude of f. We could do a similar thing with phase, but that's not so important.
Wedge of Cheese
Wedge of Cheese
I will conclude by explaining the significance of a transformation S with these two features:

1) it's distributive over addition (S(f+g)=S(f)+S(g))
2) the transformation of a sine wave is a sine wave with the same frequency (but not necessarily the same amplitude or phase)

If we think of an audio stream has essentially a bunch of sine waves added together, then performing the transformation S on an audio stream will adjust each of these sine waves independently of each other. Furthermore, since it doesn't change their frequency, the pitch of the audio stream will not be altered at all, only the relative loudness of various parts of the spectrum.

The particular transformation we've been looking at in so much detail so far is just one of infinitely many such transformations. Another one is the sinc filter I described in the "orgs in Java" thread. There's just one other that I will be explaining to you soon.

Since there are infinitely many transformations S with those two properties, we should have a name other than S for the one we've been looking at so far. Notice that, in the formula K/sqrt(K^2+w^2), which is known as the "frequency response function" of the filter (technically, I guess it should be called the "angular velocity response function" since it uses the angular velocity variable w, rather than the frequency variable f), as w gets larger, K/sqrt(K^2+w^2) gets smaller, meaning that low frequencies pass more freely through the filter than high ones, so we call it a "low pass filter". It is certainly not the only low pass filter, but it's the only one we'll be looking at for now, so if I just say "the low pass filter" without further specificity, it's the one I'm talking about.
Lace
Lace
cool!
the lack of editing is a mite annoying though :[
Wedge of Cheese
Wedge of Cheese
Alright, since csrp2 with updated lunar eclipse is taking forever to upload, I might as well continue the postathon.
Wedge of Cheese
Wedge of Cheese
The other filter we're looking at is the "complimentary filter" to the low pass filter, and is called, logically, the high pass filter. Again, it's not the only high pass filter there is, just the only one we'll be looking at. It, too, has a K value as a parameter, and, as it turns out, if you take an audio stream, put it through a low-pass and high-pass filter with the same K value, and add the results together, you get the original audio stream. In other words, LP(f)(t) + HP(f)(t) = f(t) if LP and HP have the same K value.
Wedge of Cheese
Wedge of Cheese
The differential equation which defines the high-pass filter is as follows:
<span rel='lightbox'><img src='http://latex.codecogs.com/gif.latex?\frac{d}{dt}HP(f)(t)=\frac{df}{dt}-K\cdot HP' alt='Posted Image' class='bbc_img' /></span>

I'm not going to walk through proving that it satisfies the 2 conditions for filters, or that it is in fact complimentary to the low pass filter, because I'm kinda mathed out at the moment. Do it yourself if you must.

I also will not walk through proving that its angular velocity response function is the following:

w/sqrt(K^2+w^2)

And csrp2 finished uploading, so I'm now going to abruptly stop.
Wedge of Cheese
Wedge of Cheese
tiem fur moar
Wedge of Cheese
Wedge of Cheese
We've already seen how to implement the lowpass filter in Java:

output+=(signal-output)*controller;

but let's make a couple small modifications. First, let's change the variable names:

output+=(input-output)*k;

Recall that K=k/delta_t, so k=K*delta_t. Furthermore, delta_t is just the reciprocal of the sampling rate, so:

output+=(input-output)*K/samplingRate;

Yes, I know you're not supposed to start variable names with capital letters in Java, but the K is just a placeholder, as we'll see later. For now, let's look at the highpass filter.

First, let's take the diffEQ for the HP filter and put it in discrete form (using deltas instead of differentials), and multiply both sides by delta_t:

delta_output=delta_input-(k/delta_t)*output*delta_t

We cancel the delta_ts and rewrite what's left in Java notation:

output+=(input-prevInput)-k*output;
prevInput=input;

finally, we replace the k with K/samplingRate as we did with the LP filter:

output+=(input-prevInput)-K*output/samplingRate;
prevInput=input;
Wedge of Cheese
Wedge of Cheese
Notice that, if K and w are equal, then the angular velocity response functions of the lowpass and highpass filters are equal. If K is greater, then that of the lowpass is greater, and if w is greater, then that of the highpass is greater. We're going to call the point at which they're equal the "cutoff frequency" of the filters, and that point is the point at which K=w. Recall that w=2*pi*f. We can therefore calculate the value of K based on the cutoff frequency f like so: K=2*pi*f

Plugging this in to our Java code we get:

//lowpass
output+=(input-output)*2*Math.PI*cutoffFreq/samplingRate;

//highpass
output+=(input-prevInput)-2*Math.PI*cutoffFreq*output/samplingRate;
prevInput=input;
Top