How to use an input with high current amplitude while the lookup tables in model are based on small amplitude values? - matlab

I am trying to fit a model to some measurements to model a battery.
Input of my model is current and the output is voltage of battery terminal.
I am using some 3D lookup tables in my model.
The breakpoints (dimensions) are: SOC (state of charge), temperature, and current amplitude and the table data in the impedance value of battery circuit elements.
The measurements are done using very small values for the current (in range of 2 A).
After completing the model I am supposed to validate the model using a standard signal for current input that includes very high current amplitudes (in range of 250 A).
Then comparing the output of my model (voltage) with the one from the measurements using that standard signal for the current.
Now when I try to run the model I get singularity error over one of the integrators. I am sure this is caused by the high amlitude of current as the input, but the problem is that I can not limit the amplitude using e.g. saturation blocks. I also tried to solve the problem with different solvers but could not fix the problem. Does anyone have an idea how to resolve this problem?
Please access my files from here.

Related

How do I model the RF propagation of a custom UWB transmission using MATLAB?

I've successfully plotted the signal strength coverage map for a generic narrow band (read single frequency) horn antenna using MATLAB's in-built functions design(), txsite() and coverage().
MATLAB uses the 'Longley-Rice' propagation model when terrain data is present which I downloaded and introduced using addCustomTerrain().
However, I don't want my antenna to be narrow band operating at a single frequency.
I want to model the coverage map I would get on location with a known ultra-wide band (UWB) transient pulsed signal. I have the time domain E-field of this waveform as well as the FFT and energy spectral density.
My plan was to loop over many tx antennas, each having an operating frequency equal to one of the ~1000 frequency bins in the UWB spectral content and an output power equal to the scaled energy spectral density (ESD) multiplied by the frequency step size (df) and divided by the total time period of the measured pulsed signal (to get power). P = ESD * (df/T).
However, when I ran this looped code, I got:
"Error using em.EmStructures/savesolution
The calculated result is invalid; possible cause is a coarse mesh. Please consider refining the mesh
manually."
I assume this means MATLAB can't model 1000 different antennas on the same exact location.. but any idea on this error?
Is what I'm trying to do possible in MATLAB?
Are there alternative methods?
Thank you for any help in advance!

how to conduct the proper multilayer perceptron on interval data

I have a dataset of the daily temperature for a couple of years. The data is in the interval form, including daily high temp and daily low temp.
I want to do a forecasting of the data, and I recently read several paper mention that the multilayer perceptron have the advantage to do this. However, after reading the paper I still got puzzled. I know in order to conduct it, I will need to have input, hidden layer and output. But in Matlab, though I have the code already, I still don't know how to simulate it. What should I put as its input and output, should I put the interval data as the input and output? And how can I choose hidden layer?
The input in an MLP network is the input feature data that you are trying to predict the outcome of. The output is what you are trying to predict. For the hidden layer that will determine how well it predicts, which you want as large as it needs to achieve reasonable prediction results. Going too large and it just memorizes the data rather than generalize on a pattern when training is run.
For example, if your input layer would be what day of the year it is (1-365), what the high was of the day, and what the low is of the day. And I assume is what the high and low temperature would be for the next day?
The more relevant input features you have the better the network will be.

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

Measuring curve “closeness” with unequal data ranges

Provided that I have a similar example:
where the blue data is my calculated/measured data and my red data is the given groundtruth data. The task is to get the similarity/closeness between the data and each of the given curves so that a classification can be done, it could also be possible to choose multiple classes if the results seem to be very close.
I can divide the problem in my mind to several subproblems:
The data range is no the same
The resolution of the calculated/measured data is higher than the ground-truth data
The calculated data has some bias/shift
The following questions come to my mind when trying to solve those problems
Is it better to fit the calculated/measured data first then attempting to solve the problem?
Would it be fine to use the data points as is and calculate the mean squared error of each curve assuming it is a fitting attempt and thus getting the best fit? What would be the effect of the bias/shift in this case?
What is a good approach to dealing with the data/range mismatch, by decreasing the number of samples for the higher sampled version or increasing the number of samples for the lower sampled data in the given range?

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