Transition probability in a non-homogenous continuous time Markov model along a given fixed path of states, say s1->s2->s3? - transition

In a non-homogenous, continuous time Markov model, the Nelson-Aalen estimator of the transition matrix P(s,t) estimates the transition probability in the time interval [s,t] from any state s1 to any other state s2.
Is it possible to estimate the transition probability within the time interval [s,t] along a given fixed path of adjacent states, say s1->s2->s3?
In other words: only such transitions are of interested which do not deviate from s1->s2->s3, e.g. s1->s4->s2->s3 is not allowed.
It is clear that this is not given by the P(s,t)(1,3), i.e. the matrix element in 1st row and 3 column, because this estimates the transition probability of ALL paths from 1->3.
Is there any idea how to estimate the transition probability along a given path?
Any idea would be very appreciated.
Thanks!

Related

If we take STFT of a single sinusoid, and plot the value corresponding to carrier frequency in real imaginary plane, how many points should it be?

I created a sinusoid with frequency 550Hz that goes for 1 second
fs=44100;
Duration=1; %second
Len=Duration * fs; %length of sinusoid
t=(0:Len-1)/fs;
x=sin(2*pi*550*t);
for the purpose of exploring and learning, I have decided to take the short time Fourier transform of this signal. I did it as below:
window_len=0.02*fs; %length of the window
hop=window_len/3; %hop size
nfft=2^nextpow2(window_len);
window=hamming(window_len,'periodic');
[S,f,t]=spectrogram(x,window,hop,nfft,fs);
Now I want to plot the real versus imaginary value of S for the frequency equal to 550 and see what happens. First of all, in the frequency vector I didn’t have the exact 550. There was one 516.5 and 559.6. So, I just looked at the spectrogram and chose whichever that was close to it and picked that. When I tried to plot real vs imaginary of S for the frequency I chose (over all time frames), the values all fall in 3 points as it shows in the attached plot. Why three points?
Each STFT window can have a different complex phase depending on how the start (or middle) of the window is synchronized (or not) with the sinusoids period. So the real-complex IQ plot for the peak magnitude DFT result bin can be a circular scatter plot, depending on the number of DFT windows and the ratio between the stepping distance (or length - overlap) and the period of the sinusoid.
The phase of the STFT coefficients for the different windows depends on which data exactly the window "sees". So for your particular choice of window length and hop, it so happens that as you slide through your single-frequency sinusoid, there only three different data chunks that you window "sees". To see what I mean, just plot:
plot(x(1:window_len),'x')
plot(x(1+hop:window_len+hop),'x')
plot(x(1+2*hop:window_len+2*hop),'x')
plot(x(1+3*hop:window_len+3*hop),'x')
.. and if you continue you will see that the pattern repeats itself, i.e., the first plot for instance is the same as the fourth, the second as the fifth etc. Therefore you only have three different real-imaginary part combinations.
Of course, this will change if you change the window length and the hopsize, and you will get more points. For instance, try
window_len =nfft;
hop=ceil(window_len/4)
I hope that helps.

Are MATLAB's lsim outputs derivatives or the state vector?

I'm trying to do a simulation of a 2-body mass-spring-damper. I've set up a state-space model that I'm pretty confident in and set an input of a displacement and velocity at the base in just one degree of freedom. Upon getting my outputs, I expected that the output vector would just be the state vector at each time step. However, when plotting the output vector corresponding to displacement for each mass in the vertical direction (the input direction), it looked much more like a velocity (0 at the extrema of the input). The plots are shown below:
When I integrated the top 2 plots, I got the following:
Now, I obviously can just accept the outputs as they are and assume I am right in my understanding. But, I want to be sure. From the documentation page:
lsim(___) also returns the time vector t used for simulation and the
state trajectories x (for state-space models only)
I'm just hoping to find out whether or not I am correct in that the output matrix columns correspond to the history of the state derivatives before I go base an analysis on a bad assumption.
I figured it out. My B-matrix expected [derivative, state,...] but I had them in the opposite order.

Confusion between prediction matrix and measurement covariance matrix in Kalman filter

I am trying to implement Kalman filter for vehicle tracking in MATLAB. A Vehicle is moving in X direction with constant velocity. Initial state for vehicle =[x(t) v(t)].
I have to find position of vehicle after t=2 sec. Position of vehicle from GPS is corrupted by noise.
My question is: if I consider that there is no process noise, then will initial prediction matrix be equal to measurement noise matrix? I don't know how to initialise prediction matrix.
Any part of your state that is initialized from a measurement can have the corresponding variance initialized from the measurement variance. If your state has other variables (e.g. velocity) which aren't directly measured, then you'll have to put in educated guesses about how far wrong you could be. Variance has units of "state unit squared" (because variance is the square of standard deviation). So if your velocity estimate has a 68% chance (see: normal distribution) of being within +/-7mph, then the initial variance would be 49 miles^2/hour^2.

Resampling in a particle filter with replacement

Please help. The condensation algorithm steps to track an object in a frame are:
Initialize a point and choose N random points around it and set the weight to be 1/N.
Propagate the points as per the dynamic model (constant velocity model).
Now, calculate the weights of each particle using an observation model. Till now, there are N particles.
Now, in the resampling step pick N particles from the above set of particles?
What? How can we pick N particles from N particles?
How can we pick N particles from N particles?
Pick N particles with replacement, i.e one particle can be chosen more than one time according to the weight you assign to it.
If you have 3 particles , with weight [0.1 0.2 0.7 ] , then choose the 3rd particle twice and 2nd particle one,hence you have selected get 3 particles from 3 particles itself.
There are many techniques to do this step i.e resampling N particles.Even I am trying to write a code for this part only.
Some sites where you can learn about resampling is :-
Udacity - Artificial Intelligence for Robotics - Link to the course page
IEEE paper- tutorial on Particle filter for online .... by Arulampalam ,gordon maskell, This is a highly cited paper,and almost every where people have taken references for particle filter from here only.
This paper is lecture tutorial in which they have explained resampling nicely, just follow the algorithm, and i think your code will do the resampling Link
I don't know how much detail is required...forgive me if most of this is known. The particle filter attempts to estimate the posterior distribution p(x_t|y_1,...,y_t) based on the observations y_1,...,y_t. The "correction step" relies on the simplification:
p(x_t|y_1,...,y_t) = p(y_t|x_t)p(x_t|y_1,...,y_t-1)/p(y_t|y_1,...,y_t-1)
N points are sampled from this posterior distribution, then evolved according to the right-hand side to approximate the next posterior. We are not dealing with normals so we need to approximate more than just 2 moments. The N points for the next step are then resampled from the new posterior, rather than just using the old points, wherever they have eveolved. The reason is the well-known degeneracy effect - that all points but 1 will tend to 0.
So we are not picking N particles from N particles, but rather throwing away the old particles, and resampling N from the new estimate of the posterior.

Creating a 1D Second derivative of gaussian Window

In MATLAB I need to generate a second derivative of a gaussian window to apply to a vector representing the height of a curve. I need the second derivative in order to determine the locations of the inflection points and maxima along the curve. The vector representing the curve may be quite noise hence the use of the gaussian window.
What is the best way to generate this window?
Is it best to use the gausswin function to generate the gaussian window then take the second derivative of that?
Or to generate the window manually using the equation for the second derivative of the gaussian?
Or even is it best to apply the gaussian window to the data, then take the second derivative of it all? (I know these last two are mathematically the same, however with the discrete data points I do not know which will be more accurate)
The maximum length of the height vector is going to be around 100-200 elements.
Thanks
Chris
I would create a linear filter composed of the weights generated by the second derivative of a Gaussian function and convolve this with your vector.
The weights of a second derivative of a Gaussian are given by:
Where:
Tau is the time shift for the filter. If you are generating weights for a discrete filter of length T with an odd number of samples, set tau to zero and allow t to vary from [-T/2,T/2]
sigma - varies the scale of your operator. Set sigma to a value somewhere between T/6. If you are concerned about long filter length then this can be reduced to T/4
C is the normalising factor. This can be derived algebraically but in practice I always do this numerically after calculating the filter weights. For unity gain when smoothing periodic signals, I will set C = 1 / sum(G'').
In terms of your comment on the equivalence of smoothing first and taking a derivative later, I would say it is more involved than that. As which derivative operator would you use in the second step? A simple central difference would not yield the same results.
You can get an equivalent (but approximate) response to a second derivative of a Gaussian by filtering the data with two Gaussians of different scales and then taking the point-wise differences between the two resulting vectors. See Difference of Gaussians for that approach.