Model variable/jittered clock to sample a signal in Simulink - how does variable sample times work?

19 views (last 30 days)
I'm trying to understand the impact of a clock jitter in an embedded system and its effect on an FFT calculation.
Thus, I'm creating a jittered clock in Simulink, which triggers a sample & hold subsystem, which shall create discrete samples (like in an ADC) of a continuous 20 Hz sine input signal.
Due to the jittered nature of the clock, I can't use a fixed sample rate (or would need to choose a way higher sample rate to model the jitter), thus I chose the auto solver and continuous sample rates.
Sample rate legend:
I tried to follow Model Effect of Temperature and Jitter on Crystal Oscillation Frequency and created two options for the clock generation, hit scheduler and the variable pulse generator, but those seem not to make any difference.
In the model, you can choose to enable or disable the jitter. f0 is the nominal clock frequency, which is 1 kHz in this example.
There's also a counter to visualize the number of clock cycles. Assuming a simulation time of 2.048 s, exactly 2048 clock cycles are generated, assuming no jitter, which makes sense given the 1 kHz clock. On my PC, when I enable the jitter, only 1822 clock cycles are present.
Below you can see the input signal (20 Hz sine), the clock, and the sampled signal:
In the detail view you can see the desired unsteady clock and the sampled signal.
While this looks good at the first glance, I was wondering, how many data points per step are really generated? Can the be answered given that SL chooses the variable sample rate? Is there a way to generate exactly one data point/sample per clock trigger?
If the clock was stable, I'd use a rate transition (which is in the model, see the screenshot). But rate transitions can't have variable sample rates, e.g. via an in-port it seems.
My next steps would be to calculate the FFT on those samples. But I'm not sure how to make sure that there's one sample per clock.
In the model you can see various approaches I've tried to use to calculate the FFT, but I'm not sure if any is correct.
Unfortunately, the Spectrum Analyzer as well as the buffer blocks need non-continuous sample rates, thus the rate transition seems to be the only choice? But that implies a constant sample rate, which is not true...
Another trial was to calculate the FFT in a MATLAB function but not sure if that approach is correct.
Ultimately I want to estimate the error of the frequency bin estimation in the FFT given an unstable clock. I.e., when there's no jitter in the clock, the 20 Hz sine should appear perfectly. But what if there's a jitter?
Can the Spectrum Analyzer block used without discrete sample rates?
Are there any concepts I could use I'm not aware of? Right now I'm using normal rising edge triggers, would function-call triggers change something? Again, I'd like to make sure that there's exactly one data point/sample available per clock edge - just like it would be in the embedded device's ADC interrupt.
Is the problem clear? You need any more information?
Thanks for any input,
Jan
The model is attached for your reference.
  2 Comments
Paul
Paul on 23 Feb 2025
Edited: Paul on 23 Feb 2025
Hi Jan,
What exactly is the model for the clock jitter?
For example, w/o jitter the time vector for the 2.048 sec would be
Ts = 1/1000;
t = (0:2048)*Ts;
Is the time vector with jitter to be modeled by adding independent, random samples to each element of t? For example, something like
jitter = 1e-6*randn(size(t)); % use normal random number as in the Simulink model
jitter(abs(jitter)>3e-6) = 3e-6*sign(abs(jitter)>3e-6); % clip
tjitter = t + jitter;
Or does each element of the jittered time vector depend on the value of the previous element?
Also, what is the block that's outlined in green with |FFT| and what is the block to the left of it?
Jan Kappen
Jan Kappen on 23 Feb 2025
Hi @Paul,
my model for the clock jitter is to vary the period length of the clock by an additive normal random number.
The results are the same no matter if the Variable Pulse Generator or the Hit Scheduler are used.
> Or does each element of the jittered time vector depend on the value of the previous element?
No, it's a simple additive model, exactly like you described.
> Also, what is the block that's outlined in green with |FFT| and what is the block to the left of it?
Thats the Magnitude FFT. I could've used the "normal" FFT block and calculate the magnitude of the complex output - should be the same. The block left of it is a Buffer. It's used to transform a number of samples over time to a block of samples which can be used by the FFT.
The problem is, that the Buffer needs a non-continuous sample time, exactly like the Spectrum Analyzer. I think there are similar things going on inside the Spectrum Analyzer block. The idea is taken from here: Transform Time-Domain Data into Frequency Domain
I think the main question remains: How do I create non-uniformly sampled data points in Simulink :)
Thanks!

Sign in to comment.

Answers (1)

Paul
Paul on 24 Feb 2025
Because the Hit Scheduler can accept vector inputs, I suppose the simplest approach would be to create the jittered sample times before the simulation runs and then inject them into the Hit Scheduler at T = 0. However, I can see this approach being potentially problematic if the nominal sampling period is small and there is a need to process many frames of data (I don't know what the maximum buffere size is of the Hit Scheduler block).
If you prefer a dynamic approach that executes during a runtime like the approach in the question, I might have a solution, but thought I'd suggest the simpler option first.
  4 Comments
Jan Kappen
Jan Kappen on 25 Feb 2025
Dear @Paul, some very nice approaches here, I did not think about the tapped delay block, only about the buffer and memory blocks... I'll try to use Variable Integer Delay because it has a variable delay via in-port (was no requirement so far, but likely the number of samples shall be calculated dynamically).
Could you upload the model by any chance?
It's interesting that you don't have to feed back the En signal of the hit scheduler as shown in Model Effect of Temperature and Jitter on Crystal Oscillation Frequency. I really need to try to understand the block more in detail.
I think the key is to put the sampling stuff into the triggered subsystem and not try to process it outside the block where apparantely SL sample rates can change.
Big thanks again!
Paul
Paul on 25 Feb 2025
Edited: Paul on 25 Feb 2025
I was originally feeding back the output of the Hit Scheduler block to the En signal, but that was causing me complications until I realized it's not necessary based on how I understand the problem at hand. Basically, the time of the next sample does not depend on the time of the current sample, so the feedback is not necessary. At one point I was using the feedback and trying to compensate for the difference between the actual and nominal hit times in order to schedule the next, random hit time. For example, if the second sample is recorded at T = 0.0009, then we have to deal with the difference between 0.001 and 0.0009 in order to schedule the third hit that is supposed to nominally be at T = 0.002, not T = 0.0009 + 0.001. But I then realized that level of complication is not necessary and settled on the current approach.
I did not look too closely at the Model Effect of Temperature and Jitter on Crystal Oscillation Frequency, so can't say what the differences are there.
The Buffer block from the DSP System Toolbox may offer better functionality. I don't use that toolbox so can't say one way or the other.
Not sure what you mean by the sample times changing outside the triggered subsystem(s). Sample times in the model are determined from the block sample times, events, and the solver (maybe other stuff?). I think I agree that the processing has to be done inside the triggered subsystems because those subsystems are essentially operating at the effective sample times, non constant though they may be.

Sign in to comment.

Products


Release

R2024b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!