%% Read Multiple Variables from Files In Signal Datastore
% Specify the path to example files included with Signal Processing Toolbox™. Each file contains two signals and a random sample rate fs ranging from 3000 to 4000 Hz.
% The first signal x1 consists of a set of pulses of decreasing duration, separated by regions of oscillating amplitude and fluctuating frequency with an increasing trend.
% The second signal x2 is a chirp with sinusoidally varying frequency content.

folder = fullfile(matlabroot,'examples','signal','data','dataset');

% Create a signal datastore that points to the specified folder and set the names of the signal variables and sample rate. While the datastore has data, read each observation and visualize their spectrograms.

sds = signalDatastore(folder,'SignalVariableNames',['x1';'x2'],'SampleRateVariableName','fs');
plotID = 1;
while hasdata(sds) 
    [data,info] = read(sds);
    subplot(2,2,plotID)
    pspectrum(data{1},info.SampleRate,'OverlapPercent',50,'Leakage',1,'TwoSided',true,'spectrogram')
    subplot(2,2,plotID+1)
    pspectrum(data{2},info.SampleRate,'OverlapPercent',90,'Leakage',0.4,'TwoSided',true,'spectrogram')
    plotID = plotID + 2;
end

% Copyright 2019 The MathWorks, Inc.