How to display data saved with getSpectrumData? Why are saved values different from input?

조회 수: 3 (최근 30일)
Hello dear community,
in my example code I create two sinus signals, display it with spectrumAnalyzer and save data to tables (later I will use it to receive data from hardware device). There are 3 ways to display it: 1. time I just display a created sinus-signal
and save it directly to variable "y" directly and to variable "data" using getSpectrumData function.
When I display "y" it works perfectly:
when I try to display "data" saved by getSpectrumData I get no signal information:
What is wrong?
Thank you!
% create two sinus signals
wave = dsp.SineWave(Frequency=100,SampleRate=1000);
wave.SamplesPerFrame = 1000;
wave2 = dsp.SineWave(Frequency=150,SampleRate=1000);
wave2.SamplesPerFrame = 1000;
% init variables
data = [];
y = [];
frames = 500;
% init scope 1
scope = spectrumAnalyzer(SampleRate=wave.SampleRate,...
ViewType="spectrum-and-spectrogram",...
FrequencyScale="Linear");
for ii = 1:frames
x = wave() + 0.5*wave2()+ 0.05*randn(1000,1);
scope(x); % spectrum of created signal x
if scope.isNewDataReady
y = [y,x]; %save input signal
data = [data;getSpectrumData(scope)]; % save signal using getSpectrumData
end
end
release(scope)
% init scope 2
scope = spectrumAnalyzer(SampleRate=wave.SampleRate,...
ViewType="spectrum-and-spectrogram",...
FrequencyScale="Linear");
for a = 1:width(y)
scope(y(:,a)) % spectrum of saved signal y
pause(0.01)
end
release(scope)
% init scope 3
scope = spectrumAnalyzer(SampleRate=wave.SampleRate,...
ViewType="spectrum-and-spectrogram",...
FrequencyScale="Linear");
for a = 1:height(data)
scope(data.Spectrum{a,1}) % spectrum of saved signal using getSpectrumData
pause(0.01)
end
  댓글 수: 2
Khodour Al Kadry
Khodour Al Kadry 2023년 1월 24일
Hi Nick
getSpectrumData will return the computed spectrum in frequency domain. In your third case where you are plotting the saved data using getSpectrumData, you are actually plotting the frequency response of data that is already in frequency domain.What you should do, is set the InputDomain='frequency' on spectrumAnalyzer, this will allow you to plot pre-computed spectrum (frequency doamin data).
Regards
-Khodour

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Scopes and Data Logging에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by