Re: [music-dsp] proper scaling of an FFT

2015-11-04 Thread Charles Z Henry
On Wed, Nov 4, 2015 at 10:56 AM, Phil Burk  wrote:
> What is the "right" way to scale the inputs of an FFT.
>
> I have implemented some FFT functions in JSyn. The goal is to support
> spectral analysis, processing and synthesis for music applications.
>
> I would like to be able to measure the amplitude of various sinewave
> partials in the original signal. With my current scaling, if I do an FFT of
> a sine wave with amplitude 1.0 aligned with a bin then the magnitude comes
> out 1.0.
>
> magnitude = sqrt(real*real + imag*imag);
>
> Also my FFT and IFFT are inverse functions:   x==IFFT(FFT(x))
>
> My current scale factors are 2.0/M for FFT and 0.5 for IFFT. I am happy with
> this. But I see many conflicting recommendations in the literature that
> suggest I am doing it wrong.

Hi Phil,

The correct scaling factor depends on what you want to do with it.

For example: convolution

Suppose my input is a vector with a simple unit impulse at the the first index.
Then, the convolution of this signal with itself is expected to be
itself.  The spectrum of this signal is 1, everywhere.

That's not what you'd get, if you used your scaling factor 2/M on the
DFT.  The correct scaling factor for this application is 1 on the DFT
and 1/M for the IDFT.  (Try it for yourself for the DFT, and use the
CFT to explain why more generally).

Next example:  isometric fourier transform

Suppose I have a signal and I want to know how the energy is
distributed with respect to frequency.  The isometric fourier
transform has scaling factor 1/sqrt(M) on each of the DFT and IDFT.
The sum of squares of my signal (the metric) and the sum of squares of
its spectrum are identical.

Your scaling factors are perfectly fine, if what you want to do is
read the amplitude of signal components in the spectrum :)

Chuck
___
dupswapdrop: music-dsp mailing list
music-dsp@music.columbia.edu
https://lists.columbia.edu/mailman/listinfo/music-dsp


[music-dsp] proper scaling of an FFT

2015-11-04 Thread Phil Burk
What is the "right" way to scale the inputs of an FFT.

I have implemented some FFT functions in JSyn. The goal is to support
spectral analysis, processing and synthesis for music applications.

I would like to be able to measure the amplitude of various sinewave
partials in the original signal. With my current scaling, if I do an FFT of
a sine wave with amplitude 1.0 aligned with a bin then the magnitude comes
out 1.0.

magnitude = sqrt(real*real + imag*imag);

Also my FFT and IFFT are inverse functions:   x==IFFT(FFT(x))

My current scale factors are 2.0/M for FFT and 0.5 for IFFT. I am happy
with this. But I see many conflicting recommendations in the literature
that suggest I am doing it wrong.

In this MatLab forum,
http://www.mathworks.com/matlabcentral/answers/15770-scaling-the-fft-and-the-ifft
they recommend  1/M and M, or 1/sqrt(M) and sqrt(M).  They say it is
important that the product of the scale factors is 1.0. But then the IFFT
is not the exact inverse of the FFT.

Is there a "right" way or a "wrong" way or is there just "my" way?

BTW, the scaling source code is on line 126 at

https://github.com/philburk/jsyn/blob/master/src/com/softsynth/math/FourierMath.java

Thanks,
Phil Burk
___
dupswapdrop: music-dsp mailing list
music-dsp@music.columbia.edu
https://lists.columbia.edu/mailman/listinfo/music-dsp

Re: [music-dsp] how to derive spectrum of random sample-and-hold noise?

2015-11-04 Thread Theo Verelst

Ross Bencina wrote:

Hi Everyone,

Suppose that I generate a time series x[n] as follows:

 >>>
P is a constant value between 0 and 1

At each time step n (n is an integer):

r[n] = uniform_random(0, 1)
x[n] = (r[n] <= P) ? uniform_random(-1, 1) : x[n-1]

Where "(a) ? b : c" is the C ternary operator that takes on the value b if a is 
true, and
c otherwise.
<<<

What would be a good way to derive a closed-form expression for the spectrum of 
x?
(Assuming that the series is infinite.)

...


Hi, from me at the moment only some generalities that appear difficult (at any level) 
usually: if you want the Fourier transform of a "signal" in this case a sequence of 
numbers between 0 and 1 (inclusive), the interpretations are important: is this coming 
from a physical process you sampled (without much regarding Shannon), or is this some sort 
of discrete Markov chain output, where you interpret the sequence of samples zeroth order 
interpolated as an continuous signal that you take the FT of? In the last case, you'll get 
a spectrum that shows clear multiples of the "sampling frequency" and that is highly 
irregular because of the randomness, and I don't know if the FT's infinite integral of 
this signal converges and is unambiguous, you might have to prove that first.


Statistically, often a problem, this sequence of numbers is like two experiments in 
sequence, on depending on the other. The randomness of the P invoked choice still easily 
works with the norm "big numbers" approximation, clearly, but the second one, and therefor 
the result of the function prescription, has a ***dependency** which makes normal 
statistical shortcuts invalid. I don't know a proper way to give a proper and correct 
statistical analysis of the number sequence, and I am not even sure there is a infinite 
summation based proper DC average computable. Two statistical variables with a 
inter-dependency requires the use of proper summations sums or maybe Poisson sequence 
analysis, I don't recall exactly, but the dependency makes it hard to do an "easy" analysis.


It could be a problem from an electronics circuit for switched supplies or something, or 
maybe in a more restricted form it's an antenna signal processor step or something, 
usually there are more givens in these cases, analog or digital, that you might want to 
know before a proper statistical analysis can be in order, but anyhow, you could write a 
simple program and do some very large sum computations, as separate experiments a number 
of times with different random seeds or generators and see what happens, for instance if 
simulation results soon give the impression of a fixed signal average.


T.V.
___
dupswapdrop: music-dsp mailing list
music-dsp@music.columbia.edu
https://lists.columbia.edu/mailman/listinfo/music-dsp


Re: [music-dsp] how to derive spectrum of random sample-and-hold noise?

2015-11-04 Thread Ethan Duni
Yep that's the same approach I just posted :]

E

On Tue, Nov 3, 2015 at 11:48 PM, Ethan Fenn  wrote:

> How about this:
>
> For a lag of t, the probability that no new samples have been accepted is
> (1-P)^|t|.
>
> So the autocorrelation should be:
>
> AF(t) = E[x(n)x(n+t)] = (1-P)^|t| * E[x(n)^2] + (1 -
> (1-P)^|t|)*E[x(n)*x_new]
>
> The second term covers the case that a new sample has popped up, so x(n)
> and x(n+t) are uncorrelated. So, this term vanishes. The first term is
> (1/3)*(1-P)^|t|, so I reckon:
>
> AF(t) = (1/3)*(1-P)^|t|
>
> Does that make sense?
>
> -Ethan
>
>
>
>
>
> On Wed, Nov 4, 2015 at 8:21 AM, robert bristow-johnson <
> r...@audioimagination.com> wrote:
>
>>
>>
>>  Original Message 
>> Subject: Re: [music-dsp] how to derive spectrum of random sample-and-hold
>> noise?
>> From: "Ross Bencina" 
>> Date: Wed, November 4, 2015 12:22 am
>> To: r...@audioimagination.com
>> music-dsp@music.columbia.edu
>> --
>>
>>
>>
>> with mods
>>
>>
>> > Using ASDF instead of autocorrelation:
>> >
>> > let n be an arbitrary time index
>> > let t be the ASDF lag time of interest
>> >
>> > ASDF[t] = (x[n] - x[n-t])^2
>> >
>> > there are two cases:
>> >
>> > case 1, (holding): x[n-t] == x[n]
>>
>> this has probability of P^|t|
>>
>>
>>
>>
>> > case 2, (not holding) x[n-t] == uniform_random(-1, 1)
>>
>> this has probability of 1 - P^|t|
>>
>>
>> >
>> > In case 1, ASDF[t] = 0
>> > In case 2, ASDF[t] = (1/3)^2  (i think)
>>
>>
>>
>> so maybe it's
>>
>>
>>
>> ASDF[t] = 0 * P^|t|  +  (1/3)^2 * (1 - P^|t|)
>>
>>
>>
>> now the autocorrelation function (AF) is related to the ASDF as
>>
>>
>>
>> AF[t] =  mean{ x[n] * x[n-t] }
>>
>> AF[t] =  mean{ (x[n])^2 }  - (1/2)*mean{ (x[n] - x[n-t])^2 }
>>
>>
>> AF[t] =  mean{ (x[n])^2 }  - (1/2)*ASDF[t]
>>
>>
>>
>> AF[t]  =  (1/3)  -  (1/2) * (1/3)^2 * (1 - P^|t|)
>>
>>
>>
>> this doesn't quite look right to me.  somehow i was expecting  AF[t] to
>> go to zero as t goes to infinity.
>>
>>
>>
>>
>> > To get the limit of ASDF[t], weight the values of the two cases by the
>> > probability of each case case. (Which seems like a textbook waiting-time
>> > problem, but will require me to return to my textbook).
>> >
>> > Then I just need to convert the ASDF to PSD somehow.
>>
>>
>>
>>   ASDF[t] = 2*AF[0] - 2*AF[t]
>>
>>
>>
>> or
>>
>>
>>
>>   AF[t]  =  AF[0]  - (1/2)*ASDF[t]
>>
>>
>>
>>
>>
>> PSD = Fourier_Transform{ AF[t] }
>>
>>
>> > Does that seem like a reasonable approach?
>>
>>
>> it's the approach i am struggling with.   somehow, i don't like the AF i
>> get.
>>
>>
>>
>> --
>>
>>
>>
>>
>> r b-j   r...@audioimagination.com
>>
>>
>>
>>
>> "Imagination is more important than knowledge."
>>
>> ___
>> dupswapdrop: music-dsp mailing list
>> music-dsp@music.columbia.edu
>> https://lists.columbia.edu/mailman/listinfo/music-dsp
>>
>
>
> ___
> dupswapdrop: music-dsp mailing list
> music-dsp@music.columbia.edu
> https://lists.columbia.edu/mailman/listinfo/music-dsp
>
___
dupswapdrop: music-dsp mailing list
music-dsp@music.columbia.edu
https://lists.columbia.edu/mailman/listinfo/music-dsp

Re: [music-dsp] how to derive spectrum of random sample-and-hold noise?

2015-11-04 Thread Ethan Duni
It's pretty straightforward to derive the autocorrelation and psd for this
one. Let me restate it with some convenient notation. Let's say there are a
parameter P in (0,1) and 3 random processes:
r[n] i.i.d. ~U(0,1)
y[n] i.i.d. ~(some distribution with at least first and second moments
finite)
x[n] = (r[n]
wrote:

> On 4/11/2015 5:26 AM, Ethan Duni wrote:
>
>> Do you mean the literal Fourier spectrum of some realization of this
>> process, or the power spectral density? I don't think you're going to
>> get a closed-form expression for the former (it has a random component).
>>
>
> I am interested in the long-term magnitude spectrum. I had assumed
> (wrongly?) that in the limit (over an infinite length series), that the
> fourier integral would converge. And modeling in that way would be
> (slightly) more familiar to me. However, If autocorrelation or psd is the
> better way to characterize the spectra of random signals then I should
> learn about that.
>
>
> For the latter what you need to do is work out an expression for the
>> autocorrelation function of the process.
>>
> >
>
>> As far as the autocorrelation function goes you can get some hints by
>> thinking about what happens for different values of P. For P=1 you get
>> an IID uniform noise process, which will have autocorrelation equal to a
>> kronecker delta, and so psd equal to 1. For P=0 you get a constant
>> signal. If that's the zero signal, then the autocorrelation and psd are
>> both zero. If it's a non-zero signal (depends on your initial condition
>> at n=-inf) then the autocorrelation is a constant and the psd is a dirac
>> delta.Those are the extreme cases. For P in the middle, you have a
>> piecewise-constant signal where the length of each segment is given by a
>> stopping time criterion on the uniform process (and P). If you grind
>> through the math, you should end up with an autocorrelation that decays
>> down to zero, with a rate of decay related to P (the larger P, the
>> longer the decay). The FFT of that will have a similar shape, but with
>> the rate of decay inversely proportional to P (ala Heisenberg
>> Uncertainty principle).
>>
>> So in broad strokes, what you should see is a lowpass spectrum
>> parameterized by P - for P very small, you approach a flat spectrum, and
>> for P close to 1 you approach a spectrum that's all DC.
>>
>> Deriving the exact expression for the autocorrelation/spectrum is left
>> as an exercise for the reader :]
>>
>
> Ok, thanks. That gives me a place to start looking.
>
> Ross.
>
>
>
> E
>>
>> On Tue, Nov 3, 2015 at 9:42 AM, Ross Bencina > > wrote:
>>
>> Hi Everyone,
>>
>> Suppose that I generate a time series x[n] as follows:
>>
>>  >>>
>> P is a constant value between 0 and 1
>>
>> At each time step n (n is an integer):
>>
>> r[n] = uniform_random(0, 1)
>> x[n] = (r[n] <= P) ? uniform_random(-1, 1) : x[n-1]
>>
>> Where "(a) ? b : c" is the C ternary operator that takes on the
>> value b if a is true, and c otherwise.
>> <<<
>>
>> What would be a good way to derive a closed-form expression for the
>> spectrum of x? (Assuming that the series is infinite.)
>>
>>
>> I'm guessing that the answer is an integral over the spectra of
>> shifted step functions, but I don't know how to deal with the random
>> magnitude of each step, or the random onsets. Please assume that I
>> barely know how to take the Fourier transform of a step function.
>>
>> Maybe the spectrum of a train of randomly spaced, random amplitude
>> pulses is easier to model (i.e. w[n] = x[n] - x[n-1]). Either way,
>> any hints would be appreciated.
>>
>> Thanks in advance,
>>
>> Ross.
>>
> ___
> dupswapdrop: music-dsp mailing list
> music-dsp@music.columbia.edu
> https://lists.columbia.edu/mailman/listinfo/music-dsp
>
___
dupswapdrop: music-dsp mailing list
music-dsp@music.columbia.edu
https://lists.columbia.edu/mailman/listinfo/music-dsp