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

5 vues (au cours des 30 derniers jours)
Mladen
Mladen le 27 Oct 2014
Réponse apportée : Hari le 24 Fév 2025
How do I write code in Matlab for sampling sine wave signal from Simulink...

Réponses (1)

Hari
Hari le 24 Fév 2025
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!

Catégories

En savoir plus sur Audio Processing Algorithm Design dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by