Export Spectrum Analyser trace to workspace or file

Hi, as the title says, I want to find out how to export the trace (dBm) from a Spectrum Analyser, in Simulink, to either the workspace or preferably to an external (EXCEL spreadsheet) file ?

1 Comment

Assuming it is possible to export the dBm trace from the Simulink spectrum analyzer to an excel spreadsheet, please see my latest attempts :
>> sablock = fsk, '/Spectrum Analyzer' ;
sablock =
0
4
0
0
0
0
1
>> config = get.param ( [sablock],'Scope Configuration');
Undefined variable "get" or class "get.param".
>> config = get_param ( [sablock],'Scope Configuration');
Error at element 1 of first input to get_param:
block_diagram does not have a parameter named 'Scope Configuration'
>> config = get_param ( [sablock],'Spectrum Analyzer Configuration');
Error at element 1 of first input to get_param:
block_diagram does not have a parameter named 'Spectrum Analyzer Configuration'
>> config = get_param ( [sablock],'dBm');
Error at element 1 of first input to get_param:
block_diagram does not have a parameter named 'dBm'
Interesting the sablock command returns a (1x7) array with numbers I dont recognise and why 7 values ?
I think I need to specify a Spectrum Analyzer Configuration object for the spectrum analyzer block, then use the
spectrumTable = getSpectrumData(scope) command to read the dBm trace ? As you can see from my attempts above I am having trouble specifying the sa configuration using the config and get_param commands/functions.
Any help would be most welcome.

Sign in to comment.

Answers (1)

Fangjun Jiang
Fangjun Jiang on 17 Mar 2020
Edited: Fangjun Jiang on 17 Mar 2020
Run this to open the document and example, I believe the answer can be found there. The key is probabaly the function getMeasurementsData()
web(fullfile(docroot, 'dsp/ref/dsp.spectrumanalyzer.getmeasurementsdata.html'))
or from https://www.mathworks.com/help/releases/R2019b/dsp/ref/dsp.spectrumanalyzer.getmeasurementsdata.html

8 Comments

Hi Fangjun, many thanks for you response.
Unfortunately, I am still not having much success :
>> sablock = fsk, '/Spectrum Analyzer' ;
sablock =
0
4
0
0
0
0
1
>> data = [];
>> data = [data;getMeasurementsData(sablock)];
Undefined function 'getMeasurementsData' for input arguments of type 'double'.
>> data = getMeasurementsData(sablock)
Undefined function 'getMeasurementsData' for input arguments of type 'double'.
>> data = [data;getMeasurementsData(sablock)];
Undefined function 'getMeasurementsData' for input arguments of type 'double'.
>> sablock = fsk, '/Spectrum Analyzer' ;
sablock =
0
4
0
0
0
0
1
>> cfg = get_param ( [sablock],'ScopeConfiguration');
Error at element 1 of first input to get_param:
block_diagram does not have a parameter named 'ScopeConfiguration'
>> cfg.CursorMeasurements.Enable = true;
cfg.ChannelMeasurements.Enable = true;
cfg.PeakFinder.Enable = true;
cfg.DistortionMeasurements.Enable = true;
>> data = getMeasurementsData(cfg)
Undefined function 'getMeasurementsData' for input arguments of type 'struct'.
>> Undefined function 'getMeasurementsData' ?
I did a search for undefined function and there seemed to be a lot of replies dealing with setting the correct path ?
I dont see how this would be applicable in my case ?
What are you trying to do with this? "sablock" is goint to have the same value as "fsk"
sablock = fsk, '/Spectrum Analyzer'
Open the html weblink, there is a model, there is a spectrum analyzer block, there are example code!
I have used a very simple model in simulink called fsk.slx to generate a baseband m=2 fsk signal.
I have also used Fourier Analysis to calculate the frequency response of such a signal and plotted it using EXCEL spreadsheet.
I was hoping to export the frequency response in simulink into EXCEL so I could compare the two responses.
Then, it should be sablock='fsk/Spectrum Analyzer'. Or, click (once) the Spectrum Analyzer block in your model, go to Command Window, type "sablock=gcb" and you'll get the full path of the Spectrum Analyzer block. Then follow the example in the webpage.
I don't know why your previous post shows some numerical numbers.
I have used the following MATLAB code :
>> scope = fsk, '/ Spectrum Analyzer ' ;
>> config = get_param (gcb, 'ScopeConfiguration');
>> specTable = getSpectrumData(config)
To get the following result :
specTable =
1×3 table
SimulationTime Spectrum FrequencyVector
______________ ______________ _______________
[2.0000e-05] [163×1 double] [163×1 double]
I dont really understand the code but it gets me what I want.
It would be nice to know why :
1. Only 3 parameters are returned.
2. The simulation time, spectrum and frequencyvector parameters were selected to be returned.
3. 163 samples were returned.
4. scope = fsk, '/ Spectrum Analyzer ' ; returns a 1x7 array of numbers, mostly zero.
They all depend on your simulation data and setting.
If your model name is 'fsk.slx', then specifying the full path of the scope block should be scope='fsk/Spectrum Analyzer'. type "fsk" before and after the simulation to see what happened. "fsk" should just bring up your model.
"They all depend on your simulation data and setting." - Is there something I can read to help me understand this ? For example I have stipulated 100 samples in my model but 163 are returned ?
Tried adding path in MATLAB with the following results ?
addpath('Derek/1electronics/1TELECOMMS/4MODULATION/1FSK/2-FSK MODULATOR/BASEBAND/NONCOHERENT')
Warning: Name is nonexistent or not a directory: C:\Derek\1electronics\1TELECOMMS\4MODULATION\1FSK\2-FSK
Modulator\BaseBand\NONCOHERENT\Derek\1electronics\1TELECOMMS\4MODULATION\1FSK\2-FSK
MODULATOR\BASEBAND\NONCOHERENT
> In path (line 109)
In addpath (line 86)
>> addpath('Derek/1electronics/1TELECOMMS/4MODULATION/1FSK/2-FSK MODULATOR/BASEBAND/NONCOHERENT'/fsk.slx')
Undefined variable "fsk" or class "fsk.slx".

Sign in to comment.

Products

Asked:

on 16 Mar 2020

Edited:

on 19 Mar 2020

Community Treasure Hunt

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

Start Hunting!