Main Content

generateMATLABFunction

Create MATLAB function compatible with C/C++ code generation

Since R2020b

    Description

    Generate Equivalent MATLAB Function

    generateMATLABFunction(afe) generates code and opens an untitled file containing a function named extractAudioFeatures. The generated MATLAB® function has the signature:

    featureVector = extractAudioFeatures(audioIn)
    The signature is equivalent to:
    featureVector = extract(afe,audioIn)

    example

    generateMATLABFunction(afe,fileName) generates code and saves the resulting function to the file specified by fileName. The generated MATLAB function has the signature:

    featureVector = functionName(audioIn)
    The signature is equivalent to:
    featureVector = extract(afe,audioIn)

    Generate MATLAB Function for Stream Processing

    example

    generateMATLABFunction(___,'IsStreaming',TF) specifies whether the function is intended for stream (single-frame) processing. If TF is specified as true, the resulting function requires single-frame input of length numel(afe.Window). If individual feature extractors have state, the resulting function maintains the state between calls. If unspecified, TF defaults to false. The streaming function has the signature:

    featureVector = functionName(audioIn,varargin)
    The size of featureVector depends on the value of IsStreaming.

    • If IsStreaming was set to true, then featureVector is returned as an M-by-N matrix, where M is the number of features extracted and N is the number of channels.

    • If IsStreaming was set to false, then featureVector is returned as an L-by-M-by-N array, where L is the number of hops, M is the number of feature vectors, and N is the number of channels.

    The possible values of varargin depends on the configuration of your audioFeatureExtractor object, afe.

    • If the features your audioFeatureExtractor object extracts do not require state, then varargin must be empty.

    • If the features your audioFeatureExtractor object extracts require state, then varargin can be the optional name-value pair 'Reset' and either true or false. If you call the function with 'Reset' set to true, then the function clears any state before calculating and returning the feature vector.

    Examples

    collapse all

    You can use the audioFeatureExtractor object while developing a feature extraction pipeline in MATLAB. Once you are ready to deploy your system to a device or integrate it into a larger system, use generateMATLABFunction to create a MATLAB function suitable for C/C++ code generation. Then use MATLAB Coder™ to generate equivalent C/C++ code.

    Read in an audio file. You will use this audio file to verify the equivalency of the audioFeatureExtractor object and the generated MATLAB function.

    [audioIn,fs] = audioread('Counting-16-44p1-mono-15secs.wav');

    Create an audioFeatureExtractor object to extract the Bark spectrum, the delta gammatone cepstral coefficients (GTCC), and the harmonic ratio.

    afe = audioFeatureExtractor("Window",hann(512,"periodic"), ...
        "OverlapLength",256, ...
        "SampleRate",fs, ...
        "FFTLength",1024, ...
        'barkSpectrum',true, ...
        "gtccDelta",true, ...
        "harmonicRatio",true)
    afe = 
      audioFeatureExtractor with properties:
    
       Properties
                         Window: [512x1 double]
                  OverlapLength: 256
                     SampleRate: 44100
                      FFTLength: 1024
        SpectralDescriptorInput: 'linearSpectrum'
            FeatureVectorLength: 46
    
       Enabled Features
         barkSpectrum, gtccDelta, harmonicRatio
    
       Disabled Features
         linearSpectrum, melSpectrum, erbSpectrum, mfcc, mfccDelta, mfccDeltaDelta
         gtcc, gtccDeltaDelta, spectralCentroid, spectralCrest, spectralDecrease, spectralEntropy
         spectralFlatness, spectralFlux, spectralKurtosis, spectralRolloffPoint, spectralSkewness, spectralSlope
         spectralSpread, pitch, zerocrossrate, shortTimeEnergy
    
    
       To extract a feature, set the corresponding property to true.
       For example, obj.mfcc = true, adds mfcc to the list of enabled features.
    
    

    Call generateMATLABFunction on the object and specify a name for the generated MATLAB function.

    functionName = 'extractAudioFeatures';
    generateMATLABFunction(afe,functionName)

    The generated function is saved to your current folder.

    type extractAudioFeatures
    function featureVector = extractAudioFeatures(x)
    %extractAudioFeatures Extract multiple features from batch audio
    %   featureVector = extractAudioFeatures(audioIn) returns audio features
    %   extracted from audioIn.
    %
    %   Parameters of the audioFeatureExtractor used to generate this
    %   function must be honored when calling this function.
    %    - Sample rate of the input should be 44100 Hz.
    %    - Input frame length should be greater than or equal to 512 samples.
    %
    %
    %      % Example 1: Extract features
    %        source = dsp.ColoredNoise(SamplesPerFrame=44100);
    %        for ii = 1:10
    %            audioIn = source();
    %            featureArray = extractAudioFeatures(audioIn);
    %            % ... do something with featureArray ...
    %        end
    %
    %
    %      % Example 2: Generate code
    %        targetDataType = "single";
    %        codegen extractAudioFeatures -args {ones(44100,1,targetDataType)}
    %        source = dsp.ColoredNoise(SamplesPerFrame=44100, ...
    %                                  OutputDataType=targetDataType);
    %        for ii = 1:10
    %            audioIn = source();
    %            featureArray = extractAudioFeatures_mex(audioIn);
    %            % ... do something with featureArray ...
    %        end
    %
    %   See also audioFeatureExtractor, dsp.AsyncBuffer, codegen.
    
    %   Generated by audioFeatureExtractor on 13-Feb-2024 00:00:32 UTC-05:00
    %#codegen
    
    dataType = underlyingType(x);
    [numSamples,numChannels] = size(x);
    
    props = coder.const(getProps(dataType));
    
    persistent config outputIndex
    if isempty(outputIndex)
        [config, outputIndex] = coder.const(@getConfig,dataType,props);
    end
    
    % Preallocate feature vector
    numHops = floor((numSamples-numel(props.Window))/(numel(props.Window) - props.OverlapLength)) + 1;
    featureVector = coder.nullcopy(zeros(numHops,props.NumFeatures,numChannels,dataType));
    
    % Short-time Fourier transform
    Y = stft(x,Window=props.Window,OverlapLength=props.OverlapLength,FFTLength=props.FFTLength,FrequencyRange="onesided");
    Z = reshape(Y,[],numHops*numChannels);
    Zpower = real(Z.*conj(Z));
    
    % Bark spectrum
    y = applyFilterBank(config.barkSpectrum.FilterBank,Zpower,dataType);
    barkSpectrum = reshape(y,[],numHops,numChannels);
    featureVector(:,outputIndex.barkSpectrum,:) = permute(barkSpectrum,[2,1,3]);
    
    % ERB spectrum
    y = applyFilterBank(config.erbSpectrum.FilterBank,Zpower,dataType);
    erbSpectrum = reshape(y,[],numHops,numChannels);
    
    % Gammatone-frequency cepstral coefficients (GTCC)
    gammacc = cepstralCoefficients(erbSpectrum,NumCoeffs=13,Rectification="log");
    featureVector(:,outputIndex.gtccDelta,:) = audioDelta(gammacc,9);
    
    % Periodicity features
    featureVector(:,outputIndex.harmonicRatio,:) = harmonicRatio(x,props.SampleRate,Window=props.Window,OverlapLength=props.OverlapLength);
    end
    
    function props = getProps(dataType)
    props.Window = cast([0;3.764908042774850471801073581446e-05;0.00015059065189787501637397326703649;0.00033880770582522812262027400720399;0.00060227189741379749676752908271737;0.00094094354992541040516584871511441;0.0013547716606548965145861984638032;0.0018436939086109993546358509775018;0.0024076366639015356341246842930559;0.0030465149988219697441138578142272;0.0037602327006450164681439218838932;0.0045486822861099951431640420196345;0.0054117450176094927805081624683226;0.0063492909210707826339614712196635;0.0073611788055293891908092973608291;0.0084472562843918574948531841073418;0.0096073597983847847103788808453828;0.010841314640186172635338834879803;0.012148934980735714983524076160393;0.0135300238972199116105343819072;0.014984373402728012880658070571371;0.016511764477573964704504305700539;0.018111967102280079888743102856097;0.019784740292217106727434838830959;0.021529832133895587809035987447714;0.023346979822903068946260418670136;0.025235909703481662624824366503162;0.027196337309739360144078545999946;0.029227967408489596845555524851079;0.031330494043712520113587061132421;0.0335036005826305216537264186627;0.035746959763392205378096377899055;0.038060233744356630758431947469944;0.040443074154971114797518794148345;0.042895122148234654524401321395999;0.045416008454738809874129401578102;0.048005353438278330902022617010516;0.050662767153023091637464858649764;0.053387849402242337770729818657856;0.056180189798573032522455150683527;0.059039367825822475221997365224524;0.061964952902296699388529077623389;0.064956504445644269729598363483092;0.068013571939206651784104451508028;0.071135694999863940957141039689304;0.07432240344736740222941762112896;0.077573217375146441554534249007702;0.080887647222580960626459045670344;0.084265193848727382164298660427448;0.087705348607487354506417887023417;0.091207593424208144305964651721297;0.094771400873702615896831957797986;0.098396234259677528566356841110974;0.1020815476955582168372416163038;0.10582678618669683068276299309218;0.10963138571395275588926665477629;0.11349477331863150331159317829588;0.11741636718877052070197919420025;0.12139557674675771625771858452936;0.12543180273827031490085914811061;0.12952443732252039154673184384592;0.13367286416379359215156341633701;0.1378764585242664986175498142984;0.14213458735809070265787568132509;0.14644660940672621363134453531529;0.1508118752955135422055832350452;0.15522972763146652974697303761786;0.159699501102273433428280213775;0.16422052257649077944279270013794;0.16879211120491410813571064863936;0.17341357852311156673152936491533;0.17808422855510425142355757088808;0.18280335791817725610286515802727;0.1875702559288067727827353792236;0.19238420470968659037325210192648;0.19724447929783722743835028268222;0.20215034775378326603600953603745;0.2071010712717805679616844827251;0.21209590429107733067226604362077;0.21713409460819338425707769602013;0.22221488349019885566448806457629;0.22733750578897676808409755722096;0.23250119005645136782689519350242;0.23770515866076558086916747924988;0.24294862790338916935795054996561;0.248230808137141212288412361886;0.25355090388510792553944384053466;0.25890811396043855729942606558325;0.26430163158700109571341840819514;0.2697306445208800251833736183471;0.27519433517269670241844892188965;0.28069188073073614297925360006047;0.28622245328485890203396024844551;0.29178521995118134046975910678157;0.29737934299750506950132944439247;0.3030039799694759228287921359879;0.30865828381745508135480804412509;0.31434140302408120071220309910132;0.32005248173250588905602853628807;0.32579065987528277315021796312067;0.33155507330389000220094430915196;0.33734485391886848137943388792337;0.34315912980055418568525738010067;0.34899702534038590240328403524472;0.354857661372768862229065689462;0.36074015530747349789209010850755;0.36664362126255078955239241622621;0.37256717019774265864384688029531;0.37850991004836798126120811502915;0.38447094585966434809876091094338;0.39044937992156514283692558819894;0.39644431190389073371704853343545;0.40245483899193584820253022371617;0.40848005602242948297586622175004;0.41451905561984930814745098359708;0.42057092833306930490522290710942;0.42663476277231915378962412432884;0.43270964574643688838051502898452;0.43879466240039188829058502960834;0.44488889635305839398426996922353;0.45099142983521961491888419004681;0.4571013438277800600140210462996;0.46321771820016627296823230608425;0.46933963184889565534163580196036;0.47546616283629095089935390205937;0.481596388529320518223642011435;0.48772938573854385246875153825385;0.49386423085714004077573235917953;0.49999999999999994448884876874217;0.50613576914285995922426764082047;0.51227061426145603650894599923049;0.518403611470679481776357988565;0.52453383716370904910064609794063;0.53066036815110428914721296678181;0.53678228179983367152061646265793;0.54289865617221988447482772244257;0.54900857016478032956996457869536;0.55511110364694149499342756826081;0.56120533759960811170941497039166;0.56729035425356300059718250849983;0.57336523722768084621037587567116;0.57942907166693058407247463037493;0.58548094438015063634139778514509;0.59151994397757046151298254699213;0.59754516100806409628631854502601;0.60355568809610926628295146656455;0.60955062007843485716307441180106;0.61552905414033554087893662654096;0.6214900899516319077164894224552;0.62743282980225723033385065718903;0.63335637873744921044760758377379;0.63925984469252650210790989149245;0.64514233862723102674863184802234;0.65100297465961398657441350223962;0.65684087019944570329244015738368;0.66265514608113140759826364956098;0.66844492669610999779905569084804;0.67420934012471722684978203687933;0.67994751826749411094397146371193;0.68565859697591879928779690089868;0.69134171618254480762288949335925;0.69699602003052396614890540149645;0.70262065700249487498751932434971;0.70821478004881854850793843070278;0.71377754671514093143258605778101;0.71930811926926363497614147490822;0.72480566482730335309270230936818;0.73026935547912008583892884416855;0.73569836841299884877543036054703;0.7410918860395613316782714719011;0.74644909611489196343825369694969;0.75176919186285873220043640685617;0.75705137209661077513089821877657;0.76229484133923430810853005823446;0.7674988099435484656396511127241;0.77266249421102317640475121152122;0.77778511650980097780205824165023;0.78286590539180656023177107272204;0.78790409570892272483888518763706;0.7928989287282194320383155172749;0.79784965224621662294168800144689;0.80275552070216271705049848605995;0.80761579529031335411559666681569;0.81242974407119317170611338951858;0.81719664208182263287483237945708;0.82191577144489569306529119785409;0.82658642147688832224616817256901;0.83120788879508600288659181387629;0.83577947742350922055720729986206;0.84030049889772651106056855496718;0.84477027236853352576417819363996;0.84918812470448634677211430243915;0.85355339059327373085750423342688;0.85786541264190929734212431867491;0.86212354147573333484899649192812;0.86632713583620635233728535240516;0.87047556267747938640866323112277;0.87456819726172962958798962063156;0.8786044232532423947645838779863;0.88258363281122953480917203705758;0.88650522668136844117725559044629;0.89036861428604718859958211396588;0.89417321381330316931723700690782;0.89791845230444167214045592118055;0.9016037657403224159224919276312;0.90522859912629738410316804220201;0.90879240657579174467173288576305;0.91229465139251253447127965046093;0.91573480615127267334685257083038;0.91911235277741898386238972307183;0.9224267826248535584454657509923;0.92567759655263259777058237887104;0.92886430500013594802055649779504;0.93198642806079334821589554849197;0.93504349555435561924809917400125;0.93803504709770324510031969111878;0.94096063217417746926685140351765;0.94381981020142691196639361805865;0.94661215059775760671811895008432;0.94933723284697690836253514135024;0.95199464656172172460912861424731;0.9545839915452611901258705984219;0.957104877851765345475598678604;0.95955692584502894071363243710948;0.96193976625564336924156805253006;0.96425304023660773911075239084312;0.96649639941736942283512235007947;0.96866950595628742437526170760975;0.97077203259151034764329324389109;0.9728036626902605288336189914844;0.97476409029651833737517563349684;0.97665302017709687554258835007204;0.97847016786610441219096401255229;0.98021525970778289327256516116904;0.98188803289771997562240812840173;0.98348823552242603529549569429946;0.98501562659727204263049316068646;0.98646997610277997736716315557715;0.98785106501926422950532469258178;0.98915868535981377185350993386237;0.99039264020161521528962111915462;0.99155274371560819801629804715049;0.99263882119447055529803947138134;0.99365070907892916185488729752251;0.9945882549823905627306430687895;0.99545131771388994934568472672254;0.99623976729935503904300730937393;0.9969534850011780857670373734436;0.99759236333609835334357285319129;0.99815630609138894513421291776467;0.9986452283393451034854138015362;0.99905905645007453408368292002706;0.99939772810258620250323247091728;0.99966119229417471636622849473497;0.99984940934810206947247479547514;0.99996235091957230700643322052201;1;0.99996235091957230700643322052201;0.99984940934810206947247479547514;0.99966119229417471636622849473497;0.99939772810258620250323247091728;0.99905905645007453408368292002706;0.9986452283393451034854138015362;0.99815630609138894513421291776467;0.99759236333609835334357285319129;0.9969534850011780857670373734436;0.99623976729935503904300730937393;0.99545131771388994934568472672254;0.9945882549823905627306430687895;0.99365070907892916185488729752251;0.99263882119447055529803947138134;0.99155274371560819801629804715049;0.99039264020161521528962111915462;0.98915868535981377185350993386237;0.98785106501926422950532469258178;0.98646997610277997736716315557715;0.98501562659727204263049316068646;0.98348823552242603529549569429946;0.98188803289771997562240812840173;0.98021525970778289327256516116904;0.97847016786610441219096401255229;0.97665302017709687554258835007204;0.97476409029651833737517563349684;0.9728036626902605288336189914844;0.97077203259151034764329324389109;0.96866950595628742437526170760975;0.96649639941736942283512235007947;0.96425304023660773911075239084312;0.96193976625564336924156805253006;0.95955692584502894071363243710948;0.957104877851765345475598678604;0.9545839915452611901258705984219;0.95199464656172172460912861424731;0.94933723284697690836253514135024;0.94661215059775760671811895008432;0.94381981020142691196639361805865;0.94096063217417746926685140351765;0.93803504709770324510031969111878;0.93504349555435561924809917400125;0.93198642806079334821589554849197;0.92886430500013594802055649779504;0.92567759655263259777058237887104;0.9224267826248535584454657509923;0.91911235277741898386238972307183;0.91573480615127267334685257083038;0.91229465139251253447127965046093;0.90879240657579174467173288576305;0.90522859912629738410316804220201;0.9016037657403224159224919276312;0.89791845230444167214045592118055;0.89417321381330316931723700690782;0.89036861428604718859958211396588;0.88650522668136844117725559044629;0.88258363281122953480917203705758;0.8786044232532423947645838779863;0.87456819726172962958798962063156;0.87047556267747938640866323112277;0.86632713583620635233728535240516;0.86212354147573333484899649192812;0.85786541264190929734212431867491;0.85355339059327373085750423342688;0.84918812470448634677211430243915;0.84477027236853352576417819363996;0.84030049889772651106056855496718;0.83577947742350922055720729986206;0.83120788879508600288659181387629;0.82658642147688832224616817256901;0.82191577144489569306529119785409;0.81719664208182263287483237945708;0.81242974407119317170611338951858;0.80761579529031335411559666681569;0.80275552070216271705049848605995;0.79784965224621662294168800144689;0.7928989287282194320383155172749;0.78790409570892272483888518763706;0.78286590539180656023177107272204;0.77778511650980097780205824165023;0.77266249421102317640475121152122;0.7674988099435484656396511127241;0.76229484133923430810853005823446;0.75705137209661077513089821877657;0.75176919186285873220043640685617;0.74644909611489196343825369694969;0.7410918860395613316782714719011;0.73569836841299884877543036054703;0.73026935547912008583892884416855;0.72480566482730335309270230936818;0.71930811926926363497614147490822;0.71377754671514093143258605778101;0.70821478004881854850793843070278;0.70262065700249487498751932434971;0.69699602003052396614890540149645;0.69134171618254480762288949335925;0.68565859697591879928779690089868;0.67994751826749411094397146371193;0.67420934012471722684978203687933;0.66844492669610999779905569084804;0.66265514608113140759826364956098;0.65684087019944570329244015738368;0.65100297465961398657441350223962;0.64514233862723102674863184802234;0.63925984469252650210790989149245;0.63335637873744921044760758377379;0.62743282980225723033385065718903;0.6214900899516319077164894224552;0.61552905414033554087893662654096;0.60955062007843485716307441180106;0.60355568809610926628295146656455;0.59754516100806409628631854502601;0.59151994397757046151298254699213;0.58548094438015063634139778514509;0.57942907166693058407247463037493;0.57336523722768084621037587567116;0.56729035425356300059718250849983;0.56120533759960811170941497039166;0.55511110364694149499342756826081;0.54900857016478032956996457869536;0.54289865617221988447482772244257;0.53678228179983367152061646265793;0.53066036815110428914721296678181;0.52453383716370904910064609794063;0.518403611470679481776357988565;0.51227061426145603650894599923049;0.50613576914285995922426764082047;0.49999999999999994448884876874217;0.49386423085714004077573235917953;0.48772938573854385246875153825385;0.481596388529320518223642011435;0.47546616283629095089935390205937;0.46933963184889565534163580196036;0.46321771820016627296823230608425;0.4571013438277800600140210462996;0.45099142983521961491888419004681;0.44488889635305839398426996922353;0.43879466240039188829058502960834;0.43270964574643688838051502898452;0.42663476277231915378962412432884;0.42057092833306930490522290710942;0.41451905561984930814745098359708;0.40848005602242948297586622175004;0.40245483899193584820253022371617;0.39644431190389073371704853343545;0.39044937992156514283692558819894;0.38447094585966434809876091094338;0.37850991004836798126120811502915;0.37256717019774265864384688029531;0.36664362126255078955239241622621;0.36074015530747349789209010850755;0.354857661372768862229065689462;0.34899702534038590240328403524472;0.34315912980055418568525738010067;0.33734485391886848137943388792337;0.33155507330389000220094430915196;0.32579065987528277315021796312067;0.32005248173250588905602853628807;0.31434140302408120071220309910132;0.30865828381745508135480804412509;0.3030039799694759228287921359879;0.29737934299750506950132944439247;0.29178521995118134046975910678157;0.28622245328485890203396024844551;0.28069188073073614297925360006047;0.27519433517269670241844892188965;0.2697306445208800251833736183471;0.26430163158700109571341840819514;0.25890811396043855729942606558325;0.25355090388510792553944384053466;0.248230808137141212288412361886;0.24294862790338916935795054996561;0.23770515866076558086916747924988;0.23250119005645136782689519350242;0.22733750578897676808409755722096;0.22221488349019885566448806457629;0.21713409460819338425707769602013;0.21209590429107733067226604362077;0.2071010712717805679616844827251;0.20215034775378326603600953603745;0.19724447929783722743835028268222;0.19238420470968659037325210192648;0.1875702559288067727827353792236;0.18280335791817725610286515802727;0.17808422855510425142355757088808;0.17341357852311156673152936491533;0.16879211120491410813571064863936;0.16422052257649077944279270013794;0.159699501102273433428280213775;0.15522972763146652974697303761786;0.1508118752955135422055832350452;0.14644660940672621363134453531529;0.14213458735809070265787568132509;0.1378764585242664986175498142984;0.13367286416379359215156341633701;0.12952443732252039154673184384592;0.12543180273827031490085914811061;0.12139557674675771625771858452936;0.11741636718877052070197919420025;0.11349477331863150331159317829588;0.10963138571395275588926665477629;0.10582678618669683068276299309218;0.1020815476955582168372416163038;0.098396234259677528566356841110974;0.094771400873702615896831957797986;0.091207593424208144305964651721297;0.087705348607487354506417887023417;0.084265193848727382164298660427448;0.080887647222580960626459045670344;0.077573217375146441554534249007702;0.07432240344736740222941762112896;0.071135694999863940957141039689304;0.068013571939206651784104451508028;0.064956504445644269729598363483092;0.061964952902296699388529077623389;0.059039367825822475221997365224524;0.056180189798573032522455150683527;0.053387849402242337770729818657856;0.050662767153023091637464858649764;0.048005353438278330902022617010516;0.045416008454738809874129401578102;0.042895122148234654524401321395999;0.040443074154971114797518794148345;0.038060233744356630758431947469944;0.035746959763392205378096377899055;0.0335036005826305216537264186627;0.031330494043712520113587061132421;0.029227967408489596845555524851079;0.027196337309739360144078545999946;0.025235909703481662624824366503162;0.023346979822903068946260418670136;0.021529832133895587809035987447714;0.019784740292217106727434838830959;0.018111967102280079888743102856097;0.016511764477573964704504305700539;0.014984373402728012880658070571371;0.0135300238972199116105343819072;0.012148934980735714983524076160393;0.010841314640186172635338834879803;0.0096073597983847847103788808453828;0.0084472562843918574948531841073418;0.0073611788055293891908092973608291;0.0063492909210707826339614712196635;0.0054117450176094927805081624683226;0.0045486822861099951431640420196345;0.0037602327006450164681439218838932;0.0030465149988219697441138578142272;0.0024076366639015356341246842930559;0.0018436939086109993546358509775018;0.0013547716606548965145861984638032;0.00094094354992541040516584871511441;0.00060227189741379749676752908271737;0.00033880770582522812262027400720399;0.00015059065189787501637397326703649;3.764908042774850471801073581446e-05],dataType);props.OverlapLength = cast(256,dataType);
    props.SampleRate = cast(44100,dataType);
    props.FFTLength = uint16(1024);
    props.NumFeatures = uint8(46);
    end
    
    function [config, outputIndex] = getConfig(dataType, props)
    powerNormalizationFactor = 1/(sum(props.Window)^2);
    
    barkFilterbank = designAuditoryFilterBank(props.SampleRate, ...
        FrequencyScale="bark", ...
        FFTLength=props.FFTLength, ...
        OneSided=true, ...
        FrequencyRange=[0 22050], ...
        NumBands=32, ...
        Normalization="bandwidth", ...
        FilterBankDesignDomain="linear");
    barkFilterbank = barkFilterbank*powerNormalizationFactor;
    config.barkSpectrum.FilterBank = cast(barkFilterbank,dataType);
    
    erbFilterbank = coder.const(@feval,'designAuditoryFilterBank',props.SampleRate, ...
        FrequencyScale="erb", ...
        FFTLength=props.FFTLength, ...
        OneSided=true, ...
        FrequencyRange=[0 22050], ...
        NumBands=43, ...
        Normalization="bandwidth");
    erbFilterbank = erbFilterbank*powerNormalizationFactor;
    config.erbSpectrum.FilterBank = cast(erbFilterbank,dataType);
    
    outputIndex.barkSpectrum = uint8(1:32);
    outputIndex.gtccDelta = uint8(33:45);
    outputIndex.harmonicRatio = uint8(46);
    end
    
    function y = applyFilterBank(filterBank, Z, dataType, varargin)
    if isempty(coder.target)
        y = filterBank*Z;
    else
        % Generate optimized C/C++ code for filter bank operation
        [numBands,filterLength] = size(filterBank);
        numChan = size(Z,2);
        
        if nargin == 3
            y = zeros(numBands,numChan,dataType);
        else
            y = varargin{1};
        end
        
        for channel = 1:numChan
            temp = zeros(numBands,1,dataType);
            for jj = 1:filterLength
                temp = temp + Z(jj,channel)*filterBank(:,jj);
            end
            y(:,channel) = temp;
        end
    end
    end
    

    Calling the generated function is equivalent to calling extract on the audioFeatureExtrator object. You can replace calls to extract with calls to the generated function in your code. Verify the equivalency between the object and the function.

    a = extract(afe,audioIn);
    b = extractAudioFeatures(audioIn);
    isequal(a,b)
    ans = logical
       1
    
    

    The generated function contains help text that indicates any requirements on the input. In this example, the only requirement is that the input sample rate should be 44.1 kHz. The help text also contains custom examples. These examples show how to use the function directly in MATLAB and how to generate C/C++ code.

    help extractAudioFeatures
     extractAudioFeatures Extract multiple features from batch audio
        featureVector = extractAudioFeatures(audioIn) returns audio features
        extracted from audioIn.
     
        Parameters of the audioFeatureExtractor used to generate this
        function must be honored when calling this function.
         - Sample rate of the input should be 44100 Hz.
         - Input frame length should be greater than or equal to 512 samples.
     
     
           % Example 1: Extract features
             source = dsp.ColoredNoise(SamplesPerFrame=44100);
             for ii = 1:10
                 audioIn = source();
                 featureArray = extractAudioFeatures(audioIn);
                 % ... do something with featureArray ...
             end
     
     
           % Example 2: Generate code
             targetDataType = "single";
             codegen extractAudioFeatures -args {ones(44100,1,targetDataType)}
             source = dsp.ColoredNoise(SamplesPerFrame=44100, ...
                                       OutputDataType=targetDataType);
             for ii = 1:10
                 audioIn = source();
                 featureArray = extractAudioFeatures_mex(audioIn);
                 % ... do something with featureArray ...
             end
     
        See also audioFeatureExtractor, dsp.AsyncBuffer, codegen.
    

    Run the first example to see how to use the function to extract features in MATLAB.

    source = dsp.ColoredNoise("SamplesPerFrame",44100);
    for ii = 1:10
        audioIn = source();
        featureArray = extractAudioFeatures(audioIn);
        % ... do something with featureArray ...
    end

    Run the second example to see how to generate a MATLAB executable from the function. Then use the MEX file to extract features while working in MATLAB. MATLAB Coder™ is required to run the following code.

    targetDataType = "single";
    codegen extractAudioFeatures -args {ones(44100,1,targetDataType)}
    Code generation successful.
    
    source = dsp.ColoredNoise("SamplesPerFrame",44100, ...
                              "OutputDataType",targetDataType);
    for ii = 1:10
        audioIn = source();
        featureArray = extractAudioFeatures_mex(audioIn);
        % ... do something with featureArray ...
    end

    You can use the audioFeatureExtractor object to develop a feature extraction pipeline in MATLAB. The audioFeatureExtractor is optimized to extract features from audio signals that contain several windows of data. Typically, audio features are extracted on time scales from 5 ms to 100 ms, depending on the application. When you are ready to deploy your system to a device or to integrate it into a larger system, you can use generateMATLABFunction to create a MATLAB function suitable for C/C++ code generation. Deployed systems are often concerned with minimizing latency. You can set the IsStreaming parameter to true when calling generateMATLABFunction to generate a MATLAB function that is optimized for stream processing. The generated MATLAB function assumes that the input has already been buffered and requires a fixed input frame size. The generated MATLAB function also maintains any required state for you between calls.

    Read in an audio file. You will use this audio file to verify the approximate equivalency of the audioFeatureExtractor object and the generated MATLAB function.

    [audioToVerify,fs] = audioread('Counting-16-44p1-mono-15secs.wav');

    Create an audioFeatureExtractor object to extract the mel frequency cepstral coefficients (MFCC), the delta and delta-delta MFCC, the spectral centroid, and the pitch. Extract features from 30 ms windows with 20 ms overlap between windows.

    afe = audioFeatureExtractor("Window",hann(round(0.03*fs),'periodic'), ...
        "OverlapLength",round(0.02*fs), ...
        "SampleRate",fs, ...
        "mfcc",true, ...
        "mfccDelta",true, ...
        "mfccDeltaDelta",true, ...
        "spectralCentroid",true, ...
        "pitch",true)
    afe = 
      audioFeatureExtractor with properties:
    
       Properties
                         Window: [1323x1 double]
                  OverlapLength: 882
                     SampleRate: 44100
                      FFTLength: []
        SpectralDescriptorInput: 'linearSpectrum'
            FeatureVectorLength: 41
    
       Enabled Features
         mfcc, mfccDelta, mfccDeltaDelta, spectralCentroid, pitch
    
       Disabled Features
         linearSpectrum, melSpectrum, barkSpectrum, erbSpectrum, gtcc, gtccDelta
         gtccDeltaDelta, spectralCrest, spectralDecrease, spectralEntropy, spectralFlatness, spectralFlux
         spectralKurtosis, spectralRolloffPoint, spectralSkewness, spectralSlope, spectralSpread, harmonicRatio
         zerocrossrate, shortTimeEnergy
    
    
       To extract a feature, set the corresponding property to true.
       For example, obj.mfcc = true, adds mfcc to the list of enabled features.
    
    

    Call generateMATLABFunction on the object and specify a name and the full path for the generated MATLAB function. Set IsStreaming to true to generate a MATLAB function optimized for stream processing.

    filename = fullfile(tempdir,"extractAudioFeatures");
    generateMATLABFunction(afe,filename,'IsStreaming',true);

    The generated function is saved to the tempdir folder. Because the mfccDelta and mfccDeltaDelta features require state, the generated function includes the ability to reset states using the optional name-value pair "Reset" and either true or false. If you generate a function that does not require state, the "Reset" parameter is not included in the generated function.

    cd(tempdir)
    type extractAudioFeatures
    function featureVector = extractAudioFeatures(x, varargin)
    %extractAudioFeatures Extract multiple features from streaming audio
    %   featureVector = extractAudioFeatures(audioIn) returns audio features
    %   extracted from audioIn.
    %
    %   featureVector = extractAudioFeatures(audioIn,Reset=TF) returns feature extractors
    %   to their initial conditions before extracting features.
    %
    %   Parameters of the audioFeatureExtractor used to generate this
    %   function must be honored when calling this function.
    %    - Sample rate of the input should be 44100 Hz.
    %    - Frame length of the input should be 1323 samples.
    %    - Successive frames of the input should be overlapped by
    %      882 samples before calling extractAudioFeatures.
    %
    %
    %      % Example 1: Extract features
    %        source = dsp.ColoredNoise();
    %        inputBuffer = dsp.AsyncBuffer;
    %        for ii = 1:10
    %            audioIn = source();
    %            write(inputBuffer,audioIn);
    %            while inputBuffer.NumUnreadSamples > 441
    %                x = read(inputBuffer,1323,882);
    %                featureVector = extractAudioFeatures(x);
    %                % ... do something with featureVector ...
    %            end
    %         end
    %
    %
    %      % Example 2: Extract features from speech regions only
    %        [audioIn,fs] = audioread("Counting-16-44p1-mono-15secs.wav");
    %        audioIn = resample(audioIn,44100,fs);
    %        source = dsp.AsyncBuffer(size(audioIn,1));
    %        write(source,audioIn);
    %        TF = false;
    %        while source.NumUnreadSamples > 441
    %            x = read(source,1323,882);
    %            isSilence = var(x) < 0.01;
    %            if ~isSilence
    %                featureVector = extractAudioFeatures(x,Reset=TF);
    %                TF = false;
    %            else
    %                TF = true;
    %            end
    %            % ... do something with featureVector ...
    %        end
    %
    %
    %      % Example 3: Generate code that does not use reset
    %        targetDataType = "single";
    %        codegen extractAudioFeatures -args {ones(1323,1,targetDataType)}
    %        source = dsp.ColoredNoise(OutputDataType=targetDataType);
    %        inputBuffer = dsp.AsyncBuffer;
    %        for ii = 1:10
    %            audioIn = source();
    %            write(inputBuffer,audioIn);
    %            while inputBuffer.NumUnreadSamples > 441
    %                x = read(inputBuffer,1323,882);
    %                featureVector = extractAudioFeatures_mex(x);
    %                % ... do something with featureVector ...
    %            end
    %         end
    %
    %
    %      % Example 4: Generate code that uses reset
    %        targetDataType = "single";
    %        codegen extractAudioFeatures -args {ones(1323,1,targetDataType),"Reset",true}
    %        [audioIn,fs] = audioread("Counting-16-44p1-mono-15secs.wav");
    %        audioIn = resample(audioIn,44100,fs);
    %        source = dsp.AsyncBuffer(size(audioIn,1));
    %        write(source,cast(audioIn,targetDataType));
    %        TF = false;
    %        while source.NumUnreadSamples > 441
    %            x = read(source,1323,882);
    %            isSilence = var(x) < 0.01;
    %            if ~isSilence
    %                featureVector = extractAudioFeatures_mex(x,Reset=TF);
    %                TF = false;
    %            else
    %                TF = true;
    %            end
    %            % ... do something with featureVector ...
    %        end
    %
    %   See also audioFeatureExtractor, dsp.AsyncBuffer, codegen.
    
    %   Generated by audioFeatureExtractor on 13-Feb-2024 00:01:12 UTC-05:00
    %#codegen
    
    dataType = underlyingType(x);
    numChannels = size(x,2);
    
    props = coder.const(getProps(dataType));
    
    persistent config outputIndex state
    if isempty(outputIndex)
        [config, outputIndex] = coder.const(@getConfig,dataType,props);
        state = getState(dataType,numChannels);
    else
        assert(state.NumChannels == numChannels)
    end
    if nargin==3
        if strcmpi(varargin{1},"Reset") && varargin{2}
            state = reset(state);
        end
    end
    
    % Preallocate feature vector
    featureVector = coder.nullcopy(zeros(props.NumFeatures,numChannels,dataType));
    
    % Fourier transform
    Y = fft(bsxfun(@times,x,props.Window),props.FFTLength);
    Z = Y(config.OneSidedSpectrumBins,:);
    Zpower = real(Z.*conj(Z));
    
    % Linear spectrum
    linearSpectrum = Zpower(config.linearSpectrum.FrequencyBins,:)*config.linearSpectrum.NormalizationFactor;
    linearSpectrum(1,:) = 0.5*linearSpectrum(1,:);
    linearSpectrum = reshape(linearSpectrum,[],1,numChannels);
    
    % Mel spectrum
    y = applyFilterBank(config.melSpectrum.FilterBank,Zpower,dataType);
    melSpectrum = reshape(y,[],1,numChannels);
    
    % Mel-frequency cepstral coefficients (MFCC)
    melcc = cepstralCoefficients(melSpectrum,NumCoeffs=13,Rectification="log");
    featureVector(outputIndex.mfcc,:) = melcc;
    [melccDelta,state.mfccDelta] = audioDelta(melcc,9,state.mfccDelta);
    featureVector(outputIndex.mfccDelta,:) = melccDelta;
    [featureVector(outputIndex.mfccDeltaDelta,:),state.mfccDeltaDelta] = audioDelta(melccDelta,9,state.mfccDeltaDelta);
    
    % Spectral descriptors
    featureVector(outputIndex.spectralCentroid,:) = spectralCentroid(linearSpectrum,config.SpectralDescriptorInput.FrequencyVector);
    
    % Periodicity features
    featureVector(outputIndex.pitch,:) = pitch(x,props.SampleRate,WindowLength=numel(props.Window),OverlapLength=props.OverlapLength,Method='NCF',Range=coder.const(cast([50 400],like=x)));
    end
    
    function props = getProps(dataType)
    props.Window = cast([0;5.6387032669191761158344888826832e-06;2.2554685887743453065468202112243e-05;5.0747566325726189973011059919372e-05;9.0216708695634029169241330237128e-05;0.00014096122277840184011665769503452;0.00020297996404095020039903829456307;0.00027627153366222012564890064822976;0.00036083427856448135884193106903695;0.00045666629145085790852931495464873;0.00056376541084829367989073034550529;0.00068212922115606922091046726563945;0.00081175505270059122864267919794656;0.00095263998179551112599483531084843;0.0011047808308075057759367609833134;0.001268174168228275444647579206503;0.00144281630875153776827346518985;0.0016287033133565165243794581328984;0.0018258309893965374293145487172296;0.00203419489069373016221220495936;0.0022537903176392259929627925885143;0.0024846123172992951033677400118904;0.0027266556835268129788119040313177;0.0029799149570789440488738364365418;0.0032443844257400433761517888342496;0.0035200581244507755940276183537208;0.0038069298354423408703439690725645;0.0041049930883769181200193543190835;0.0044142411604936038216351334995124;0.0047346670767599019491456147079589;0.0050662636100292091079211331816623;0.0054090232812036287413093305076472;0.0057629383594029470749831034481758;0.0061280008621386050648993659706321;0.0065042025554942206611030997009948;0.0068915349543108850305372925504344;0.0072899893223787315399420094763627;0.0076995566726339448315741265105316;0.008120227767361598569806346858968;0.0085519931184036557247907239798224;0.0089948429873734636608162418269785;0.0094487673858749121613698207511334;0.009913756075728086258891380566638;0.010389798569200026090442179338424;0.010876884129241204401949971725116;0.011375001769727999256787143167458;0.01188414025570999621450596350769;0.012404288103663951847721591548179;0.012935433581752309173396042751847;0.01347756471008809686651375159272;0.014030669261005046521972872142214;0.01459473475933348307620462946943;0.015169748482681433277008409277187;0.015755697461721951402324748414685;0.016352568480485274449165444821119;0.016960348076657194571481568345916;0.017579022541882538543944747289061;0.018208577922074309363154043239774;0.018849000017728712030873339244863;0.019500274384245008807425847408012;0.02016238633225159171402651736571;0.020835320927937328594481414256734;0.021519062993388182736254066185211;0.022213597106929605651259862497682;0.022918907603474591994086040358525;0.02363497857487673048382248452981;0.024361793870289027985620577965165;0.02509933709652845124082887195982;0.025847591618445353578437106989441;0.026606540559298896830853209394263;0.027376166801137580275593563783332;0.028156452985185376203247642479255;0.028947381512233305578263298230013;0.029748934543036231747947795156506;0.030561093998715427311196890514111;0.031383841561166136990834729658673;0.032217158673470969176833023084328;0.033061026540318172450838574150112;0.0339154261284257407815800888784;0.034780338166970736768490723989089;0.035655743148023777422395141911693;0.036541621326989126572470922837965;0.037437952723050116343728177525918;0.038344717119619620149251204566099;0.039261894064796187819865735946223;0.040189462871825232248568227078067;0.041127402619565822661229503864888;0.042075692152962140824001835426316;0.043034310083521154499663907699869;0.044003234789794509751459372637328;0.044982444417866696007024529535556;0.045971916881847485480960813220008;0.046971629864370534335193951847032;0.04798156081709631370912916281668;0.049001686961220980442988093273016;0.050031985287990077271302880035364;0.051072432559217451064625947765308;0.052123005307809389119455545369419;0.053183679838293862474074558122084;0.054254432227355209317209983055363;0.055335238324373370311093367490685;0.056426073751968952585400529642357;0.057526913906552734623289779847255;0.058637733958880777773714498835034;0.059758508854614589278497760460596;0.060889213314885726191505455062725;0.062029821836866561035606082441518;0.063180308694345155284821657915018;0.064340647938305295383543125353754;0.065510813397512468458927514802781;0.066690778679103335235822669346817;0.067880517169181642245234797883313;0.06908000203341801981338221594342;0.070289206217655719743930831100442;0.071508102448520294291967047684011;0.072736663234035159320001184823923;0.073974860864241431812615701346658;0.075222667411823096461631621423294;0.076480054732736613143373460843577;0.077746994466846075511057279072702;0.079023458038562588434672306902939;0.080309416657488919000229543598834;0.081604841319068810445713779699872;0.082909702805241125567192739254097;0.084223971685099041639688266513986;0.085547618315553630718994782000664;0.086880612842002546969411014288198;0.088222925199003432439326388703194;0.089574525110952041284662072939682;0.090935382092764971417864217073657;0.092305465450567336649356775524211;0.0936847442823852127880002171878;0.095073187478842358100195042425185;0.096470763723861929772596113252803;0.097877441495373140867286565480754;0.099293189066021692035235446383012;0.10071797450388575434487847815035;0.1021517656731961709581923969381;0.10359453023506115521001902379794;0.10504623564819570713524399252492;0.10650684916965552639922520938853;0.1079763378555757546983784322947;0.10945466856191377047480273176916;0.11094180794519681310106307137175;0.11243772246327410346822261999478;0.11394237837607329444367110227176;0.1154557417463615842656565746438;0.11697777844051099327415954576281;0.11850845412926847011192421632586;0.12004773428852993921722713821509;0.12159558420011912227565176181088;0.1231519689525706895416590214154;0.12471685344191751898534903375548;0.12629020237248228530901883459592;0.12787198025767421150078462233068;0.12946215142078854043461433320772;0.13106067999581216820814688617247;0.13266752992823177548231683431368;0.13428266497584750993610214209184;0.13590604870959038796840445684211;0.13753764451434363769166679958289;0.13917741558976892690679960651323;0.14082532495113619930293680226896;0.14248133543015784052698791128932;0.14414540967582700758953251352068;0.14581751015526028814051073823066;0.14749759915454385694744132706546;0.14918563877958423979919189150678;0.15088159095696357381299890221271;0.15258541743479731023214185370307;0.15429707978359774589449671111652;0.15601653939714066332555830740603;0.1577437574933358011008976973244;0.15947869511510198714532293706725;0.16122131313124526963420635183866;0.16297157223734226594302754165255;0.16472943295662600959872179373633;0.1664948556408764601677319205919;0.16826780047131500994694874862034;0.17004822745950248785717917598959;0.1718360964482409380948979560344;0.17363136711247945109803936247772;0.17543399896022404682582873647334;0.1772439513334501670627219027665;0.17906118340902044128171155534801;0.18088565419960500602059028096846;0.1827173225546063761726145457942;0.1845561471610870918347302449547;0.18640208654470197258135044648952;0.18825509907063320280684592944453;0.19011514294452969142668052882073;0.19198217621344965122531789347704;0.19385615676680656438435335076065;0.19573704233731942236929057798989;0.19762479050196579688503106808639;0.19951935868293863007849608948163;0.20142070414860685501068360281351;0.20332878401447890270858920302999;0.20524355524417009499771324954054;0.20716497465037320147018817806384;0.2090929988958327712111895380076;0.21102758449432229559405982399767;0.21296868781162520134486726419709;0.21491626506651911876488725283707;0.21687027233176314755525027067051;0.21883066553508856433296614341089;0.22079740046019324939408079444547;0.22277043274773855596748717289302;0.22474971789635006524932236970926;0.22673521126362117250607752794167;0.22872686806712028140253778474289;0.23072464338540032979807392621296;0.23272849215901270092388131160988;0.23473836919152257785015081026359;0.23675422915052951600145547672582;0.23877602656868873731710323227162;0.24080371584473742041510035960528;0.24283725124452310017986178536376;0.24487658690203506495208785054274;0.2469216768204384737650514125562;0.24897247487311280345068098540651;0.25102893480469112841291234872187;0.25309101023210422987119727622485;0.25515865464562614839394427690422;0.25723182140992395527945291178185;0.25931046376510846762641904206248;0.26139453482779029247495827803505;0.26348398759213587094762942797388;0.26557877493092885146097614779137;0.26767884959663235111548829081585;0.26978416422245476979924205807038;0.27189467132341849087140417395858;0.27401032329743024718027299968526;0.27613107242635515081730090969359;0.27825687087709327638407330596237;0.28038767070265774306037087626464;0.28252342384325679347512050298974;0.28466408212737781546763926598942;0.28680959727287308469456661441654;0.28895992088804967057313888290082;0.29111500447276039693633720162325;0.29327479941949807784595805060235;0.29543925701449103016216213291045;0.29760832843880313802742421103176;0.29978196476943363979472678693128;0.30196011698042157789245720778126;0.30414273594395091482311954678153;0.30632977243145909085342282196507;0.30852117711474680294969630267587;0.31071690056709111438237869151635;0.31291689326436000762043931899825;0.31512110558612949073875597605365;0.31732948781680236916002968428074;0.31954199014673079215498319172184;0.32175856267333791116413976851618;0.32397915540224497821242266581976;0.32620371824839777818993979963125;0.32843220103719750202486693524406;0.33066455350563117576712102163583;0.33290072530340619749722463893704;0.33514066599408576241359014602494;0.33738432505622639734355061591486;0.33963165188451716058892770888633;0.34188259579092178386261480227404;0.34413710600582092524746258277446;0.34639513167915836344690205805819;0.34865662188158696999096264335094;0.35092152560561823415596904851554;0.35318979176677173237308693387604;0.3554613692047284834174547540897;0.35773620668448380399695452069864;0.36001425289750355052120767140877;0.36229545646288152660474679578329;0.3645797659284973901705484422564;0.36686712977217839082300088193733;0.36915749640286049659820832857804;0.37145081416175262933876410897938;0.37374703132350128864658245220198;0.37604609609735772934868691663723;0.37834795662834563856335989839863;0.38065256099843108872349262128409;0.38295985722769332326720359560568;0.3852697932754972631741452460119;0.38758231704166701270253270195099;0.38989737636766153006107060718932;0.39221491903775018705857746681431;0.39453489278019154840038140719116;0.39685724526841120729514500453661;0.39918192412218334030882260776707;0.40150887690881059688408072361199;0.40383805114430815219606074606418;0.40616939429458620569590721061104;0.40850285377663608787912608022452;0.41083837695971520131976717493671;0.41317591116653479277331939556461;0.41551540367444778079075717869273;0.41785680171663808213367019561701;0.42020005248331032676745167009358;0.42254510312288173778938471514266;0.42489190074317328971176266350085;0.42724039241260347576911726719118;0.42959052516138163113623704703059;0.43194224598270308801417627364572;0.43429550183394410867165902345732;0.43665023963785909444368371623568;0.43900640628377674001825425875722;0.44136394862879907430297521386819;0.44372281349899916902401741936046;0.44608294769062067919307423835562;0.44844429797127816073043504729867;0.45080681108115749911036118646734;0.45317043373421717067373037934885;0.45553511261938994802989100207924;0.45790079440178577119269220929709;0.46026742572389406360500174741901;0.46263495320678782452006316816551;0.46500332345132727729364319202432;0.46737248303936435034344754058111;0.46974237853494726913083923136583;0.47211295648552631387673272911343;0.47448416342315868909906839689938;0.47685594586571544706288250381476;0.47922825031808663487353783239087;0.48160102327338916161636461765738;0.4839742112141723340279497733718;0.48634776061362594568038275610888;0.4887216179367867008309644916153;0.49109572964174674769566308896174;0.4934700421808601022988227668975;0.49584450200195145930237572429178;0.49821905554952328198936584158218;0.50059364926596450207085808870033;0.50296822959275733211370607023127;0.50534274297168657597012497717515;0.50771713584604671876121528839576;0.5100913546618505156615697160305;0.51246534586903635943855306322803;0.51483905592267631412539685697993;0.51721243128418381562738659340539;0.51958541842252126130574652052019;0.52195796381540726649461703345878;0.52433001395052414306263699472765;0.52670151532672448979610635433346;0.5290724144552378938044512324268;0.53144265786087796499259638949297;0.53381219208324737213189337126096;0.53618096367794532142170282895677;0.53854891921777048313657587641501;0.54091600529392891427704626039485;0.54328216851723665214990433014464;0.54564735551932408430531040721689;0.5480115129538408735854204678617;0.55037458749765777454854287498165;0.55273652585207044829473943536868;0.55509727474400061275616735656513;0.55745678092719819218814336636569;0.55981499118344291154869551974116;0.56217185232374244918673866777681;0.56452731118953514144465088975267;0.56688131465388580387809724925319;0.56923380962268710359097667605965;0.57158474303585404818761617207201;0.57393406186852347072857583043515;0.57628171313224818561593565391377;0.57862764387619258776851438597078;0.58097180118832758566327356675174;0.58331413219662286984146248869365;0.58565458407024062470469516483718;0.58799310402072624270886080921628;0.59032963930319937162494170479476;0.59266413721754362953220152121503;0.59499654510959487652144161984324;0.59732681037232915333134997126763;0.59965488044704895465031313506188;0.60198070282456905832901838948601;0.60430422504640035619161153590539;0.60662539470593357382455224069417;0.60894415944962099196402505185688;0.61126046697815716868262825300917;0.613574265047658884419945479749;0.61588550147084297758937054823036;0.61819412411820451325183967128396;0.62050008091919039987516271139611;0.62280331986337666982933569670422;0.62510378900163954263291543611558;0.62740143644732726535551137203583;0.62969621037743139790876512051909;0.63198805903375487869055859846412;0.63427693072407975716231476326357;0.63656277382333270598024910214008;0.63884553677474997801510880890419;0.6411251680910403649704676354304;0.6434016163555449363542493301793;0.64567483022339944298551017709542;0.64794475842268917098465408344055;0.65021134975560856972265355580021;0.65247455309961355229830815005698;0.65473431740857579441694724664558;0.65699059171393381362236141285393;0.65924332512584216114959190235822;0.66149246683432016968851030469523;0.66373796611039681536681200668681;0.66597977230725580177761457889574;0.66821783486137742436028474912746;0.67045210329367888046903090071282;0.67268252721065380228537833318114;0.67490905630550723781624355979147;0.6771316403592920751819406177674;0.67935022924204013783366917778039;0.68156477291389405692711989104282;0.68377522142623514689319108583732;0.68598152492281050385258822643664;0.6881836336408572174505593466165;0.69038149791222469531248862040229;0.69257506816449543318725545759662;0.69476429492210189931000741125899;0.69694912880744452898795771034202;0.69912952054200272478112765384139;0.70130542094744896530755795538425;0.70347678094675636373267479939386;0.70564355156530567114714358467609;0.70780568393199105869939558033366;0.70996312928032068167993884344469;0.71211583894951879791790361196036;0.71426376438562022563871778402245;0.71640685714256879812467104784446;0.71854506888330815783660909801256;0.72067835138087199542411553920829;0.72280665651947229033424946464947;0.72492993629558444279581408409285;0.72704814281903029637987856403925;0.72916122831405749682431860492215;0.73126914512041751859072746810853;0.7333718456944412489306728275551;0.73546928261010990901525019580731;0.73756140856012630813154373754514;0.73964817635698043574166149483062;0.74172953893401494251946814983967;0.7438054493464856253837069743895;0.74587586077262169048651685443474;0.74794072651468002099761633871822;0.74999999999999988897769753748435;0.75205363478205300431511659553507;0.75410158454149056606041767736315;0.75614380308718853740401755203493;0.75818024435728936794021137757227;0.76021086242024094037361692244303;0.76223561147583263064575476164464;0.76425444585622770432564720977098;0.76626732002699426971048524137586;0.76827418858813145696728952316334;0.77027500627509426500694189599017;0.77226972795981363439921096869512;0.77425830865171474393093831167789;0.77624070349873219853975570003968;0.77821686778832033226649400603492;0.78018675694846351120759209152311;0.78215032654867955308475302445004;0.78410753230102325783690275784465;0.78605833006108472016393307058024;0.78800267582898531060209279530682;0.78994052575036977081879285833566;0.79187183611739486721603498153854;0.79379656336971682328851329657482;0.79571466409547197962126574566355;0.7976260950322571208204180948087;0.79953081306810469541801467130426;0.80142877524245537124159000086365;0.80331993874712770420387641934212;0.80520426092728158984357378358254;0.80708169928238282508914380741771;0.80895221146716012050603694660822;0.81081575529256111334319712113938;0.81267228872670305150904823676683;0.81452176989582125710143145624897;0.81636415708521359313465382001596;0.81819940874018171061976545388461;0.82002748346696752168583088860032;0.82184834003368700816594127900316;0.8236619373712610325810601352714;0.82546823457434048698644346586661;0.82726719090222977648352298274403;0.82905876577980497366127110581147;0.83084291879842964156921425455948;0.83261960971686610477604517654981;0.83438879846218294566995155037148;0.83615044513065850395605593803339;0.83790450998868126752938678691862;0.83965095347364671063417063123779;0.84138973619484835886339624266839;0.84312081893436674473463199319667;0.84484416264795458850755949242739;0.84655972846591620584177917407942;0.84826747769398591625389371984056;0.84996737181419823592420925706392;0.85165937248575984686027595671476;0.85334344154591135200860207987716;0.85501954101079014058939264941728;0.85668763307628614800393052064464;0.85834768011889439609518603901961;0.85999964469656453580626020993805;0.86164348954954395054528504260816;0.86327917760121963830499680625508;0.86490667195895287733264922280796;0.86652593591491300362150695946184;0.86813693294690430501958644526894;0.86973962671918958466932281226036;0.87133398108331061582276788612944;0.87291996007890237940785027603852;0.8744975279345055252377960641752;0.87606664906837194983779681933811;0.87762728808926726564720866008429;0.87917940979727082773109714253224;0.88072297918456721177449253445957;0.88225796143623758105434262688505;0.88378432193104394798410794464871;0.88530202624221099316770278164768;0.88681104013820144515989341016393;0.88831132958348923978064703987911;0.88980286073932601809133302595001;0.89128559996450573699178221431794;0.8927595138161221743899886860163;0.89422456905032388085885486361803;0.89568073262306402426702334196307;0.89712797169084534942840036819689;0.89856625361146114094879067124566;0.89999554594473196722503871569643;0.90141581645323576310602220473811;0.90282703310303724641983080800856;0.90422916406440834169444542567362;0.90562217771254749365539282734971;0.90700604262829243040755500260275;0.90838072759882826368027508578962;0.90974620161839281351490171800833;0.91110243388897460548037088301498;0.91244939382100842539813356779632;0.9137870510340646568181455222657;0.91511537535753506578117821845808;0.91643433683131281242140175891109;0.91774390570646813269917174693546;0.91904405244592024537553243135335;0.92033474772510226458166471275035;0.92161596243262366989767997438321;0.92288766767092600407096369963256;0.9241498347569354621100501390174;0.92540243522270904108495415130164;0.92664544081607780334763901919359;0.92787882350128281228052173901233;0.92910255545960795942050935991574;0.9303166090900081286463318974711;0.93152095700973014391621518370812;0.9327155720549322737156217044685;0.93390042728129496474309689801885;0.93507549596463035435078836599132;0.93624075160148412244609517074423;0.93739616790973290250121863209642;0.93854171882917802882673186104512;0.93967737852213262250700154254446;0.94080312137400445848811614268925;0.94191892199387416972911069024121;0.94302475521506712308195119476295;0.9441205960957219645024451892823;0.94520641991935228087839959698613;0.94628220219540493118870472244453;0.94734791865981149427966556686442;0.9484035452755366080168641929049;0.94944905823311898096505956345936;0.95048443395120951748822335503064;0.95150964907710244844452063261997;0.9525246804872621320114944865054;0.95352950528784496952994231833145;0.95452410081521543716576161386911;0.95550844463645723259048736508703;0.95648251454987942565821867901832;0.95744628858551728001202718587592;0.95839974500562763459754478390096;0.95934286230517917815063810849097;0.96027561921233739461456480057677;0.96119799468894473459812388682622;0.96210996793099468060717072148691;0.96301151836910126036173096508719;0.9639026256689626759310840498074;0.96478326973182060299905060674064;0.96565343069491293981343460472999;0.96651308893192156013185467600124;0.96736222505341551425317447865382;0.96820081990728867893380993336905;0.96902885457919052392128378414782;0.96984631039295421395252105867257;0.9706531689110162730571573774796;0.97144941193483402841479801281821;0.97223502150529461651728979632026;0.9730099799031211027511290012626;0.97377426964927193964172147389036;0.97452787350533431887100732637919;0.97527077447391441467061667935923;0.97600295579901996667615549085895;0.97672440096643753371097318449756;0.97743509370410674996776378975483;0.97813501798248525531676023092587;0.97882415801491229334629906588816;0.9795024982579629835299783735536;0.98017002341179981783625407842919;0.98082671842051816213370329933241;0.98147256847248443012432517207344;0.98210755900067159274158257176168;0.98273167568298702700957392153214;0.98334490444259559094319911309867;0.98394723144823725835550476404023;0.9845386431145388694829989617574;0.98511912610232110765196011925582;0.9856886673188984815396906924434;0.98624725391837553267748717189534;0.9867948733019357154816475485859;0.98733151311812628048159012905671;0.98785716126313638518752213713014;0.98837180588107065304370735248085;0.98887543536421562695437614820548;0.98936803835330255907365426537581;0.98984960373776331721273891162127;0.99032012065598029604274188386626;0.99077957849553266456155142805073;0.99122796689343461995491679772385;0.99166527573636975567694662458962;0.99209149516091865717015707559767;0.99250661555378205669342150940793;0.99291062755199721578946991940029;0.99330352204314864561496278838604;0.99368529016557483046767629275564;0.99405592330856717975251513053081;0.99441541311256420598851946124341;0.99476375146934081783456349512562;0.99510093052219028564309155626688;0.995426942666102321233267957723;0.99574178054793371916986188807641;0.99604543706657511226154610994854;0.99633790537311028856493066996336;0.9966191788709715115857079581474;0.99688925121608740198553277878091;0.99714811631702682248601377068553;0.99739576833513576836764968902571;0.9976322016846692619651548739057;0.99785741103291725195845174312126;0.99807139130032496154854015912861;0.99827413766060768551824367023073;0.99846564554085903697711046334007;0.99864591062165453116961089108372;0.99881492883714906305669956054771;0.99897269637516816764843952114461;0.99911920967729472842222548933933;0.99925446543894858031364947237307;0.99937846060946111670375557878288;0.999491192392144789380381553201;0.99959265824435505898293286008993;0.99968285587754857068887304194504;0.99976178325733466856206632655812;0.99982943860352102571908972095116;0.99988582039015394542502690455876;0.99993092734555277800723160908092;0.99996475845233878665396787255304;0.99998731294745724085260007996112;0.99999859032219606813640666587162;0.99999859032219606813640666587162;0.99998731294745724085260007996112;0.99996475845233878665396787255304;0.99993092734555277800723160908092;0.99988582039015394542502690455876;0.99982943860352102571908972095116;0.99976178325733466856206632655812;0.99968285587754857068887304194504;0.99959265824435505898293286008993;0.999491192392144789380381553201;0.99937846060946111670375557878288;0.99925446543894858031364947237307;0.99911920967729472842222548933933;0.99897269637516816764843952114461;0.99881492883714906305669956054771;0.99864591062165453116961089108372;0.99846564554085903697711046334007;0.99827413766060768551824367023073;0.99807139130032496154854015912861;0.99785741103291725195845174312126;0.9976322016846692619651548739057;0.99739576833513576836764968902571;0.99714811631702682248601377068553;0.99688925121608740198553277878091;0.9966191788709715115857079581474;0.99633790537311028856493066996336;0.99604543706657511226154610994854;0.99574178054793371916986188807641;0.995426942666102321233267957723;0.99510093052219028564309155626688;0.99476375146934081783456349512562;0.99441541311256420598851946124341;0.99405592330856717975251513053081;0.99368529016557483046767629275564;0.99330352204314864561496278838604;0.99291062755199721578946991940029;0.99250661555378205669342150940793;0.99209149516091865717015707559767;0.99166527573636975567694662458962;0.99122796689343461995491679772385;0.99077957849553266456155142805073;0.99032012065598029604274188386626;0.98984960373776331721273891162127;0.98936803835330255907365426537581;0.98887543536421562695437614820548;0.98837180588107065304370735248085;0.98785716126313638518752213713014;0.98733151311812628048159012905671;0.9867948733019357154816475485859;0.98624725391837553267748717189534;0.9856886673188984815396906924434;0.98511912610232110765196011925582;0.9845386431145388694829989617574;0.98394723144823725835550476404023;0.98334490444259559094319911309867;0.98273167568298702700957392153214;0.98210755900067159274158257176168;0.98147256847248443012432517207344;0.98082671842051816213370329933241;0.98017002341179981783625407842919;0.9795024982579629835299783735536;0.97882415801491229334629906588816;0.97813501798248525531676023092587;0.97743509370410674996776378975483;0.97672440096643753371097318449756;0.97600295579901996667615549085895;0.97527077447391441467061667935923;0.97452787350533431887100732637919;0.97377426964927193964172147389036;0.9730099799031211027511290012626;0.97223502150529461651728979632026;0.97144941193483402841479801281821;0.9706531689110162730571573774796;0.96984631039295421395252105867257;0.96902885457919052392128378414782;0.96820081990728867893380993336905;0.96736222505341551425317447865382;0.96651308893192156013185467600124;0.96565343069491293981343460472999;0.96478326973182060299905060674064;0.9639026256689626759310840498074;0.96301151836910126036173096508719;0.96210996793099468060717072148691;0.96119799468894473459812388682622;0.96027561921233739461456480057677;0.95934286230517917815063810849097;0.95839974500562763459754478390096;0.95744628858551728001202718587592;0.95648251454987942565821867901832;0.95550844463645723259048736508703;0.95452410081521543716576161386911;0.95352950528784496952994231833145;0.9525246804872621320114944865054;0.95150964907710244844452063261997;0.95048443395120951748822335503064;0.94944905823311898096505956345936;0.9484035452755366080168641929049;0.94734791865981149427966556686442;0.94628220219540493118870472244453;0.94520641991935228087839959698613;0.9441205960957219645024451892823;0.94302475521506712308195119476295;0.94191892199387416972911069024121;0.94080312137400445848811614268925;0.93967737852213262250700154254446;0.93854171882917802882673186104512;0.93739616790973290250121863209642;0.93624075160148412244609517074423;0.93507549596463035435078836599132;0.93390042728129496474309689801885;0.9327155720549322737156217044685;0.93152095700973014391621518370812;0.9303166090900081286463318974711;0.92910255545960795942050935991574;0.92787882350128281228052173901233;0.92664544081607780334763901919359;0.92540243522270904108495415130164;0.9241498347569354621100501390174;0.92288766767092600407096369963256;0.92161596243262366989767997438321;0.92033474772510226458166471275035;0.91904405244592024537553243135335;0.91774390570646813269917174693546;0.91643433683131281242140175891109;0.91511537535753506578117821845808;0.9137870510340646568181455222657;0.91244939382100842539813356779632;0.91110243388897460548037088301498;0.90974620161839281351490171800833;0.90838072759882826368027508578962;0.90700604262829243040755500260275;0.90562217771254749365539282734971;0.90422916406440834169444542567362;0.90282703310303724641983080800856;0.90141581645323576310602220473811;0.89999554594473196722503871569643;0.89856625361146114094879067124566;0.89712797169084534942840036819689;0.89568073262306402426702334196307;0.89422456905032388085885486361803;0.8927595138161221743899886860163;0.89128559996450573699178221431794;0.88980286073932601809133302595001;0.88831132958348923978064703987911;0.88681104013820144515989341016393;0.88530202624221099316770278164768;0.88378432193104394798410794464871;0.88225796143623758105434262688505;0.88072297918456721177449253445957;0.87917940979727082773109714253224;0.87762728808926726564720866008429;0.87606664906837194983779681933811;0.8744975279345055252377960641752;0.87291996007890237940785027603852;0.87133398108331061582276788612944;0.86973962671918958466932281226036;0.86813693294690430501958644526894;0.86652593591491300362150695946184;0.86490667195895287733264922280796;0.86327917760121963830499680625508;0.86164348954954395054528504260816;0.85999964469656453580626020993805;0.85834768011889439609518603901961;0.85668763307628614800393052064464;0.85501954101079014058939264941728;0.85334344154591135200860207987716;0.85165937248575984686027595671476;0.84996737181419823592420925706392;0.84826747769398591625389371984056;0.84655972846591620584177917407942;0.84484416264795458850755949242739;0.84312081893436674473463199319667;0.84138973619484835886339624266839;0.83965095347364671063417063123779;0.83790450998868126752938678691862;0.83615044513065850395605593803339;0.83438879846218294566995155037148;0.83261960971686610477604517654981;0.83084291879842964156921425455948;0.82905876577980497366127110581147;0.82726719090222977648352298274403;0.82546823457434048698644346586661;0.8236619373712610325810601352714;0.82184834003368700816594127900316;0.82002748346696752168583088860032;0.81819940874018171061976545388461;0.81636415708521359313465382001596;0.81452176989582125710143145624897;0.81267228872670305150904823676683;0.81081575529256111334319712113938;0.80895221146716012050603694660822;0.80708169928238282508914380741771;0.80520426092728158984357378358254;0.80331993874712770420387641934212;0.80142877524245537124159000086365;0.79953081306810469541801467130426;0.7976260950322571208204180948087;0.79571466409547197962126574566355;0.79379656336971682328851329657482;0.79187183611739486721603498153854;0.78994052575036977081879285833566;0.78800267582898531060209279530682;0.78605833006108472016393307058024;0.78410753230102325783690275784465;0.78215032654867955308475302445004;0.78018675694846351120759209152311;0.77821686778832033226649400603492;0.77624070349873219853975570003968;0.77425830865171474393093831167789;0.77226972795981363439921096869512;0.77027500627509426500694189599017;0.76827418858813145696728952316334;0.76626732002699426971048524137586;0.76425444585622770432564720977098;0.76223561147583263064575476164464;0.76021086242024094037361692244303;0.75818024435728936794021137757227;0.75614380308718853740401755203493;0.75410158454149056606041767736315;0.75205363478205300431511659553507;0.74999999999999988897769753748435;0.74794072651468002099761633871822;0.74587586077262169048651685443474;0.7438054493464856253837069743895;0.74172953893401494251946814983967;0.73964817635698043574166149483062;0.73756140856012630813154373754514;0.73546928261010990901525019580731;0.7333718456944412489306728275551;0.73126914512041751859072746810853;0.72916122831405749682431860492215;0.72704814281903029637987856403925;0.72492993629558444279581408409285;0.72280665651947229033424946464947;0.72067835138087199542411553920829;0.71854506888330815783660909801256;0.71640685714256879812467104784446;0.71426376438562022563871778402245;0.71211583894951879791790361196036;0.70996312928032068167993884344469;0.70780568393199105869939558033366;0.70564355156530567114714358467609;0.70347678094675636373267479939386;0.70130542094744896530755795538425;0.69912952054200272478112765384139;0.69694912880744452898795771034202;0.69476429492210189931000741125899;0.69257506816449543318725545759662;0.69038149791222469531248862040229;0.6881836336408572174505593466165;0.68598152492281050385258822643664;0.68377522142623514689319108583732;0.68156477291389405692711989104282;0.67935022924204013783366917778039;0.6771316403592920751819406177674;0.67490905630550723781624355979147;0.67268252721065380228537833318114;0.67045210329367888046903090071282;0.66821783486137742436028474912746;0.66597977230725580177761457889574;0.66373796611039681536681200668681;0.66149246683432016968851030469523;0.65924332512584216114959190235822;0.65699059171393381362236141285393;0.65473431740857579441694724664558;0.65247455309961355229830815005698;0.65021134975560856972265355580021;0.64794475842268917098465408344055;0.64567483022339944298551017709542;0.6434016163555449363542493301793;0.6411251680910403649704676354304;0.63884553677474997801510880890419;0.63656277382333270598024910214008;0.63427693072407975716231476326357;0.63198805903375487869055859846412;0.62969621037743139790876512051909;0.62740143644732726535551137203583;0.62510378900163954263291543611558;0.62280331986337666982933569670422;0.62050008091919039987516271139611;0.61819412411820451325183967128396;0.61588550147084297758937054823036;0.613574265047658884419945479749;0.61126046697815716868262825300917;0.60894415944962099196402505185688;0.60662539470593357382455224069417;0.60430422504640035619161153590539;0.60198070282456905832901838948601;0.59965488044704895465031313506188;0.59732681037232915333134997126763;0.59499654510959487652144161984324;0.59266413721754362953220152121503;0.59032963930319937162494170479476;0.58799310402072624270886080921628;0.58565458407024062470469516483718;0.58331413219662286984146248869365;0.58097180118832758566327356675174;0.57862764387619258776851438597078;0.57628171313224818561593565391377;0.57393406186852347072857583043515;0.57158474303585404818761617207201;0.56923380962268710359097667605965;0.56688131465388580387809724925319;0.56452731118953514144465088975267;0.56217185232374244918673866777681;0.55981499118344291154869551974116;0.55745678092719819218814336636569;0.55509727474400061275616735656513;0.55273652585207044829473943536868;0.55037458749765777454854287498165;0.5480115129538408735854204678617;0.54564735551932408430531040721689;0.54328216851723665214990433014464;0.54091600529392891427704626039485;0.53854891921777048313657587641501;0.53618096367794532142170282895677;0.53381219208324737213189337126096;0.53144265786087796499259638949297;0.5290724144552378938044512324268;0.52670151532672448979610635433346;0.52433001395052414306263699472765;0.52195796381540726649461703345878;0.51958541842252126130574652052019;0.51721243128418381562738659340539;0.51483905592267631412539685697993;0.51246534586903635943855306322803;0.5100913546618505156615697160305;0.50771713584604671876121528839576;0.50534274297168657597012497717515;0.50296822959275733211370607023127;0.50059364926596450207085808870033;0.49821905554952328198936584158218;0.49584450200195145930237572429178;0.4934700421808601022988227668975;0.49109572964174674769566308896174;0.4887216179367867008309644916153;0.48634776061362594568038275610888;0.4839742112141723340279497733718;0.48160102327338916161636461765738;0.47922825031808663487353783239087;0.47685594586571544706288250381476;0.47448416342315868909906839689938;0.47211295648552631387673272911343;0.46974237853494726913083923136583;0.46737248303936435034344754058111;0.46500332345132727729364319202432;0.46263495320678782452006316816551;0.46026742572389406360500174741901;0.45790079440178577119269220929709;0.45553511261938994802989100207924;0.45317043373421717067373037934885;0.45080681108115749911036118646734;0.44844429797127816073043504729867;0.44608294769062067919307423835562;0.44372281349899916902401741936046;0.44136394862879907430297521386819;0.43900640628377674001825425875722;0.43665023963785909444368371623568;0.43429550183394410867165902345732;0.43194224598270308801417627364572;0.42959052516138163113623704703059;0.42724039241260347576911726719118;0.42489190074317328971176266350085;0.42254510312288173778938471514266;0.42020005248331032676745167009358;0.41785680171663808213367019561701;0.41551540367444778079075717869273;0.41317591116653479277331939556461;0.41083837695971520131976717493671;0.40850285377663608787912608022452;0.40616939429458620569590721061104;0.40383805114430815219606074606418;0.40150887690881059688408072361199;0.39918192412218334030882260776707;0.39685724526841120729514500453661;0.39453489278019154840038140719116;0.39221491903775018705857746681431;0.38989737636766153006107060718932;0.38758231704166701270253270195099;0.3852697932754972631741452460119;0.38295985722769332326720359560568;0.38065256099843108872349262128409;0.37834795662834563856335989839863;0.37604609609735772934868691663723;0.37374703132350128864658245220198;0.37145081416175262933876410897938;0.36915749640286049659820832857804;0.36686712977217839082300088193733;0.3645797659284973901705484422564;0.36229545646288152660474679578329;0.36001425289750355052120767140877;0.35773620668448380399695452069864;0.3554613692047284834174547540897;0.35318979176677173237308693387604;0.35092152560561823415596904851554;0.34865662188158696999096264335094;0.34639513167915836344690205805819;0.34413710600582092524746258277446;0.34188259579092178386261480227404;0.33963165188451716058892770888633;0.33738432505622639734355061591486;0.33514066599408576241359014602494;0.33290072530340619749722463893704;0.33066455350563117576712102163583;0.32843220103719750202486693524406;0.32620371824839777818993979963125;0.32397915540224497821242266581976;0.32175856267333791116413976851618;0.31954199014673079215498319172184;0.31732948781680236916002968428074;0.31512110558612949073875597605365;0.31291689326436000762043931899825;0.31071690056709111438237869151635;0.30852117711474680294969630267587;0.30632977243145909085342282196507;0.30414273594395091482311954678153;0.30196011698042157789245720778126;0.29978196476943363979472678693128;0.29760832843880313802742421103176;0.29543925701449103016216213291045;0.29327479941949807784595805060235;0.29111500447276039693633720162325;0.28895992088804967057313888290082;0.28680959727287308469456661441654;0.28466408212737781546763926598942;0.28252342384325679347512050298974;0.28038767070265774306037087626464;0.27825687087709327638407330596237;0.27613107242635515081730090969359;0.27401032329743024718027299968526;0.27189467132341849087140417395858;0.26978416422245476979924205807038;0.26767884959663235111548829081585;0.26557877493092885146097614779137;0.26348398759213587094762942797388;0.26139453482779029247495827803505;0.25931046376510846762641904206248;0.25723182140992395527945291178185;0.25515865464562614839394427690422;0.25309101023210422987119727622485;0.25102893480469112841291234872187;0.24897247487311280345068098540651;0.2469216768204384737650514125562;0.24487658690203506495208785054274;0.24283725124452310017986178536376;0.24080371584473742041510035960528;0.23877602656868873731710323227162;0.23675422915052951600145547672582;0.23473836919152257785015081026359;0.23272849215901270092388131160988;0.23072464338540032979807392621296;0.22872686806712028140253778474289;0.22673521126362117250607752794167;0.22474971789635006524932236970926;0.22277043274773855596748717289302;0.22079740046019324939408079444547;0.21883066553508856433296614341089;0.21687027233176314755525027067051;0.21491626506651911876488725283707;0.21296868781162520134486726419709;0.21102758449432229559405982399767;0.2090929988958327712111895380076;0.20716497465037320147018817806384;0.20524355524417009499771324954054;0.20332878401447890270858920302999;0.20142070414860685501068360281351;0.19951935868293863007849608948163;0.19762479050196579688503106808639;0.19573704233731942236929057798989;0.19385615676680656438435335076065;0.19198217621344965122531789347704;0.19011514294452969142668052882073;0.18825509907063320280684592944453;0.18640208654470197258135044648952;0.1845561471610870918347302449547;0.1827173225546063761726145457942;0.18088565419960500602059028096846;0.17906118340902044128171155534801;0.1772439513334501670627219027665;0.17543399896022404682582873647334;0.17363136711247945109803936247772;0.1718360964482409380948979560344;0.17004822745950248785717917598959;0.16826780047131500994694874862034;0.1664948556408764601677319205919;0.16472943295662600959872179373633;0.16297157223734226594302754165255;0.16122131313124526963420635183866;0.15947869511510198714532293706725;0.1577437574933358011008976973244;0.15601653939714066332555830740603;0.15429707978359774589449671111652;0.15258541743479731023214185370307;0.15088159095696357381299890221271;0.14918563877958423979919189150678;0.14749759915454385694744132706546;0.14581751015526028814051073823066;0.14414540967582700758953251352068;0.14248133543015784052698791128932;0.14082532495113619930293680226896;0.13917741558976892690679960651323;0.13753764451434363769166679958289;0.13590604870959038796840445684211;0.13428266497584750993610214209184;0.13266752992823177548231683431368;0.13106067999581216820814688617247;0.12946215142078854043461433320772;0.12787198025767421150078462233068;0.12629020237248228530901883459592;0.12471685344191751898534903375548;0.1231519689525706895416590214154;0.12159558420011912227565176181088;0.12004773428852993921722713821509;0.11850845412926847011192421632586;0.11697777844051099327415954576281;0.1154557417463615842656565746438;0.11394237837607329444367110227176;0.11243772246327410346822261999478;0.11094180794519681310106307137175;0.10945466856191377047480273176916;0.1079763378555757546983784322947;0.10650684916965552639922520938853;0.10504623564819570713524399252492;0.10359453023506115521001902379794;0.1021517656731961709581923969381;0.10071797450388575434487847815035;0.099293189066021692035235446383012;0.097877441495373140867286565480754;0.096470763723861929772596113252803;0.095073187478842358100195042425185;0.0936847442823852127880002171878;0.092305465450567336649356775524211;0.090935382092764971417864217073657;0.089574525110952041284662072939682;0.088222925199003432439326388703194;0.086880612842002546969411014288198;0.085547618315553630718994782000664;0.084223971685099041639688266513986;0.082909702805241125567192739254097;0.081604841319068810445713779699872;0.080309416657488919000229543598834;0.079023458038562588434672306902939;0.077746994466846075511057279072702;0.076480054732736613143373460843577;0.075222667411823096461631621423294;0.073974860864241431812615701346658;0.072736663234035159320001184823923;0.071508102448520294291967047684011;0.070289206217655719743930831100442;0.06908000203341801981338221594342;0.067880517169181642245234797883313;0.066690778679103335235822669346817;0.065510813397512468458927514802781;0.064340647938305295383543125353754;0.063180308694345155284821657915018;0.062029821836866561035606082441518;0.060889213314885726191505455062725;0.059758508854614589278497760460596;0.058637733958880777773714498835034;0.057526913906552734623289779847255;0.056426073751968952585400529642357;0.055335238324373370311093367490685;0.054254432227355209317209983055363;0.053183679838293862474074558122084;0.052123005307809389119455545369419;0.051072432559217451064625947765308;0.050031985287990077271302880035364;0.049001686961220980442988093273016;0.04798156081709631370912916281668;0.046971629864370534335193951847032;0.045971916881847485480960813220008;0.044982444417866696007024529535556;0.044003234789794509751459372637328;0.043034310083521154499663907699869;0.042075692152962140824001835426316;0.041127402619565822661229503864888;0.040189462871825232248568227078067;0.039261894064796187819865735946223;0.038344717119619620149251204566099;0.037437952723050116343728177525918;0.036541621326989126572470922837965;0.035655743148023777422395141911693;0.034780338166970736768490723989089;0.0339154261284257407815800888784;0.033061026540318172450838574150112;0.032217158673470969176833023084328;0.031383841561166136990834729658673;0.030561093998715427311196890514111;0.029748934543036231747947795156506;0.028947381512233305578263298230013;0.028156452985185376203247642479255;0.027376166801137580275593563783332;0.026606540559298896830853209394263;0.025847591618445353578437106989441;0.02509933709652845124082887195982;0.024361793870289027985620577965165;0.02363497857487673048382248452981;0.022918907603474591994086040358525;0.022213597106929605651259862497682;0.021519062993388182736254066185211;0.020835320927937328594481414256734;0.02016238633225159171402651736571;0.019500274384245008807425847408012;0.018849000017728712030873339244863;0.018208577922074309363154043239774;0.017579022541882538543944747289061;0.016960348076657194571481568345916;0.016352568480485274449165444821119;0.015755697461721951402324748414685;0.015169748482681433277008409277187;0.01459473475933348307620462946943;0.014030669261005046521972872142214;0.01347756471008809686651375159272;0.012935433581752309173396042751847;0.012404288103663951847721591548179;0.01188414025570999621450596350769;0.011375001769727999256787143167458;0.010876884129241204401949971725116;0.010389798569200026090442179338424;0.009913756075728086258891380566638;0.0094487673858749121613698207511334;0.0089948429873734636608162418269785;0.0085519931184036557247907239798224;0.008120227767361598569806346858968;0.0076995566726339448315741265105316;0.0072899893223787315399420094763627;0.0068915349543108850305372925504344;0.0065042025554942206611030997009948;0.0061280008621386050648993659706321;0.0057629383594029470749831034481758;0.0054090232812036287413093305076472;0.0050662636100292091079211331816623;0.0047346670767599019491456147079589;0.0044142411604936038216351334995124;0.0041049930883769181200193543190835;0.0038069298354423408703439690725645;0.0035200581244507755940276183537208;0.0032443844257400433761517888342496;0.0029799149570789440488738364365418;0.0027266556835268129788119040313177;0.0024846123172992951033677400118904;0.0022537903176392259929627925885143;0.00203419489069373016221220495936;0.0018258309893965374293145487172296;0.0016287033133565165243794581328984;0.00144281630875153776827346518985;0.001268174168228275444647579206503;0.0011047808308075057759367609833134;0.00095263998179551112599483531084843;0.00081175505270059122864267919794656;0.00068212922115606922091046726563945;0.00056376541084829367989073034550529;0.00045666629145085790852931495464873;0.00036083427856448135884193106903695;0.00027627153366222012564890064822976;0.00020297996404095020039903829456307;0.00014096122277840184011665769503452;9.0216708695634029169241330237128e-05;5.0747566325726189973011059919372e-05;2.2554685887743453065468202112243e-05;5.6387032669191761158344888826832e-06],dataType);props.OverlapLength = cast(882,dataType);
    props.SampleRate = cast(44100,dataType);
    props.FFTLength = uint16(1323);
    props.NumFeatures = uint8(41);
    end
    
    function [config, outputIndex] = getConfig(dataType, props)
    powerNormalizationFactor = 1/(sum(props.Window)^2);
    
    config.OneSidedSpectrumBins = uint16(1:662);
    
    linearSpectrumFrequencyBins = 1:662;
    config.linearSpectrum.FrequencyBins = uint16(linearSpectrumFrequencyBins);
    config.linearSpectrum.NormalizationFactor = cast(2*powerNormalizationFactor,dataType);
    
    melFilterbank = designAuditoryFilterBank(props.SampleRate, ...
        FrequencyScale="mel", ...
        MelStyle="oshaughnessy", ...
        FFTLength=props.FFTLength, ...
        OneSided=true, ...
        FrequencyRange=[0 22050], ...
        NumBands=32, ...
        Normalization="bandwidth", ...
        FilterBankDesignDomain="linear");
    melFilterbank = melFilterbank*powerNormalizationFactor;
    config.melSpectrum.FilterBank = cast(melFilterbank,dataType);
    
    FFTLength = cast(props.FFTLength,like=props.SampleRate);
    w = (props.SampleRate/FFTLength)*(linearSpectrumFrequencyBins-1);
    w(end) = props.SampleRate*(FFTLength-1)/(2*FFTLength);
    config.SpectralDescriptorInput.FrequencyVector = cast(w(:),dataType);
    
    outputIndex.mfcc = uint8(1:13);
    outputIndex.mfccDelta = uint8(14:26);
    outputIndex.mfccDeltaDelta = uint8(27:39);
    outputIndex.spectralCentroid = uint8(40);
    outputIndex.pitch = uint8(41);
    end
    
    function state = getState(dataType, numChannels)
    state.NumChannels = numChannels;
    state.mfccDelta = zeros(8,13,numChannels,dataType);
    state.mfccDeltaDelta = zeros(8,13,numChannels,dataType);
    end
    
    function state = reset(state)
    state.mfccDelta(:,:,:) = 0;
    state.mfccDeltaDelta(:,:,:) = 0;
    end
    
    function y = applyFilterBank(filterBank, Z, dataType, varargin)
    if isempty(coder.target)
        y = filterBank*Z;
    else
        % Generate optimized C/C++ code for filter bank operation
        [numBands,filterLength] = size(filterBank);
        numChan = size(Z,2);
        
        if nargin == 3
            y = zeros(numBands,numChan,dataType);
        else
            y = varargin{1};
        end
        
        for channel = 1:numChan
            temp = zeros(numBands,1,dataType);
            for jj = 1:filterLength
                temp = temp + Z(jj,channel)*filterBank(:,jj);
            end
            y(:,channel) = temp;
        end
    end
    end
    

    The generated function contains help text that indicates any requirements on the input. In this example, the sample rate of the input should be 44.1 kHz, the frame input to the function should be 1323 samples, and successive frames should be overlapped by 882 samples before calling the function. The differences between the audioFeatureExtractor object and the function are described in more detail in Approximate Equivalency Between audioFeatureExtractor and Generated Function.

    help extractAudioFeatures
     extractAudioFeatures Extract multiple features from streaming audio
        featureVector = extractAudioFeatures(audioIn) returns audio features
        extracted from audioIn.
     
        featureVector = extractAudioFeatures(audioIn,Reset=TF) returns feature extractors
        to their initial conditions before extracting features.
     
        Parameters of the audioFeatureExtractor used to generate this
        function must be honored when calling this function.
         - Sample rate of the input should be 44100 Hz.
         - Frame length of the input should be 1323 samples.
         - Successive frames of the input should be overlapped by
           882 samples before calling extractAudioFeatures.
     
     
           % Example 1: Extract features
             source = dsp.ColoredNoise();
             inputBuffer = dsp.AsyncBuffer;
             for ii = 1:10
                 audioIn = source();
                 write(inputBuffer,audioIn);
                 while inputBuffer.NumUnreadSamples > 441
                     x = read(inputBuffer,1323,882);
                     featureVector = extractAudioFeatures(x);
                     % ... do something with featureVector ...
                 end
              end
     
     
           % Example 2: Extract features from speech regions only
             [audioIn,fs] = audioread("Counting-16-44p1-mono-15secs.wav");
             audioIn = resample(audioIn,44100,fs);
             source = dsp.AsyncBuffer(size(audioIn,1));
             write(source,audioIn);
             TF = false;
             while source.NumUnreadSamples > 441
                 x = read(source,1323,882);
                 isSilence = var(x) < 0.01;
                 if ~isSilence
                     featureVector = extractAudioFeatures(x,Reset=TF);
                     TF = false;
                 else
                     TF = true;
                 end
                 % ... do something with featureVector ...
             end
     
     
           % Example 3: Generate code that does not use reset
             targetDataType = "single";
             codegen extractAudioFeatures -args {ones(1323,1,targetDataType)}
             source = dsp.ColoredNoise(OutputDataType=targetDataType);
             inputBuffer = dsp.AsyncBuffer;
             for ii = 1:10
                 audioIn = source();
                 write(inputBuffer,audioIn);
                 while inputBuffer.NumUnreadSamples > 441
                     x = read(inputBuffer,1323,882);
                     featureVector = extractAudioFeatures_mex(x);
                     % ... do something with featureVector ...
                 end
              end
     
     
           % Example 4: Generate code that uses reset
             targetDataType = "single";
             codegen extractAudioFeatures -args {ones(1323,1,targetDataType),"Reset",true}
             [audioIn,fs] = audioread("Counting-16-44p1-mono-15secs.wav");
             audioIn = resample(audioIn,44100,fs);
             source = dsp.AsyncBuffer(size(audioIn,1));
             write(source,cast(audioIn,targetDataType));
             TF = false;
             while source.NumUnreadSamples > 441
                 x = read(source,1323,882);
                 isSilence = var(x) < 0.01;
                 if ~isSilence
                     featureVector = extractAudioFeatures_mex(x,Reset=TF);
                     TF = false;
                 else
                     TF = true;
                 end
                 % ... do something with featureVector ...
             end
     
        See also audioFeatureExtractor, dsp.AsyncBuffer, codegen.
    

    The examples in the help show how to use the function directly in MATLAB and how to generate C/C++ code. Run the first example to see how to use the function to extract features in MATLAB.

    source = dsp.ColoredNoise();
    inputBuffer = dsp.AsyncBuffer;
    for ii = 1:10
        audioIn = source();
        write(inputBuffer,audioIn);
        while inputBuffer.NumUnreadSamples > 441
            x = read(inputBuffer,1323,882);
            featureVector = extractAudioFeatures(x);
            % ... do something with featureVector ...
        end
    end

    Run the second example to see how to extract features in MATLAB while using the optional "Reset" name-value pair. The Reset name-value pair enables you to reset states on the function. For example, if you are only concerned with extracting features from regions of voiced speech and want to avoid the overhead of extracting features constantly, you can use the "Reset" parameter to avoid bleeding feature information between regions.

    [audioIn,fs] = audioread("Counting-16-44p1-mono-15secs.wav");
    source = dsp.AsyncBuffer(size(audioIn,1));
    write(source,audioIn);
    TF = false;
    while source.NumUnreadSamples > 441
        x = read(source,1323,882);
        isSilence = var(x) < 0.01;
        if ~isSilence
            featureVector = extractAudioFeatures(x,"Reset",TF);
            TF = false;
        else
            TF = true;
        end
        % ... do something with featureVector ...
    end

    Run the third example to see how to generate code that does not include the ability to reset state. When generating code that does not use the 'Reset' parameter, only specify a prototype for the audio input argument. The following code requires MATLAB Coder™.

    targetDataType = "single";
    codegen extractAudioFeatures -args {ones(1323,1,targetDataType)}
    Code generation successful.
    
    source = dsp.ColoredNoise('OutputDataType',targetDataType);
    inputBuffer = dsp.AsyncBuffer;
    for ii = 1:10
        audioIn = source();
        write(inputBuffer,audioIn);
        while inputBuffer.NumUnreadSamples > 441
            x = read(inputBuffer,1323,882);
            featureVector = extractAudioFeatures_mex(x);
            % ... do something with featureVector ...
        end
    end

    Run the fourth example to see how to generate code that can reset state. When generating code that uses the 'Reset' parameter, specify prototype input arguments for the full function signature. The following code requires MATLAB Coder™.

    targetDataType = "single";
    codegen extractAudioFeatures -args {ones(1323,1,targetDataType),'Reset',true}
    Code generation successful.
    
    [audioIn,fs] = audioread("Counting-16-44p1-mono-15secs.wav");
    source = dsp.AsyncBuffer(size(audioIn,1));
    write(source,cast(audioIn,targetDataType));
    TF = false;
    while source.NumUnreadSamples > 441
        x = read(source,1323,882);
        isSilence = var(x) < 0.01;
        if ~isSilence
            featureVector = extractAudioFeatures_mex(x,'Reset',TF);
            TF = false;
        else
            TF = true;
        end
        % ... do something with featureVector ...
    end

    Approximate Equivalency Between audioFeatureExtractor and Generated Function

    When you call extract using audioFeatureExtractor, the input is buffered internally prior to feature extraction. The output from extract is an L-by-M-by-N array, where L is the number of feature vectors and is equal to the number of analysis windows. M is the number of features extracted per analysis window. N is the number of channels.

    featuresA = extract(afe,audioToVerify);
    [L,M,N] = size(featuresA)
    L = 1551
    
    M = 41
    
    N = 1
    

    When you call the generated function, extractAudioFeatures, the input should represent a single frame of audio data. The output from the generated function is an M-by-N matrix, where M is the number of features extracted and N is the number of channels. Use the generated function to extract features from the audio signal audioIn. Use the dsp.AsyncBuffer object to buffer the input into the required frame length and overlap length prior to calling extractAudioFeatures. Reshape the extracted feature vectors to match the orientation output from audioFeatureExtractor.

    frameLength = 1323;
    overlapLength = 882;
    hopLength = frameLength - overlapLength;
    
    featuresB = zeros(L,M,N);
    
    buff = dsp.AsyncBuffer('Capacity',numel(audioToVerify));
    write(buff,audioToVerify);
    
    hop = 1;
    while buff.NumUnreadSamples > hopLength
        if hop==1
            x = read(buff,frameLength);
            features = extractAudioFeatures(x,'Reset',true);
        else
            x = read(buff,frameLength,overlapLength);
            features = extractAudioFeatures(x);
        end
        featuresB(hop,:,:) = reshape(features,[1,M,N]);
        hop = hop + 1;
    end

    Visualize the difference between the output from audioFeatureExtractor and the generated function. The differences between frames are less than 1.8e-14 and are due to the different code paths being optimized for batch versus stream processing.

    differenceBetweenFrames = sum(abs(featuresA-featuresB),2);
    plot(differenceBetweenFrames)
    xlabel('Frame')
    title('Absolute Difference Between Feature Vectors')

    Input Arguments

    collapse all

    Input object, specified as an audioFeatureExtractor object.

    File name where the generated function is saved, specified as a character vector or string scalar.

    Data Types: char | string

    Flag to specify if generated function is intended for stream processing, specified as true or false.

    Data Types: logical

    Version History

    Introduced in R2020b