modules/utils.py
def asnr(x, xhat, compute_psnr=False):
    '''
        Compute affine SNR, which accounts for any scaling and shift between two
        signals

        Inputs:
            x: Ground truth signal(ndarray)
            xhat: Approximation of x

        Outputs:
            asnr_val: 20log10(||x||/||x - (a.xhat + b)||)
                where a, b are scalars that miminize MSE between x and xhat
    '''
    mxy = (x*xhat).mean()
    mxx = (xhat*xhat).mean()
    mx = xhat.mean()
    my = x.mean()
    

    a = (mxy - mx*my)/(mxx - mx*mx)
    b = my - a*mx

    if compute_psnr:
        return psnr(x, a*xhat + b)
    else:
        return rsnr(x, a*xhat + b)

        Compute affine SNR, which accounts for any scaling and shift between two
        signals

        Inputs:
            x: Ground truth signal(ndarray)
            xhat: Approximation of x

        Outputs:
            asnr_val: 20log10(||x||/||x - (a.xhat + b)||)
                where a, b are scalars that miminize MSE between x and xhat
    
Compute affine SNR, which accounts for any scaling and shift between two
signals

Ground truth signal(ndarray)
xhat: Approximation of x


Compute affine SNR which accounts for any scaling and shift between two signals Ground truth signal ( ndarray ) xhat : Approximation of x
def asnr(x, xhat, compute_psnr=False):
    mxy = (x*xhat).mean()
    mxx = (xhat*xhat).mean()
    mx = xhat.mean()
    my = x.mean()
    a = (mxy - mx*my)/(mxx - mx*mx)
    b = my - a*mx
    if compute_psnr:
        return psnr(x, a*xhat + b)
    else:
        return rsnr(x, a*xhat + b)
def asnr ( x , xhat , compute_psnr = False ) : mxy = ( x * xhat ) . mean ( ) mxx = ( xhat * xhat ) . mean ( ) mx = xhat . mean ( ) my = x . mean ( ) a = ( mxy - mx * my ) / ( mxx - mx * mx ) b = my - a * mx if compute_psnr : return psnr ( x , a * xhat + b ) else : return rsnr ( x , a * xhat + b )
Compute affine SNR, which accounts for any scaling and shift between two
signals
Compute affine SNR which accounts for any scaling and shift between two signals
'''
        Compute affine SNR, which accounts for any scaling and shift between two
        signals

        Inputs:
            x: Ground truth signal(ndarray)
            xhat: Approximation of x

        Outputs:
            asnr_val: 20log10(||x||/||x - (a.xhat + b)||)
                where a, b are scalars that miminize MSE between x and xhat
    '''
x
xhat
compute_psnr