主要内容

generateMATLABFunction

创建MATLAB函数兼容C / c++代码生成

自从R2021b

    描述

    例子

    generateMATLABFunction (超临界流体)生成代码基于输入特征提取器对象超临界流体并打开一个无标题的文件包含的功能extractSignalFeatures。取决于你如何设置的函数签名FeatureFormat输入特征提取器对象的属性。

    • 当你指定FeatureFormat作为“矩阵”,生成的MATLAB®函数签名:

      [特性、信息framelimits] = extractSignalFeatures (x)
      签名等同于:
      (特性、信息framelimits) =提取(超临界流体,x)

    • 当你指定FeatureFormat作为“表”,生成的MATLAB函数签名:

      特点= extractSignalFeatures (x)
      签名等同于:
      =特征提取(超临界流体,x)

    例子

    全部折叠

    创建一个signalTimeFeatureExtractor对象提取均值,标准差,随机信号的峰值。

    x = randn (1000 1);超临界流体= signalTimeFeatureExtractor (FrameSize = 100,FrameOverlapLength = 10,意味着= true, StandardDeviation = true,PeakValue = true)
    超临界流体=signalTimeFeatureExtractor属性:属性FrameSize: 100 FrameOverlapLength: 10 SampleRate: [] IncompleteFrameRule:“下降”FeatureFormat:“矩阵”启用的特性意味着,StandardDeviation, RMS PeakValue禁用功能,ShapeFactor,信噪比,THD, SINAD, CrestFactor ClearanceFactor, ImpulseFactor

    调用generateMATLABFunction在对象上。生成的函数extractSignalFeatures相当于调用吗提取函数超临界流体。保存到当前文件夹并查看函数脚本。

    generateMATLABFunction(医药)类型extractSignalFeatures
    函数[特性、信息frameLimits] = extractSignalFeatures (x) % extractSignalFeatures提取信号特征%[特性、信息frameLimits] = extractSignalFeatures (x)返回一个矩阵包含特征提取输入x %,信息,特定功能结构映射%输出特征矩阵的列位置%和frameLimits的i行包含% i帧的开始和结束的限制。% % signalTimeFeatureExtractor参数用于生成这个%函数必须尊敬当调用这个函数。%由MATLAB 9.11 (R)和信号处理工具箱8.7。%上生成:10 - 2021年6月——08:25:02。% # codegen如果istimetable xInTT = x (x) {:,:};其他xInTT = x;如果isrow (xInTT)鑫= xInTT (:);其他新= xInTT;结束数据类型=类(新);signalLength =大小(新1); numChannels = size(xIn,2); frameSize = 100; frameOverlapLength = 10; frameRate = frameSize - frameOverlapLength; featureMatrix = zeros(0,1,dataType); numFeatureCols = 0; numFeatureRows = 0; frameLimits = zeros(0,2,dataType); info = struct('Mean',0,'StandardDeviation',0,'PeakValue',0); for idx = 1:numChannels if numChannels == 1 xChannel = xIn; else xChannel = xIn(:,idx); end startIdx = 1; endIdx = frameSize; while startIdx <= signalLength if endIdx > signalLength break; end featureIndex = 1; xFrame = xChannel(startIdx:endIdx,1); meanValue = mean(xFrame); numCurrentFeature = numel(meanValue); info.Mean = featureIndex; featureIndex = featureIndex+numCurrentFeature; standardDeviation = std(xFrame); numCurrentFeature = numel(standardDeviation); info.StandardDeviation = featureIndex; featureIndex = featureIndex+numCurrentFeature; peakValue = max(abs(xFrame)); info.PeakValue = featureIndex; featureVector = [meanValue(:);standardDeviation(:);peakValue(:)]; featureMatrix = [featureMatrix;featureVector]; if startIdx == 1 numFeatureCols = size(featureVector,1); end if idx == 1 numFeatureRows = numFeatureRows+1; frameLimits = [frameLimits;[startIdx endIdx]]; end startIdx = startIdx+frameRate; endIdx = startIdx+frameSize-1; end end tempFeatureMatrix = reshape(featureMatrix,numFeatureCols,numFeatureRows,numChannels); features = permute(tempFeatureMatrix,[2,1,3]); end

    你可以换电话提取在代码中调用生成的函数。输出是相同的。

    features1 =提取(超临界流体,x)
    features1 11 x3 = 0.0842 1.0690 2.7526 0.0500 1.0516 2.9491 0.1901 1.0356 2.7304 0.1209 0.9171 2.4366 0.0443 0.9399 2.4247 -0.1153 1.0490 3.5699 -0.1001 0.9530 2.4124 0.0616 0.9959 2.7485 -0.0263 0.9482 2.4868 -0.0234 0.9876 3.1585。
    features2 = extractSignalFeatures (x)
    features2 11 x3 = 0.0842 1.0690 2.7526 0.0500 1.0516 2.9491 0.1901 1.0356 2.7304 0.1209 0.9171 2.4366 0.0443 0.9399 2.4247 -0.1153 1.0490 3.5699 -0.1001 0.9530 2.4124 0.0616 0.9959 2.7485 -0.0263 0.9482 2.4868 -0.0234 0.9876 3.1585。

    版权2020年MathWorks公司。

    输入参数

    全部折叠

    特征提取器对象,指定为一个signalFrequencyFeatureExtractor对象或一个signalTimeFeatureExtractor对象。

    版本历史

    介绍了R2021b