Simulate sine wave with timestep different than overall model timestep
Show older comments
Hello All,
I needed your help in understanding of where the mistake is and wanted to know how can I implement the following:
I have a simulink model running a certain fixed time step. And inside the model there is a sine wave function connected with a digital clock that is creating a sine wave with sample rate set to -1(inherit). Meaning it will use t=simulink model timestep. Instead of -1 I would like to use a time step which is faster than Simulink time step. I tried using different values but I am getting an error: "Digital Clock has an invalid sample time. Only constant (inf) or inherited (-1) sample times are allowed in the asynchronous subsystem".
Can you please suggest me what other options can I try?
Appreciate all your help and guidance.
Answers (1)
Umar
on 17 Aug 2024
0 votes
Hi
Instead of a digital clock, you can create a MATLAB Function block that generates the desired sine wave at a faster rate which can be programmed by you to sample at your specified rate. Let me illustrate to you on how to implement a sine wave in a MATLAB Function block:
function y = fastSineWave(t)
% Define the frequency and amplitude
frequency = 1; % Hz
amplitude = 1;
% Generate the sine wave
y = amplitude * sin(2 * pi * frequency * t);
end
For more information on matlab function, please refer to
https://www.mathworks.com/help/simulink/slref/matlabfunction.html
Hope this helps. Please let me know if you have any further questions.
Categories
Find more on Simulink in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!