Varying parameters During a simulation in Simulink - time

I want to change the parameters of a block when the model is running and simultaneously see the changes in the output.
For eg.I have a sine block connected to a Scope.and when i start the simulation.I want to change the frequency of the sine wave and see the corresponding frequency changed wave on the scope output.I want to do this as i want to see how my model behaves for different frequencies.
Somebody please help me in this regard....Please comment and let me know..I will be grateful to who answer my question...

Whether you can vary a parameter during runtime depends on whether that parameter is tunable. Tunable parameters are those that can be changed after the simulation has started, however, you must pause the simulation to be able to do so.
Run your model simulation, then hit the pause button and open up the Sine block dialog. If the frequency edit box is not disabled you can change the frequency and resume the simulation.
If edit box is disabled it means that the frequency is not a tunable parameter. In this case, you can create your own Sine block using a MATLAB function call back and the sin function, by feeding the blocking the desired frequency.

In this particular case, you could use a chirp signal.

Related

Vector Recording Intervals in Omnet++

Hope you are doing good.
I would like to enable vector recording on my Omnet++ Simulation to record event logs for each second instead of milliseconds.
Could you please advise which syntax should I use to record for each seconds ?
**.vector-recording-intervals = <syntax>
Awaiting for a response.
Regards,
Azhar
The meaning of the vector-recording-intervals is slightly different. That parameter gives us an opportunity to decide when recording vectors is enabled. It should be noticed, that by default recording vectors is turned on for the whole duration the simulation.
Let's consider an example:
**.vector-recording-intervals = 10s..30s, 100s..150s
It means, that vectors will be recorded only from t=10s to 30s and from t=100s to 150s.
And the frequency of recording values into vector depends on the frequency of calling emit() or record() in your code.

OMNeT++ & Veins steady state vehicle density

I want to keep a constant number of cars in my (long) simulation (OMNeT+Veins). I do not care about mobility that much so i could probably use the Veins in-built function *.manager.numVehicles = 100. The thing is that if i do not specify any(enough) vehicle flows (from SUMO) my simulation terminates instantly (because of no events). So i create some flows (that exit the simulation sooner) and Veins fills up for the cars as they dissappear.
Is there a more elegant way to do this? I'd prefer to just use the numVehicles function since it's easier and the cars move minimally so they remain in the simulation for long.
I need steady-state vehicular density (number of vehicles fixed - even if old ones leave and new ones enter to replace them at the same instant).
Thanks,
Andreas
The autoShutdown parameter can be set to false to instruct the coupling interface to keep going even though there are no more cars in the simulation. See https://github.com/sommer/veins/blob/veins-4.5/src/veins/modules/mobility/traci/TraCIScenarioManagerLaunchd.ned#L55
https://stackoverflow.com/a/71071341/7215379 has a solution. It actually is meant to keep the number of vehicles in simulation constant. You can look into the possibility of reusing it.

Generate on/off signals of random duration SIMULINK

For my SIMULINK model I need to generate a signal that takes the values 1 or 0. To generate it I need to draw a number from a an exponential distribution and use this number as the time the signal stays in 0. Once this time has passed, I have to draw a new number from the exponential distribution and use this number as the time the signal stays in 1, and the repeat the process until the end of the simulation. As a SIMULINK newbie I'm quite puzzled by this problem and would appreciate any suggestions on how to solve it.
You've got a couple of choices.
In MATLAB, you can generate all samples in advance (i.e. before running the simulation) and use them to create a suitable signal, then use that as an input into the model (using the From Workspace block).
Or, if you need to do the sampling at each time step, then you have to write an S-Function, using the random number in the mdlGetTimeOfNextVarHit method. There is an example of doing something very similar on the Goddard Consulting web site called Square Wave with Jitter.

In matlab, speed up cross correlation

I have a long time series with some repeating and similar looking signals in it (not entirely periodical). The length of the time series is about 60000 samples. To identify the signals, I take out one of them, having a length of around 1000 samples and move it along my timeseries data sample by sample, and compute cross-correlation coefficient (in Matlab: corrcoef). If this value is above some threshold, then there is a match.
But this is excruciatingly slow (using 'for loop' to move the window).
Is there a way to speed this up, or maybe there is already some mechanism in Matlab for this ?
Many thanks
Edited: added information, regarding using 'xcorr' instead:
If I use 'xcorr', or at least the way I have used it, I get the wrong picture. Looking at the data (first plot), there are two types of repeating signals. One marked by red rectangles, whereas the other and having much larger amplitudes (this is coherent noise) is marked by a black rectangle. I am interested in the first type. Second plot shows the signal I am looking for, blown up.
If I use 'xcorr', I get the third plot. As you see, 'xcorr' gives me the wrong signal (there is in fact high cross correlation between my signal and coherent noise).
But using "'corrcoef' and moving the window, I get the last plot which is the correct one.
There maybe a problem of normalization when using 'xcorr', but I don't know.
I can think of two ways to speed things up.
1) make your template 1024 elements long. Suddenly, correlation can be done using FFT, which is significantly faster than DFT or element-by-element multiplication for every position.
2) Ask yourself what it is about your template shape that you really care about. Do you really need the very high frequencies, or are you really after lower frequencies? If you could re-sample your template and signal so it no longer contains any frequencies you don't care about, it will make the processing very significantly faster. Steps to take would include
determine the highest frequency you care about
filter your data so higher frequencies are blocked
resample the resulting data at a lower sampling frequency
Now combine that with a template whose size is a power of 2
You might find this link interesting reading.
Let us know if any of the above helps!
Your problem seems like a textbook example of cross-correlation. Therefore, there's no good reason using any solution other than xcorr. A few technical comments:
xcorr assumes that the mean was removed from the two cross-correlated signals. Furthermore, by default it does not scale the signals' standard deviations. Both of these issues can be solved by z-scoring your two signals: c=xcorr(zscore(longSig,1),zscore(shortSig,1)); c=c/n; where n is the length of the shorter signal should produce results equivalent with your sliding window method.
xcorr's output is ordered according to lags, which can obtained as in a second output argument ([c,lags]=xcorr(..). Always plot xcorr results by plot(lags,c). I recommend trying a synthetic signal to verify that you understand how to interpret this chart.
xcorr's implementation already uses Discere Fourier Transform, so unless you have unusual conditions it will be a waste of time to code a frequency-domain cross-correlation again.
Finally, a comment about terminology: Correlating corresponding time points between two signals is plain correlation. That's what corrcoef does (it name stands for correlation coefficient, no 'cross-correlation' there). Cross-correlation is the result of shifting one of the signals and calculating the correlation coefficient for each lag.

Constant animation speed, variable frame rate

Would you, dear all, suggest me best practices to get constant animation speed not depending on computer's real speed? Frames may be skipped.
There are two types of animation - frame based and time based and the names suggest the obvious.
What you are looking for is time-based where you call the display() function (the function which draws frames) is called continuously. Within the display function you set a global variable or a static variable(depends on language) to store the TIME(preferably in micro or milliseconds) when the previous occurrence to this call was made. We compare the current time and the saved time to find difference in time, dt, and the function must draw based on dt(time elapsed).

Resources