
dsp.SpectrumEstimatorを使用して得られた結果をリアルタイムで順次保存するにはどうすればよいか。
조회 수: 5 (최근 30일)
이전 댓글 표시
リアルタイムで音響信号を取り込み,TimeScopeで波形を,SpectrumAnalyzerでスペクトルを表示させ,波形をAudioFileWriterで記録するプログラムをtestbenchGeneratorExampleAppで作成しました。さらに,スペクトルを計算するプログラムのdsp.SpectrumEstimatorを追加しました。実行すると,ワークスペースのansに最終フレームのスペクトルの結果が格納されていることを確認できました。ここまでのプログラムを添付します。しかし,ansの内容をリアルタイムでファイルに順次保存したいのですがその方法が分かりません。どうかその方法を教えてください。初歩的な質問で申し訳ないですがよろしくお願いします。
댓글 수: 0
채택된 답변
Tohru Kikawada
2017년 6월 12일
"リアルタイムでファイルに順次保存"とありますが、どのような形式で保存したいのでしょうか。
たとえば、MAT-fileで保存するということであれば、 dsp.MatFileWriter が使用できます。
dsp.MatFileWriter を使用してスペクトルを保存するコードと、実行結果を可視化する例を下記に示します。
ご参考まで。

numIterations = 100;
Fs = 44100;
L = 1024;
src1= audioDeviceReader;%入力
sink1_1 = dsp.SpectrumAnalyzer('SampleRate',Fs, ...
'PlotAsTwoSidedSpectrum',false, ...
'SpectralMask',SpectralMaskSpecification, ...
'Position',[650,50,650,600],...
'ShowLegend',true,...
'Window','Hann',...
'WindowLength',L);
sink1_2 = dsp.TimeScope('SampleRate',Fs, ...
'TimeSpan',1, ...
'AxesScaling','Manual', ...
'BufferLength',Fs*2, ...
'ShowLegend',true, ...
'ShowGrid',true, ...
'Position',[0,50,650,600],...
'YLimits',[-0.1 0.1]);
clear dspStreamingPassthrough;
sink1_3 = dsp.AudioFileWriter('Filename','output1.wav');
sink1_4 = dsp.SpectrumEstimator('SampleRate',Fs,...
'SpectrumType','Power',...
'PowerUnits','dBm' ,...
'FrequencyRange','onesided',...
'OutputMaxHoldSpectrum',true,...
'OutputMinHoldSpectrum',true);
filename = 'spectrum.mat';
mfw = dsp.MatFileWriter(filename, 'VariableName', 'spectrum');
for i = 1:numIterations
in1 = src1();
% User Algorithm
% The default algorithm dspStreamingPassthrough does no operation and
% merely passes through the inputs to the outputs. Replace it with your
% custom function.
out1 = dspStreamingPassthrough(in1);
% Sinks
sink1_1(out1);
sink1_2(out1);
sink1_3(out1);
[pxx,pmax,pmin] = sink1_4(out1);
mfw(pxx');
end
% Clean up
release(src1);
release(sink1_1);
release(sink1_2);
release(sink1_3);
release(sink1_4);
release(mfw); % This will close the MAT file
% Visualize
load('spectrum');
f = Fs*(0:(L/2))/L;
t = (0:(size(spectrum)-1))/Fs;
[X,Y] = meshgrid(f,t);
figure, mesh(X,Y,spectrum);
ylabel('Time(s)'); xlabel('Frequency(Hz)'); zlabel('Power(dBm)');
댓글 수: 0
추가 답변 (0개)
참고 항목
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!