Normalizing channels with different magnitudes

We have some data where certain channel values are very large (on the order of 1e6) while others are small (1e0).

I’m just wondering if there is a way to normalize all channels to within a similar range (say 0-1) within a sample?

Cheers,
Sam

Hi @sam_faunalabs,

You can write your own custom DSP block with Python to normalize the channels, check out our tutorial here: https://docs.edgeimpulse.com/docs/custom-blocks

1 Like

Hi @jenny, thanks for following up!

I added the custom block, but I guess I want the outputs of that custom block to flow into the spectral analysis block? Is that something that is supported?

(I am talking about project 83735, and its possible I didn’t implement the custom block properly)

Cheers,
Sam

Hello @sam_faunalabs

From the default DSP block, I would change this line to normalize the channel instead of using the “scale_axes” value.
I guess something like that would work but I have not tried, you’ll probably encounter an issue is on one axis all the values are 0 :man_shrugging: :

fx = np.array(X, dtype='f')
fx = fx * (1.0/fx.max())

Can you share the code you’ve been writing?

Regards,

Louis

Thanks @louis and @jenny for the pointers!

For anyone that is interested - this was the code I adapted from the python example:

def normalize(fx,scale,zero_centered=True):
    max = int(np.max(fx))
    min = int(np.min(fx))
    fx = scale* ((fx - min) / (max - min))
    if zero_centered:
        fx = fx - 0.5*scale
    return fx

I was able to implement the custom block successfully going from

to

I guess my question now revolves around wanting to then do spectral analysis on the output of this custom block (rather than the raw data) so I can feed Keras with parameters that are all the same magnitude.

Is the easiest solution to add the spectral analysis directly into the custom code block?

1 Like

Yes that’s what I would do :slight_smile:

Regards,

Louis

Heads up in case anyone is interested, you can scale individual axes in Edge Impulse without needing to write a custom DSP block. You use multiple “Raw” or “Flatten” blocks (one for each scale factor) and set the scale value in those individual blocks. Here is an example project showing how that works: https://studio.edgeimpulse.com/public/31378/latest/create-impulse

3 Likes