![]() |
![]() ![]() ![]() ![]() ![]()
|
next newest topic | next oldest topic |
Author | Topic: sum of spectra energy | |
JonBellona Member |
![]() ![]() ![]()
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 IP: Logged | |
JonBellona Member |
![]() ![]() ![]()
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 |
![]() ![]() ![]() 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 |
![]() ![]() ![]() 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. Best, IP: Logged | |
JonBellona Member |
![]() ![]() ![]()
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, IP: Logged | |
gustl Member |
![]() ![]() ![]()
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. 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, IP: Logged | |
JonBellona Member |
![]() ![]() ![]()
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) 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 |
![]() ![]() ![]() 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 |
![]() ![]() ![]() 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, IP: Logged | |
SSC Administrator |
![]() ![]() ![]() 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 |
![]() ![]() |
This forum is provided solely for the support and edification of the customers of Symbolic Sound Corporation.