Matlab Simulink VI graph plotting - matlab

Respected,
I plotted the graph between time and current by taking values from electric load using Simulink model in matlab. Now i want to plot the graph between voltage and current that is known as VI curve.so now the problem is the axis. So kindly tell me how can i change the X axis scale of time into voltage scale.thanks.
Regards
Abbas Tausif

From your question it is not very clear how your are acquiring your data, thus my answer can only be so detailed.
This is how I would solve this problem:
In simulink use a clock connected to a "To Workspace" block to record record time.
Use another "To Workspace" block to record the load (I'm not sure if you mean power or impedance here).
set format of both "To Workspace" blocks to array.
After running the simulation you will have two variables in MATLAB (time and load), then using V=IR or P=IV you can work out arrays for voltage and current.
Finally you can plot a graph using the arrays you calculated for V and I in MATLAB using plot(time,current) or plot(voltage,current) ect...
I hope this helps.

Related

Sampling frequency from Simulink to Matlab

I'm running a simulink model from simulink using matlab. My system is mainly in matlab, but I run the slx file and export the outputs to be used in matlab. The simulation is run for 48 seconds (1 second representing an hour). When I get the outputs, I'm expecting it to be the same quality as when I view it in simulink, but it's not. Here is an example of what my data looks like in simulink:
Here is how it looks like when I plot it in matlab (the number of samples becomes 307 when exported)
I tried to change the step size in simulink or change the solver, but this distorted my simulink output as the following.
My solver is ode45, how do I control the sampling frequency of my data so that I don't get different resolution after exporting it to matlab.
P.S Once I export it, I will interpolate the data so that I get samples in between the hours (a sample every minute instead of every hours). If I can do it at once by changing the step size then that will be perfect.
following your advice, I got this plot when I plot it vs time instead of samples
Thank you
You are using a variable-step solver (ODE45) and thus there is a very high chance you won't get a consistent sampling frequency.
The only way to ensure/control the sampling frequency is to use a fixed-step solver (ode4 for instance).
However, as to why the data looks different between the Simulink scope and the plotted data, for variable timestep solvers there is refine factor (configuration parameters -> Data Import/Export -> Additional Parameters). This is by default set to 1. Set this to 100 and you should get a more consistent-looking sample density.
What should be known about the refine factor?
To get smoother output and have a better time resolution, it is much faster to change the refine factor instead of reducing the step size.
When the refine factor is changed, the solvers generate additional points by evaluating a continuous extension formula at those points.
The refine factor applies to variable-step solvers and is most useful when you are using ode45.
Usually a value of 4 produces much smoother results.
https://blogs.mathworks.com/simulink/2009/07/14/refining-the-output-of-a-simulation/
https://uk.mathworks.com/help/simulink/gui/refine-factor.html

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

Generating square wave using Matlab embeded function

I intend to generate a square wave which is applied on a DSP.
I have written these codes and put them in an embeded Matlab function.
function y = fcn(u)
%#eml
t=0:0.001:1
h = sign(sin(125600*t+u));
y= (h+1)/2
where, u is a constant value of 0.582 which is used for shifting the square wave.
The problem is at the output in the simulation, instead of getting a square wave, I see only two straight lines of y=o and y=1.
Please let me know where is the problem that I can not get the square wave?
Note that the frequency of square wave must be 20 kHz. Therefore, I adjust the sampling time as 1e-7 s. And also its amplitude is between 0 and 1 In addition, due to this signal must be transferred to a DSP board, in the "solver option" I chose the type: " Fixed-step" and for the Solver: "Discrete (no continues state)".
Thanks a lot.
This is wrong on many levels.
First of all, you never define the time vector inside a MATLAB Function, that's what the Simulink engine does. Pass time as an input to your MATLAB Function block and use a Clock block to generate the time input.
Second, the above is fine for simulation, but it sounds like you are generating C code from the Simulink model to run it (in real-time) on your DSP. This is not my area of expertise, but from memory, I think you need to enable "absolute time" or something similar for the above to work with code generation. However, I think this is target-dependent and so I'm not sure whether this will work on your DSP.
In you function type plot(t,y) at the end. You are generating a 20khz square wave (assuming you are sampling at 1e-7). Essentially your generating it is working.
Now, what is the DSP board you are using/any information that is relevant to your problem?
I don't know what you are referring to when you say "Solver" either.
Is the "simulation" an oscilloscope or a program? Either way perhaps it is not triggering correctly? Is there an edge trigger option?

Inconsistency between Simulink Scope and its Matlab plot obtained using to Workspace block

I'm running a SimEvents simulation using Variable-step discrete solver. I save a signal data using a 'to Workspace' block, but the plot that I obtain is different from the one shown in the 'Scope' block inside the model.
The original signal remains constant between t=64[h] and t=65.4[h] (and this seems to be correctly done also in the matlab plot), while elsewhere it is like the plot command and the 'scope' block are working with different "sample times".
I'd like to obtain a plot showing the typical "step shape" of a discrete signal rather than a "nearly continuous" signal.
I've used the Scope 'save data to workspace' as well, but I didn't solve the problem.
I would have attached some screenshots in order to make the question more complete, but this is my first question so I have not enough reputation to post images. If you need, I can send them to you via e-mail.
Thank you in advance!
There are no screenshots to look at, but my guess would be that the signal is discrete, and the Simulink scope block, knowing this, is only changing at the discrete time points.
However, if you are plotting the data dumped to MATLAB using the standard plot function then it treats the data as continuous and joins successive points with a (non-constant) line.
If that's the case, you most likely want to be using the stairs function to do your MATLAB plottig.

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.