Accessing simParameters.Carrier inside MATLAB function block in Simulink

14 ビュー (過去 30 日間)
Viraj
Viraj 2025 年 6 月 26 日
編集済み: Rahul 2025 年 7 月 1 日
I am trying to implement PDSCH transceiver in simulink using simulink blocks and matlab functions.
I have already implemented this in Matlab code now want to implement in simulink, so now while doing this i am facing some problems using simParameters.Carrier in simulink matlab fucntion.
I have used variable carrier = simParameters.Carrier in matlab code. Now i want to access this as when i want to do OFDM Modulation i am using matlab function and while in this function i am writing
function txWaveform = OFDMModulator(pdschGrid, carrier)
txWaveform = nrOFDMModulate(carrier, pdschGrid);
end
But now i dont know how to access this carrier (in which complete configuration is present) in Matlab function.
Any suggestions on how I can get the data stored in this struct variable accessible inside the Simulink MATLAB function block? Thank you.

回答 (1 件)

Rahul
Rahul 2025 年 7 月 1 日
編集済み: Rahul 2025 年 7 月 1 日
Hi Viraj,
I understand that you are trying to transition a PDSCH transceiver implementation from MATLAB code into a Simulink model, and are currently facing issues while accessing the carrier configuration structure within a MATLAB Function block.
In Simulink, structured data such as the 'carrier' configuration cannot be accessed directly inside a MATLAB Function block unless it is explicitly passed in as an input and its structure is well-defined. To achieve this, you can pass the 'carrier' variable into the function block as an input and define its structure using a Simulink Bus.
To begin, the 'carrier' structure can be saved to a MAT file using the following command:
save('carrierStruct.mat', '-struct', 'simParameters', 'Carrier');
This MAT file can then be loaded as shown below, and a bus object can be created from the structure using the 'Bus.createObject' API, which typically creates a bus named 'slBus1':
carrier = load('carrierStruct.mat');
Simulink.Bus.createObject(carrier);
Within the MATLAB Function block, the 'carrier' input can then be defined using the 'Ports and Data Manager', with its data type set to 'CarrierBus'. Here is how the function can be defined in this scenario:
function txWaveform = OFDMModulator(pdschGrid, carrier)
txWaveform = nrOFDMModulate(carrier, pdschGrid);
end
To provide the required input to this function, a Constant block can be used in the Simulink model, with its value set to 'simParameters.Carrier' and its data type set to 'CarrierBus'. This ensures that the structure is passed properly into the function, allowing access to its fields in a manner similar to what is done in MATLAB scripts.
Hope this helps!

カテゴリ

Help Center および File ExchangeRF Blockset Models for Transceivers についてさらに検索

製品


リリース

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by