|
import numpy as np
|
|
import matplotlib.pyplot as plt
|
|
from scipy.io import wavfile
|
|
import torch
|
|
|
|
|
|
def minmax_norm_diff(tensor: torch.Tensor, vmax: float = 2.5, vmin: float = -12) -> torch.Tensor:
|
|
tensor = torch.clip(tensor, vmin, vmax)
|
|
tensor = 2 * (tensor - vmin) / (vmax - vmin) - 1
|
|
return tensor
|
|
|
|
|
|
def reverse_minmax_norm_diff(tensor: torch.Tensor, vmax: float = 2.5, vmin: float = -12) -> torch.Tensor:
|
|
tensor = torch.clip(tensor, -1.0, 1.0)
|
|
tensor = (tensor + 1) / 2
|
|
tensor = tensor * (vmax - vmin) + vmin
|
|
return tensor
|
|
|