Need to create a generator that shift in freq. and amplitude over time ranges

6 次查看(过去 30 天)
Hi,
I wanted to create a sin generator that runs say 25 MHz for 30 msec with amplitude of 0.7 volts and then shifts to 78 MHz with 1.4 V amplituded for 150 ms and shifts to 50 MHz with 2.3 volt amplitude for another 100 ms.
I can not find a block that does that. So I went to do this via a matlab function block.
I wrote the following function:
function y = fcn(u1,u2)
%#codegen
Fs = 100;
% a vector of points in thetime ontervai 0<t<T
T = 10;
ts = Simulink.BlockDiagram.getSampleTimes('astor_my_test')
t = 0:1/Fs:T;
if (t < 25)
y = u1;
else
y= u2;
end
However, when I go to build the code, it says that only scalar is allowed in the if statment. So, I need to bring in sim time as an input. But, I can not find a way to bring in current time or make a comparison.
Is there an easy way to do this so that based on sim time, the output would be generated from a different function? I tried the switch block. but again, I got stuck creating the switch input as it does not undrestand the notion of time.
Thanks for your help

采纳的回答

Mark
Mark 2012-6-12
Thanks for the suggestion Ryan. I used two step functions along with 2 switches to activate one of the three generators for each time interval.

更多回答(0 个)

产品

Community Treasure Hunt

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

Start Hunting!

Translated by