Main Content

setAugmenterParams

Set parameters of augmentation algorithm

Since R2021a

    Description

    example

    setAugmenterParams(aug,algorithmName,params) sets parameters of the augmentation algorithm associated with the audioDataAugmenter object.

    setAugmenterParams(aug,algorithmName) without the params argument restores the algorithmName parameters to their default values.

    Examples

    collapse all

    Modify the default parameters of the shiftPitch and stretchAudio augmentation algorithms.

    Read in an audio signal and listen to it.

    [audioIn,fs] = audioread('FemaleSpeech-16-8-mono-3secs.wav');
    soundsc(audioIn,fs)

    Create an audioDataAugmenter object that applies a pitch shift of 3 semitones and a time stretch with a SpeedupFactor of 1.5.

    aug = audioDataAugmenter('AugmentationParameterSource','specify', ...
                             'ApplyPitchShift',true, ...
                             'SemitoneShift',3, ...
                             'ApplyTimeStretch',true, ...
                             'SpeedupFactor',1.5, ...
                             'ApplyVolumeControl',false, ...
                             'ApplyAddNoise',false, ...
                             'ApplyTimeShift',false)
    aug = 
      audioDataAugmenter with properties:
    
                   AugmentationMode: 'sequential'
        AugmentationParameterSource: 'specify'
                   ApplyTimeStretch: 1
                      SpeedupFactor: 1.5000
                    ApplyPitchShift: 1
                      SemitoneShift: 3
                 ApplyVolumeControl: 0
                      ApplyAddNoise: 0
                     ApplyTimeShift: 0
    
    

    Call setAugmenterParams to set the LockPhase and PreserveFormants parameters of the shiftPitch augmentation algorithm to false. Set the LockPhase parameter of the stretchAudio augmentation algorithm to false. Set the CepstralOrder parameter of the shiftPitch algorithm to 30.

    Augment the original signal and listen to the result. The resulting file has an audible distortion that sounds unnatural. View the parameters of the augmentation algorithms.

    setAugmenterParams(aug,'shiftPitch','LockPhase',false,'PreserveFormants',false,'CepstralOrder',30);
    setAugmenterParams(aug,'stretchAudio','LockPhase',false);
    data = augment(aug,audioIn,fs);
    
    pause(3)
    
    augmentationPre = data.Audio{1};
    soundsc(augmentationPre,fs)
    
    data.AugmentationInfo(1)
    ans = struct with fields:
        SpeedupFactor: 1.5000
        SemitoneShift: 3
    
    
    augmenterParamsPre = getAugmenterParams(aug);
    augmenterParamsPre.stretchAudio
    ans = struct with fields:
        LockPhase: 0
    
    
    augmenterParamsPre.shiftPitch
    ans = struct with fields:
               LockPhase: 0
        PreserveFormants: 0
           CepstralOrder: 30
    
    

    Plot the time-domain representation of the original and the augmented signals.

    t = (0:(numel(audioIn)-1))/fs;
    taug = (0:(numel(augmentationPre)-1))/fs;
    plot(t,audioIn,taug,augmentationPre)
    legend("Original Audio","Augmented Audio")
    ylabel("Amplitude")
    xlabel("Time (s)")

    To partially compensate for the audible distortion and increase the fidelity of the augmentation algorithms, apply formant preservation to the shiftPitch algorithm, apply phase-locking to both algorithms, and change the cepstral order of the shiftPitch algorithm to 25. Listen to the processed audio.

    setAugmenterParams(aug,'shiftPitch','LockPhase',true,'PreserveFormants',true,'CepstralOrder',25);
    setAugmenterParams(aug,'stretchAudio','LockPhase',true);
    data = augment(aug,audioIn,fs);
    
    augmentationPost = data.Audio{1};
    soundsc(augmentationPost,fs)
    
    data.AugmentationInfo(1)
    ans = struct with fields:
        SpeedupFactor: 1.5000
        SemitoneShift: 3
    
    
    augmenterParamsPost = getAugmenterParams(aug);
    augmenterParamsPost.stretchAudio
    ans = struct with fields:
        LockPhase: 1
    
    
    augmenterParamsPost.shiftPitch
    ans = struct with fields:
               LockPhase: 1
        PreserveFormants: 1
           CepstralOrder: 25
    
    

    Plot the original audio as well as the augmented data before and after formant preservation, phase-locking, and cepstral order modification.

    taug = (0:(numel(augmentationPost)-1))/fs;
    plot(t,audioIn,taug,augmentationPre)
    hold on
    plot(taug,augmentationPost,'LineStyle',':')
    legend("Original Audio","Pre Formant Preservation," + ...
        " Phase-Locking, and Cepstral Order", ...
        "Post Formant Preservation, Phase-Locking, and Cepstral Order")
    ylabel("Amplitude")
    xlabel("Time (s)")
    legend('Location','best')

    Return the augmentation algorithm parameters to their default values. Call getAugmenterParams to display the current parameter values for the audioAugmenter object.

    setAugmenterParams(aug,'shiftPitch')
    setAugmenterParams(aug,'stretchAudio')
    augmenterParamsDefault = getAugmenterParams(aug);
    augmenterParamsDefault.stretchAudio
    ans = struct with fields:
        LockPhase: 0
    
    
    augmenterParamsDefault.shiftPitch
    ans = struct with fields:
               LockPhase: 0
        PreserveFormants: 0
           CepstralOrder: 30
    
    

    Input Arguments

    collapse all

    Audio data augmenter, specified as an audioDataAugmenter object.

    Algorithm name, specified as 'stretchAudio' or 'shiftPitch.

    Note

    Augmentation algorithms must be modified independently using separate calls to setAugmenterParams for each algorithm.

    Data Types: char | string

    Parameter name, specified as a character vector, string, or structure array. Parameter values depend on algorithmName. Specify params as one of these:

    • When you set algorithmName to 'stretchAudio', specify params as 'LockPhase' and true or false.

    • When you set algorithmName to 'shiftPitch', specify params as one or all of these:

      • 'LockPhase' and true or false

      • 'PreserveFormants' and true or false

      • 'CepstralOrder' and a positive integer

    Example: setAugmenterParams(aug,'shiftPitch','LockPhase',true,'PreserveFormants',false,'CepstralOrder',15) enables the LockPhase parameter, disables the PreserveFormants parameter, and sets a cepstral order of 15 for the shiftPitch augmentation algorithm.

    Data Types: char | string | struct

    Version History

    Introduced in R2021a