How do I write code in Matlab for sampling sine wave signal from Simulink...

4 ビュー (過去 30 日間)
Mladen
Mladen 2014 年 10 月 27 日
回答済み: Hari 2025 年 2 月 24 日
How do I write code in Matlab for sampling sine wave signal from Simulink...

回答 (1 件)

Hari
Hari 2025 年 2 月 24 日
Hi Mladen,
I understand that you want to write MATLAB code to sample a sine wave signal generated in a Simulink model.
I assume you have a Simulink model with a sine wave block and you want to capture or sample this signal using MATLAB.
In order to sample a sine wave signal from Simulink using MATLAB, you can follow the below steps:
Create a Simulink Model:
Open Simulink and create a new model with a “Sine Wave” block and a “To Workspace” block to output the signal.
open_system('new_model'); % Open a new Simulink model
Configure the Sine Wave Block:
Set the parameters of the “Sine Wave” block such as amplitude, frequency, and sample time according to your requirements.
set_param('new_model/Sine Wave', 'Amplitude', '1', 'Frequency', '1', 'SampleTime', '0.01');
Connect the Blocks:
Connect the “Sine Wave” block to the “To Workspace” block to store the signal in the MATLAB workspace.
add_line('new_model', 'Sine Wave/1', 'To Workspace/1');
set_param('new_model/To Workspace', 'VariableName', 'sineData');
Simulate the Model:
Run the simulation for a specified duration to capture the sine wave data.
sim('new_model', 'StopTime', '10'); % Simulate for 10 seconds
Analyze the Sampled Data:
Access and plot the sampled sine wave data stored in the workspace.
plot(sineData.time, sineData.signals.values);
xlabel('Time (s)');
ylabel('Amplitude');
title('Sampled Sine Wave');
Refer to the documentation of “sim” function to know more about its usage:
Hope this helps!

カテゴリ

Help Center および File ExchangeAudio Processing Algorithm Design についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by