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

조회 수: 2 (최근 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 CenterFile Exchange에서 Audio Processing Algorithm Design에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by