How to convert a continous time simulink model to discrete time model in Simulink? - simulink

For example, I have a controller consisting of integrator and sine web signal combined in the input. My question may be very naive to you, please help me to understand.
In the picture I have a frequency which is the input of an integrator then two cos and sine block. How to make each Simulink block discrete using ZOH and rate transition block in Simulink.

Two potential solutions
Change the sample time of the sinewave to something that is non-zero. This will make it a discrete signal
Use a Zero Order Hold (as you've mentioned) to convert the signal to discrete, you will need to specify a sample time for this block to perform the conversion. Setting the time to 0.5 will sample the signal every half second for example.

Related

Obtain frequency spectrum for four basic signals using simulink blocks

I tried using the 'Spectrum Analyzer' and those signal blocks (sine, pulse generator, triangle generator and sawtooth generator) separately of course, but the spectrum block needs a discrete signal or a non-infinite signal, and there's only a discrete sine block, is there a way to generate the others?
Most input blocks, including those you list, have a Sample Time parameter. Make it a number greater than 0 to specify a discrete sample time. For instance 0.001 would give you a milli-second sample rate.
For the few blocks that don't have this, simply use a Zero-Order Hold on the output of the block, and specify a sample time for the ZOH block.

How to Add external frequency inputs in the analog filter design block simulink in matlab

I want to be able to externally have inputs for the lower passband edge frequency and higher passband edge frequencies for the butterworth filter block in the simulink signal processing toolbox in matlab. How can I achieve this. Currently you'll have to click the block to specify these frequencies and this is not possible at runtime.
Regards,
Alfred
Basically you are asking for a filter that has time varying parameters. The Butterworth filter block does not allow for this, and cannot be modified to do so, so you are going to have to roll your own. This can be achieved in several ways:
Determining the difference equations that you need to implement, then creating a filter out of fundamental blocks (product, summation and unit delay blocks) where the "parameters" you want to change are fed into the product blocks as signals.
Using a block such as Transfer Fcn Direct Form II Time Varying. (This assumes you can parameterize the changes you need as a gain-scheduled signal.)
Write an S-Function (or perhaps a MATLAB Function block) to implement any detailed/specific functionality.

Simulink: how to convert a discrete signal to a continous signal

I am working in Simulink where I have the following problem.
I have a discrete state space model whose outputs are of course discrete. Outputs are corrupted (summed in the Simulink project) by a (continuous) sinusoidal disturbance.
Does there exist a block that takes as input a discrete signal and converts it to a continous signal?
Thanks in advance
You don't need to convert the discrete signal to continuous before adding it to a continuous signal.
If you use the Summation Block to add a discrete and a continuous time signal then the output (of the sum) will be continuous.
If for some other reason you need to do the conversion then look at the Rate Conversion Block.

Using System Identification Toolbox transfer function with Simulink

I believe I am doing something fundamentally wrong when trying to import and test a transfer function in Simulink which was created within the System Identification Toolbox (SIT).
To give a simple example of what I am doing.
I have an input which is an offset sinusoidal wave from 12 seconds to 25 seconds with an amplitude of 1 and a frequency of 1.5rad/s which gives a measured output.
I have used SIT to create a simple 2 pole 1 zero transfer function which gives the following agreement:
I have then tried to import this transfer function into Simulink for investigation in the following configuration which has a sinusoidal input of frequency 1.5rad/s and a starting t=12. The LTI system block refers to the transfer function variable within the workspace:
When I run this simulation for 13 seconds the input to the block is as expected but the post transfer function signal shows little agreement with what would be expected and is an order of magnitude out.
pre:
post:
Could someone give any insight into where I am going wrong and why the output from the tf in simulink shows little resemblance to the model output displayed in the SIT. I have a basic grasp of control theory but I am struggling to make sense of this.
This could be due to different initial conditions used in SimuLink and the SI Toolbox, the latter should estimate initial conditions with the model, while Simulink does nothing special with initial conditions unless you specify them yourself.
To me it seems that your original signals are in periodic regime, since your output looks almost like a sine wave as well. In periodic regime, initial conditions have little effect. You can verify my assumption by simulating your model for a longer amount of time: if at the end, your signal reaches the right amplitude and phase lag as in your data, you will know that the initial conditions were wrong.
In any case, you can get the estimated initial state from the toolbox, I think using the InitialState property of the resulting object.
Another thing that might go wrong, is the time discretization that you use in Simulink in case you estimated a continuous time model (one in the Laplace variable s, not in z or q).
edit: In that case I would recommend you check what Simulink uses to discretize your CT model, by using c2d in MATLAB and a setup like the one below in Simulink. In MATLAB you can also "simulate" the response to a CT model using lsim, where you have to specify a discretization method.
This set-up allows you to load in a CT model and a discretized variant (in this case a state-space representation). By comparing the signals, you can see whether the discretization method you use is the same one that SimuLink uses (this depends on the integration method you set in the settings).

how to stimulate a lowerpass filter in simulink?

I should stimulate how the lowpass filter work exactly with simulink so i create a signal generator f=50 hz and i make a lowerfilter and after that i want to see it so the only tool that i found it is spectrum analyzer but when i simulate i get two errors
Sorry if it's not really explain because i'm beginner in simulink
The signals being fed into the Spectrum Scope blocks need to be discrete-time signals instead of continuous-time. You can accomplish this by adding a Zero-Order Hold block before each Spectrum Scope, setting the desired discrete sample time in the Zero-Order Hold block's dialog parameters.
As a heads up, you're probably going to want to buffer your signals as well (the spectrum is calculated on "frames" of data, which you can read about here: Create Frame-Based Signals). To do this, you can either use a Buffer block in between your Zero-Order Hold and Spectrum Scope, or select "Buffer Input" in the Spectrum Scope dialog parameters.