Kyma Forum
  Kyma Support
  sum of spectra energy

Post New Topic  Post A Reply
profile | register | preferences | faq | search

next newest topic | next oldest topic
Author Topic:   sum of spectra energy
JonBellona
Member
posted 19 April 2015 17:13         Edit/Delete Message   Reply w/Quote

spectral_jpb.kym

 
Objective: Learning how to do samplerate processes in Kyma. DSP
Working On: Spectral Brightness
Equation is defined as (Sum of k=K to N/2 of |X(k)|) divided by (Sum of k=0 to N/2 of |X(k)|), where K is bin number.

I have a basic windowed FFT with SqrtMagnitude to calculate the energy. Now I am attempting to sum the energy over the N/2 (e.g. 512 for a 1024 window).

I was going to add the energy using a samplerate counter, and I found a samplerate counter in Pete's DSP tools. However, I get an error "the uSound class named 'CounterRamp' does not exist".

That aside, I can run a test at millisecond rate, using EventVariables, since they update at millisecond rate, not audio rate. In my attached examples, I use this in a soundToGlobalController to add energy. I think this auto updates at ms rate anyway, since a pasted sound with L updates at ms rate (page 267 of manual)

I found that BrightnessFollower object computes average spectrum, but I need to compute the sum. Not sure if using a MemoryWriter is the way to go, but then I'm back to reading this at sample rate. Just trying to wrap my head around computing a sum (of a wavetable or buffer) since the only objects I can find are Product and Divide, and the code I can seem to write is updating at control rate (ms).

(Another aside, I had trouble searching the forum for "samplerate". I found posts with this term in it, but when I searched for 'samplerate' all the results turned up was a single X.73 release post. hmm)

For more reference, I am just trying to learn basic DSP math using extraction features here: https://puredata.info/community/conventions/convention09/brent.pdf
I was able to successfully run the equation in Max/MSP using pfft~, but the purpose of my journey is to get a better understanding of how to implement in Kyma, and thus improve my overall understanding.

IP: Logged

JonBellona
Member
posted 19 April 2015 18:52         Edit/Delete Message   Reply w/Quote

spectralBrightness.kym

 
I have an update. Attached is my update test.

For calculating the Spectral Brightness, I am taking the SqRtMagnitude, splitting the signal, and multiplying one side by an envelope that would represent K bin (high pass filter). Then I am taking the two signals and Dividing by each other.

I don't think it's completely right, since these are two streaming signals, and the Spectral Equation requires a sum of energy of the FFT |X(k)|. At least I am getting values within the appropriate 0-1 range, and that is certainly a start...

IP: Logged

SSC
Administrator
posted 21 April 2015 10:49         Edit/Delete Message   Reply w/Quote
You could use the AveragingLowPassFilter and specify the Cutoff as "N samp" to get an N sample average of the input signal.

IP: Logged

gustl
Member
posted 23 April 2015 13:00         Edit/Delete Message   Reply w/Quote
Hi Jon,

I've been studying samplerate (Spectral) processing for some time now and I was asking myself the same. It is possible using the feedbackloop. To avoid clipping I suggest using something like 1/100 for a Gain module before the summing. Also to reset the loop just multiply by 0.
I've already made a lot of those feature extraction algorithms as well as some low level stuff in Kyma and encapsulated them. I'll share all that stuff in some time, still betatesting though.. If you're interested in samplerate processing in general I suggest you do some private sessions with me kymaguy.com/coaching

Best,
Gustav

IP: Logged

JonBellona
Member
posted 25 April 2015 16:17         Edit/Delete Message   Reply w/Quote

spectralBrightness2.kym

 
SSC and Gustl,
Thanks! I found a solution, one that doesn't quite match the equation for spectral brightness, but one that does act like it should. Ended up using the pulse train solution Gustl used in Seeing the Wire (makes complete sense) for my KBin filter and then averaged the results after ClippingDivide. Values are correctly between 0-1. I wasn't able to get this working inside the FFT itself, but only post IFFT.

Thanks much! I've learned a bunch about Expression value rates, solution work arounds, and got to know a bunch more objects in the process.

Best,
jpb

IP: Logged

gustl
Member
posted 27 April 2015 02:03         Edit/Delete Message   Reply w/Quote

spectralBrightness3.kym

 
Hi Jon,

First of all you can't calculate the spectral brightness in the time domain. Also you used the pulse train right but you're actually splitting the spectrum by using the inverse of the pulsetrain for the other part while you're supposed to compare the high frequency content to the whole frequency content. Therefore you should only use the pulsetrain as a low cut for one part.
Also averaging after division is not the same as dividing the sums but at least it gets you close.

I've attached an example using SpectralAnalysis and the AveragingLowpassFilter. It works but for the best result you should use the summing technique using the feedbackLoops. The averaging will contain values of the previous frame as well. By writing this I realize you could use a sampleAndHold after the averaging with an offset of FrameLength - 1 samp to avoid that, but I'll leave that to you

Best,
Gustl

IP: Logged

JonBellona
Member
posted 28 April 2015 00:44         Edit/Delete Message   Reply w/Quote

adding.kym

 
Gustl,
Thanks for the hints. I knew that I was wrong by moving back into the time domain.

I went back to the drawing board and looked at just accumulating numbers using pulseTrain and FIR filter on noise. I was able to get this working for 512 samps. For FFT, since spec brightness only needs N/2 samples, I was able to come up with a solution that only needs to utilize one FIR filter (per FFT). Using this accumulator, I am summing the SqRtMagnitude of the FFT staying in the frequency domain. (see attached)
The rest was fixing my past errors (pulse train as high pass filter, etc.), which you kindly pointed out. The result is a Spectral Brightness Sound that acts extremely similar to William Brent's Timbre ID specBrigthness~ object (pure Data), whose formula I first encountered. I was able to test the Kyma "bell.aif" in pure data and Kyma achieving similar results (at least to the eye).

Appreciate the help. I'm too used to line coding and at frame/control rates at that. I'm definitely new to sample rate operations.

IP: Logged

pete
Member
posted 01 May 2015 13:57         Edit/Delete Message   Reply w/Quote
Hi Guys

Why doesn't it work with just 2 filters in the time domain and measuring the level of the two outputs. Obviously the shape of the filters is important and if you need magnitude you could play with the Hilbert transform and square and add the outputs. If all you are doing is adding up the frequencies amplitudes in the FFT, well in the time domain they add automatically , or am I missing something?

Pete

IP: Logged

gustl
Member
posted 01 May 2015 16:01         Edit/Delete Message   Reply w/Quote
Hi Pete,

You're right, for the Spectral Brightness it would work in the time domain as well. Jon was asking for a specific formula but your way would certainly come up with similar results.

I haven't had a look on Jon's last Sound, but using this kind of technique lets you calculate feature extractors like the Spectral Centroid which I think is useful.

Best,
Gustl

IP: Logged

SSC
Administrator
posted 09 May 2015 16:38         Edit/Delete Message   Reply w/Quote
There's also a "BrightnessFollower" and a "BrightnessTracking to Global Controller" in the Prototypes.

IP: Logged

All times are CT (US)

next newest topic | next oldest topic

Administrative Options: Close Topic | Archive/Move | Delete Topic
Post New Topic  Post A Reply

Contact Us | Symbolic Sound Home

This forum is provided solely for the support and edification of the customers of Symbolic Sound Corporation.


Ultimate Bulletin Board 5.45c