Calculating the mean of a series of updated jit.matrices

    Nov 26 2014 | 1:34 pm
    I am currently trying to find a way to calculate the mean of a series of updated matrices. Please read on for a brief summary of my patch.
    With this patch I am aiming to have audio input fed into a pfft sub patch to create a FFT amplitude/frequency graph of the audio signal. I have managed to get this far and it works quite well, giving me an updated graph (in the form of a jit.matrix) every time the metro provides a bang.
    What I would then like to realize is for the patch to calculate a mean graph from all of the updated FFT graphs that are triggered by the metro. So in short, an FFT graph that displays the average frequency content of an entire audio file.
    I have found that the "mean" object does what I am after for single numbers so ideally the solution I am seeking would function in the same way as this but for a jit.matrix.
    I have searched high and low for a suitable object and have had no luck so I would be very grateful if someone would be able to point me in the right direction with either a object or method that might be suitable.
    Thank you very much for your time,

    • Nov 26 2014 | 2:34 pm
    • Nov 26 2014 | 2:51 pm
      Thank you for your reply. I had looked at jit.3m but decided it wasn't what I was after. As I understand it jit.3m gives the minimum, mean and maximum values for each plane of a particular frame of a matrix.
      What I am after is something that will give the mean of many matrix frames that are output in series one after the other from the same matrix.
    • Nov 26 2014 | 4:18 pm
      Max Patcher
      In Max, select New From Clipboard.
      I suggest just calculating the mean yourself as you would with any stream of numbers: keep the running sum, and divide by the number of instances. I.e., use jit.+ (to keep the sum of all matrices received), use counter (to keep track of how many matrices you've received), and use jit./ to divide by that number (or jit.* to multiply by one over that number). In this example, I wrote a little subpatch to generate fake input data, and the rest of the patch shows the procedure for calculating the mean.
    • Nov 26 2014 | 7:35 pm
      Thank you for your reply. Your example is very promising in regards to what I am trying to achieve so thank you very much. I added your example into my patch and it seems to work well in producing a mean representation of the mean frequency content of the audio. Please see the attached screenshot taken during the analysis of the audio to see the results compared to the matrix (in blue) I used as the input.
      The only problem with this solution is that it only creates a mean representation on one axis rather than two. So at the moment with your solution it is providing the mean frequency content across the x axis but ideally I am looking for a way of realizing a mean representation of both frequency and amplitude across the x & y axis in the same way that my input matrix (in blue) represents the frequency and amplitude.
      Do you have any further ideas how I might go about achieving this?
      Please see below for the patch in its current state.
      I have a feeling in order for the pfft fft analysis object to work on your machine you will need the sub patch so please also find that attached.
      I have just realized/remembered that when I opened your patch example and tried it with your fake data it produced exactly what I am seeking with a mean representation of the x and y axis of the matrix. However I cannot for the life of me work why it does not behave this way when I incorporate in my patch. It must be possible, I just can't see where I am at fault.
      Max Patcher
      In Max, select New From Clipboard.
      Thank you
    • Nov 27 2014 | 1:02 am
      So after many further hours of head scratching I have figured it out. All it needed was a jit.graph object to be put at the end of the mean analysis process to turn the results back into the frequency/amplitude graph format I was hoping for.
      Thank you for your time and help with this issue, I am most appreciative.
    • Nov 27 2014 | 6:07 pm
      My example calculates the mean of each cell over successive matrices. It works in two dimensions on one plane of data. I see at least two flaws in your patch that uses that example.
      One of your problems is that you seem to be sending 1-dimensional 2-plane matrices, not 2-dimensional 1-plane matrices. And the dimensions of the matrices don't correspond to the size (number of bins of) your FFT.
      Also, I have no idea why you've got metro objects sending bang messages 1000 and 2000 times per second. (That's rarely if ever a good idea.) My example was meant to receive a bang for each new matrix of data. In this case, you appear to be incrementing the counter and retriggering the calculations every ms, which is not the rate at which new data is being generated.
    • Nov 27 2014 | 7:05 pm
      Thank you for the tips on the dimension and plane issues. In regards to the metro sending the bangs, I should preface this by clarifying that the pfft fft analysis part of my patch was not created by me but borrowed from a third party to test the validity of my idea. This particular pfft subpatch is actually intended to be used as a freeze effect to freeze the audio on a particular sample, the graph then displays the data for that one sample. It is for this reason that I added the metro to effectively repeatedly freeze the audio (although I am not using that audio feed) and thus drive the succession of graphs over the course of the audio file. Hope that clears up my thought process with that one.
    • Nov 27 2014 | 10:14 pm
      Sorry reading that back I realize I slightly misread your comment on the metro(s). The reason I had the metro's sending out bangs that fast was because I did not know at what rate the data was being generated.
      Moving on from your explanation of what your example does, if I wanted to have the mean calculation work for all 4 planes over 2 dimensions would it be as simple as changing the 1 (plane) arguments to 4 in the input, sum and mean matrices?
      The reason I ask is because I trying that out with a different 4 plane source and am having no luck.