Importing Voltage Data to AC Voltage Source in Simulink

31 次查看(过去 30 天)
I would like to import voltage data from text in matlab and then I would like to use this data in simulink AC voltage source .I have written one code but not sure is it okay or not as it is not
% Import voltage data from text file
data = importdata('voltage_data.txt');
time = data.data(:, 1); % time data in seconds
voltage = data.data(:, 2); % voltage data in volts
mdl = 'ac_source_model';
open_system(mdl);
set_param(mdl, 'Solver', 'ode23');
% Add AC voltage source to model
add_block('Simscape / Electrical / Specialized Power Systems / Sources/AC Voltage Source', [mdl '/Voltage Source']);
set_param([mdl '/Voltage Source'], 'Amplitude', 'voltage');
set_param([mdl '/Voltage Source'], 'Frequency', '50');
set_param([mdl '/Voltage Source'], 'Phase', '0');
% Run simulation
sim(mdl);
It can't find the block from simulink using this code.Is this way is okay or is there any other way I can use variable text data in simulink(As Voltage Source). N:B:I have read that there is a block called From Workspace which can also be used for this purpose

采纳的回答

Sara Nadeau
Sara Nadeau 2023-4-24
I believe you'll need to load the data from the workspace into Simulink using a loading block that produces the signal that would be the input for the Voltage Source block. The From Workspace block is one of the loading blocks you could use.
It's not clear to me exactly what your data looks like based on the code you showed in your answer. To load data into Simulink, I believe you'll need to remove any non-numeric text from each value. For example, if your text file captures the time as "1 s" including "s" for "s", you'd need to get rid of that "s" part. If your file contains only numbers in each column, then you don't need to worry about this.
Assuming your data includes only numbers in each column, here's the basic process for loading data using the From Workspace block:
  1. Add the From Workspace block to your model and connect it.
  2. In the parameters for the From Workspace block, specify the name of the variable you'll use for the signal data. For example, voltageData.
  3. In the MATLAB Command Window, create the variable for the From Workspace block to load using the data you loaded into MATLAB from your txt file.
For step 3, you'll need to create the variable using a format that the From Workspace block supports. The simplest format is array:
voltageData = [time voltage];
Array format has several limitations and stipluations, though, including that the values must be double. In general, timeseries format has better support.
voltageData = timeseries(voltage,time);
Here's a page that shows example code for each format the From Workspace block supports: https://www.mathworks.com/help/simulink/ug/load-data-using-the-from-workspace-block.html
Here's the reference page for the From Workspace block, which provides more information about its usage: https://www.mathworks.com/help/simulink/slref/fromworkspace.html
  2 个评论
Mashrur Zawad
Mashrur Zawad 2023-4-27
I want to give periodic voltage data from workspace(Which will be read from text file) in here.I am bit confused how to do that
Sara Nadeau
Sara Nadeau 2023-4-27
Block parameter values are typically specified as a value that's used for the calculations at each time step. If you want the voltage amplitude to vary based on external data and time values, you might need to use the From Workspace block to create a Simulink signal then use the Controlled Voltage Source block to convert the Simulink signal into the physical voltage signal for Simscape: https://www.mathworks.com/help/sps/powersys/ref/controlledvoltagesource.html
The Simulink-PS and PS-Simulink blocks might also be helpful: https://www.mathworks.com/help/simscape/ref/simulinkpsconverter.html

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Electrical Sensors 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by