Main Content

このページの内容は最新ではありません。最新版の英語を参照するには、ここをクリックします。

combine

複数のデータストアのデータの結合

R2020a 以降

説明

sdsnew = combine(sds1,sds2,...,sdsn) では、入力データストアで呼び出された関数 read が返すデータを水平方向に連結することにより、複数のデータストアを結合します。

すべて折りたたむ

MATLAB® に含まれる 4 つの信号へのパスを指定します。これらの信号は、鳥の鳴き声、銅鑼、汽車、およびスプラット (ペチャッという音) の録音です。すべての信号は、8192 Hz でサンプリングされます。

folder = fullfile(matlabroot,'toolbox','matlab','audiovideo', ...
         ["chirp.mat","gong.mat","train.mat","splat.mat"]);

指定したファイルを示す信号データストアを作成します。各ファイルには、サンプル レートを示す変数 Fs が含まれています。

sds1 = signalDatastore(folder,'SampleRateVariableName','Fs');

関数 read の出力を取得し、少なくとも 80 サンプル単位に分割された局地的最大値に対してスプライン内挿を使用して信号の上側包絡線と下側包絡線を計算する関数を定義します。この関数はさらに、各信号のサンプル時間を返します。

function [dataOut,infoOut] = signalEnvelope(dataIn,info)
    [dataOut(:,1),dataOut(:,2)] = envelope(dataIn,80,'peak');
    infoOut = info;
    infoOut.TimeInstants = (0:length(dataOut)-1)/info.SampleRate;
end

関数 transform を呼び出して、2 番目のデータストア sds2 を作成します。このデータストアでは、定義した関数を使用して信号の包絡線を計算します。

sds2 = transform(sds1,@signalEnvelope,"IncludeInfo",true);

sds1sds2 を結合して 3 番目のデータストアを作成します。結合したデータストアに対して関数 read を呼び出すたびに、次の 3 列をもつ行列が返されます。

  • 1 列目は元の信号に対応します。

  • 2 列目と 3 列目は、それぞれ上側包絡線と下側包絡線に対応します。

sdsCombined = combine(sds1,sds2);

結合したデータストアから、元のデータと上側包絡線および下側包絡線を読み取って表示します。関数extractBetweenを使用して、ファイル パスからファイル名を抽出します。

tiledlayout('flow')
while hasdata(sdsCombined)
    [dataOut,infoOut] = read(sdsCombined);
    ts = infoOut{2}.TimeInstants;
    nexttile
    hold on
    plot(ts,dataOut(:,1),'Color','#DCDCDC','LineStyle',':')
    plot(ts,dataOut(:,2:3),'Linewidth',1.5)
    hold off
    xlabel('Time (s)')
    ylabel('Signal')
    title(extractBetween(infoOut{:,2}.FileName,'audiovideo\','.mat'))
end

Figure contains 4 axes objects. Axes object 1 with xlabel Time (s), ylabel Signal contains 3 objects of type line. Axes object 2 with xlabel Time (s), ylabel Signal contains 3 objects of type line. Axes object 3 with xlabel Time (s), ylabel Signal contains 3 objects of type line. Axes object 4 with xlabel Time (s), ylabel Signal contains 3 objects of type line.

sample_chirps フォルダー内の各ファイルには、チャープと 100 ~ 150 Hz の範囲のランダム サンプル レートが含まれます。指定したフォルダーを示す信号データストアを作成し、サンプル レート変数の名前を設定します。

folder = "sample_chirps";
sds = signalDatastore(folder,SampleRateVariableName="fs");

関数 read の出力を取得し、関数 pspectrum を使用して信号のパワー スペクトルを推定する関数を定義します。推定を使用して瞬時周波数を計算します。この関数はさらに、ウィンドウ セグメントの中心に対応する時点のベクトル、および信号のスペクトログラムに含まれるスペクトル推定に対応する周波数を返します。

function [dataOut,infoOut] = extractinstfreq(dataIn,info)
    [P,F,T] = pspectrum(dataIn,info.SampleRate,"spectrogram",...
             TimeResolution=0.1,OverlapPercent=40,Leakage=0.8);
    dataOut = {instfreq(P,F,T)'};
    infoOut = info;
    infoOut.CenterFrequencies = F;
    infoOut.TimeInstants = T;
end

関数 transform を呼び出して、瞬時周波数を計算する新しいデータストアを作成します。

sds2 = transform(sds,@extractinstfreq,IncludeInfo=true);

sds2 のデータは sds のデータと水平方向に連結できないため、sds のデータを cell 配列に変換します。

sds1 = transform(sds,@(x) {x});

sds1 および sds2 を組み合わせます。組み合わせたデータストアに読み取られていないファイルがある場合、新しいデータストアから読み取って、スペクトログラムを可視化します。スペクトログラムに瞬時周波数を重ね合わせます。

sdsCombined = combine(sds1,sds2);
sdsSubset = subset(sdsCombined,[1,4,9,10]);
plotID = 1;
while hasdata(sdsSubset)
    subplot(2,2,plotID)
    [sig,info] = read(sdsSubset);
    pspectrum(sig{:,1},info{:,2}.SampleRate,"spectrogram", ...
             TimeResolution=0.1,OverlapPercent=40,Leakage=0.8)
    hold on
    plot(info{:,2}.TimeInstants',sig{:,2})
    plotID = plotID + 1;
end

Figure contains 4 axes objects. Axes object 1 with title Fres = 17.8854 Hz, Tres = 93.2203 ms, xlabel Time (s), ylabel Frequency (Hz) contains 2 objects of type image, line. Axes object 2 with title Fres = 17.3141 Hz, Tres = 96.2963 ms, xlabel Time (s), ylabel Frequency (Hz) contains 2 objects of type image, line. Axes object 3 with title Fres = 18.037 Hz, Tres = 92.437 ms, xlabel Time (s), ylabel Frequency (Hz) contains 2 objects of type image, line. Axes object 4 with title Fres = 16.6729 Hz, Tres = 100 ms, xlabel Time (s), ylabel Frequency (Hz) contains 2 objects of type image, line.

入力引数

すべて折りたたむ

組み合わせる信号データストア。2 つ以上のコンマ区切りの signalDatastore オブジェクトとして指定します。

出力引数

すべて折りたたむ

組み合わせたデータをもつ新しいデータストア。CombinedDatastore オブジェクトとして返されます。

組み合わせたデータストアで read を呼び出し、各入力データストアで read を呼び出すことにより、データを水平方向に連結します。

バージョン履歴

R2020a で導入