How to normalize a signal to zero mean and unit variance?

后端 未结 5 1062
鱼传尺愫
鱼传尺愫 2020-12-24 05:27

I am new to MATLAB and I am trying to built a voice morphing system using MATLAB.

So I would like to know how to normalize a signal to zero mean and unit variance us

相关标签:
5条回答
  • 2020-12-24 05:42

    You can determine the mean of the signal, and just subtract that value from all the entries. That will give you a zero mean result.

    To get unit variance, determine the standard deviation of the signal, and divide all entries by that value.

    0 讨论(0)
  • 2020-12-24 05:47

    if your signal is in the matrix X, you make it zero-mean by removing the average:

    X=X-mean(X(:));
    

    and unit variance by dividing by the standard deviation:

    X=X/std(X(:));
    
    0 讨论(0)
  • 2020-12-24 05:53

    If you have the stats toolbox, then you can compute

    Z = zscore(S);
    
    0 讨论(0)
  • 2020-12-24 06:03

    It seems like you are essentially looking into computing the z-score or standard score of your data, which is calculated through the formula: z = (x-mean(x))/std(x)

    This should work:

    %% Original data (Normal with mean 1 and standard deviation 2)
    x = 1 + 2*randn(100,1);
    mean(x)
    var(x)
    std(x)
    
    %% Normalized data with mean 0 and variance 1
    z = (x-mean(x))/std(x);
    mean(z)
    var(z)
    std(z)
    
    0 讨论(0)
  • 2020-12-24 06:03

    To avoid division by zero!

    function x = normalize(x, eps)
        % Normalize vector `x` (zero mean, unit variance)
    
        % default values
        if (~exist('eps', 'var'))
            eps = 1e-6;
        end
    
        mu = mean(x(:));
    
        sigma = std(x(:));
        if sigma < eps
            sigma = 1;
        end
    
        x = (x - mu) / sigma;
    end
    
    0 讨论(0)
提交回复
热议问题