Generating a sine wave in Simulink without any standard blocks - matlab

I'm trying to generate a sine wave without using any standard blocks available in Simulink. Right now I'm using constants for phase angle and frequency but eventually I want to vary this and hence not using the standard blocks. Here is the Simulink model
Here is the scope output
The output is not a sinusoidal wave. What am I screwing up here?
I'm using a fixed step auto solver.

As I'm currently not in the possession of Matlab/Simulink so I can't construct a working example. But I think the best solution for your problem is using a Simulink function block. In this block you can define a Matlab function of your own design and it will allow you to generate any signal you want.
Mathworks example

Related

Drawing Nquvist-Plot i Simulink

I build an equivalent circuit in Simulink and it works. Now I want to get the nquvist plot of this equivalent circuit. Does anyone have an idea how to achieve this. Till now I only get the Impedance versus the frequency. I attached the equivalent circuit:
Thanks a lot
When using blocks from "Simscape Power Systems Specialized Technology" use voltage/current measurement blocks (depending on the numerator/denumerator of the transfer function). The outputs of these blocks are Simulink signals. Once you have the signals, you can use the "Simulink Control Design" toolbox to display a Nyquist plot directly. See following link for an example (although for Bode plot, but it is straight forward to apply the procedure to Nyquist plots).

AC coupling in MATLAB / Simulink

I've been trying to use Simulink for modelling an oscilloscope (including DSP). I am still very novice so please forgive me if the following question is way too easy: How do I implement AC coupling (remove DC component) in Simulink while using analog signals? I know there is a DC blocker, but it only accepts discrete signals and I want to discretize my signal later with an imperfect ADC.
I'm trying to use a MATLAB function for the AC coupling, but I cannot find a way to use the existing analog signal gained from the function declaration. Instead, all MATLAB documentary seems to want me to use an analog device on my computer (https://mathworks.com/help/daq/analog-data-acquisition.html).
Thank you for any efforts and/or suggestions! :)
I don't think using the Matlab Function Block will work since you need to hold a state. To simulate AC coupling, I believe that you need to create a high pass filter. This removes DC from the signal so that the waveform is centered around zero. The corner frequency generally needs to be very low so that there is no distortion of the waveform being measured. You can build this without any special toolboxes. You just need an integrator block, gain block and some summation blocks.
An example is provided below:
This example applies a DC step to the waveform at 1 second. The figure below provides the output
In the upper figure (input) the offset remains, but in the lower figure (output) the offset is removed.
If you want using the matlab AC Coupling function, try using the Matlab Function Block : https://fr.mathworks.com/help/simulink/ug/creating-an-example-model-that-uses-a-matlab-function-block.html . You can use it like any matlab function, i.e. function [out1, out2] = my_function(in1) but it will be defined in a simulink block.

how to assign noise to sine wave using matlab or i have to use the command?

i have assignment that i have to print a pure sine wave & add some noise to it & print another copy, i know that i can get pure sine wave using matlab/simulink but how can i add noise to it? is there away to implement it using simulink part of matlab or i have to use the commands, i donnt know too much about commands in matlab so i implemented it using simulink also the output of the pure sine wave block doesn't appear like pure sine wave so what's the problem? thanks.
You can add white noise to any waveform by using the built in function awgn.
both awgn and wgn functions work. but you'd better know what SNR is needed.

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).

signal generation model in Simulink from matlab

How do I generate following signal in simulink:
t=(0:1000)/1000*10*pi;
I want to build the model of the following matlab code:
t=(0:1000)/1000*10*pi;
x = (t).*sin(t);
y = (t).*cos(t);
z = t;
This is fairly basic stuff. Have you gone through any Simulink tutorial, introduction videos/webinars or even the getting started guide of the documentation?
Here are a few suggestions to help you answer your question:
Set the stop time of your model to 1000s and use a fixed-step solver with a step time of 1s.
Use a Clock block with a decimation of 1. That's your 0:1000 vector.
Feed the output of your Clock block to a Gain block, with the gain set to 1/(10000*pi). That's your t vector.
Feed your t signal to two Trigonometric Function blocks, one set to sin and one set to cos. That will generate two signals, sin(t) and cos(t).
Now multiply your t signal with your sin(t) signal using a Product block, to generate your x signal (t*sin(t)).
Do the same thing with t and cos(t) to generate your y signal. z is already done since it's equal to t.
EDIT following comments
The answer to your comment is really basic Simulink stuff. You should learn how to use Simulink before trying to do advance stuff like VR in Simulink. It's a bit like trying to run before you can walk.
Here are a few resources that may be useful:
Simulink Videos and Examples
Simulink Webinars
Simulink tutorial
Getting Started with Simulink in the Simulink Documentation
I don't know much about VRML, but be aware that the coordinate system in VRML is different from that in MATLAB/Simulink (see http://www.mathworks.co.uk/help/sl3d/vrml.html). You should also have a look at Virtual World Connection to a Model in the Simulink 3D Animation documentation.