I am using a matlab simulink hardware in the loop setup with a DAQ with digital output. It controls an RC servo.
It is a 50hz pwm. 90 degrees is a certain time HI, -90 is a different time HI. Correlate to 5 percent to 25 percent duty cycle.
In simulink, is it possible to like scale the input (or pass it thru an arithmetic formula) so a zero duty cycle produces 5% and a 100 percent duty cycle produces 25%?
Thanks
I am a college student with only simulated experience
Related
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!
The signals are:
Tb is bit time = 0.001s. Basically, first is square wave with 50% duty cycle and second is with 100 percent duty cycle. I tried using Pulse Generator, it is not giving me negative output and it does not let me choose 100 for duty cycle.
How can I do this in Simulink?
Behold, the Simulink model that generates the first signal:
The amplitude of the Pulse Generator is set to 2/sqrt(Tb), the duty cycle to 50%, and the period to Tb, where Tb is a variable in the (model) workspace.
As for the second graph; a square wave with 100% duty cycle:
There is, of course, no difference between a constant-valued signal and a square wave with 100% duty cycle, which is what Simulink nags about. I don't know why the Mathworks decided to explicitly forbid 100% duty cycles from Pulse Generator blocks, but oh well.
I have a 10 Hz time series measured by a fast instrument and a 1 minute time series measured by a slow reference instrument. The data consists of a fluctuating meteorological parameter. The slow reference instrument is used to calibrate the fast instrument measurements. Both time series are synchronised.
My idea:
Average the 10 Hz data into 1 minute blocks.
Take 5 one minute block from each time series and calculate the linear regression equations.
Use the regression equations to calibrate the 10 Hz data in 5 minute blocks (3000 data points).
What would be the best way to match (calibrate) the high frequency data using the low frequency data? I use MATLAB.
More background: The fast instrument outputs a fluctuating voltage signal while the slow instrument outputs the true value of a trace gas concentration in ppb (parts per billion). The slow instrument samples every ten seconds and outputs the average every one minute.
In short I would like to have my fast signal also in ppb but without losing it's integrity (I need the turbulent fluctuations to remain unfiltered), hence the need to use a linear fit.
Here's my approach and the results I got...
I modelled the problem as there being
a real (unmeasured by instruments) signal.
Let's call this real.
a slow signal - which is just the real signal sampled once a minute.
Let's call this lf (short for low frequency).
a fast signal - real signal + noise + signal drift.
Let's call this hf (short for high frequency).
The task was to take the slow and fast signals and try to reconstruct the real signal.
(Using least squares as a scoring metric)
Strategy:
Define a "piecewise linear filter" - this takes a signal, and returns a piecewise version of it. (With each piecewise part occurring where the slow signal is measured.)
NOTE: The slow signal is considered piecewise anyway.
Define a forwards-backwards low pass filter.
Define "uncertainty" to be 0 at the points where the low frequency signal is measured. It linearly increases to 1 when the timestamp is halfway between low frequency signal measurements.
Now, take your high frequency signal and filter it with the low pass filter.
Let's call this hf_lp
Take hf_lp and apply the "piecewise linear filter" to it.
Let's call this hf_lp_pl
Subtract the last two from each other.
I.e. hf_diff = hf_lp - hf_lp_pl.
You now want to find some function that estimates how by how much hf_diff should be added to the low frequency signal (lf) such that the squared error between real_estimated and real is minimized.
I fitted a function along the lines of real_estimated = lf + diff.*(a1*uncertainty + a2*uncertainty.^2 + a3*uncertainty.^3)
Use fminsearch or other optimization techniques to get a1, a2, a3...
Here is a sample plot of my results - you can see that real_estimated is much closer to real than the slow signal lf.
Closing thoughts...
The fast signal contains too much very low frequency (drift) and too much
very high frequency (noise) components.
But it has valuable medium frequency info.
The slow signal has perfect low frequency information, but no medium frequency info.
The strategy above is really just one way of extracting the medium frequencies from the fast signal and adding it to the low frequency signal.
This way, we get the best of all worlds: low frequencies, medium frequencies and low noise.
I have a Simulink model with master clock value of 4410 Hz. I know for a fact that computation time of some algorithms (e.g. cubic spline interpolation on a 4410 sample frame being accumulated in real-time) is much longer than the master time period (i.e. computation time of spline is cca 0.7 seconds). I would expect Simulink to output frame elements AFTER initial 1 second + propagation time delay (like in hardware languages, e.g. VHDL), but it actually starts outputting the elements of the frame just after one seconds (which is the length of frame, 4410/4410 seconds). This wouldn't be a problem if my output values weren't unexpected/wrong.
How does Simulink build the simulation in this case? It would appear that it stops the simulation for larger computation times, then continues it afterwards.
A simulink simulation assumes infinite computation capacity, it does not simulate computation times. It does not stop the simulation, it does not use a real clock at all. While simulink is a bit more complicated with the different solvers, you can take a look at discrete event simulation which should give a simple example of isolating the simulation clock form your real clock.
I'm working on the IMU of mobile phones. I need to get reading from accelerometer and gyroscope at the same time.
But I find their reading frequency isn't the same. How could I to retrieve reading from them at the same interval?
Actually, the first answer to this post also find the problem, but the guy doesn't give the solution.
Any help is appreciated!
Can't you just multiply the frequency of the accelerometer by the frequency of the gyroscope?
Imagine that f1 samples every four time units and f2 samples every three time units. If the sampling is regular and they begin to sample at same time they will meet every twelve time units.
e.g.
if the accelerometer has 40 samples every 5 seconds and the gyro has 1332 samples in the same amount of time.
to calculate the frequency:
the accelerometer has 40/5 = 8 samples per second
the gyro has 1332/5 = 266.4 samples per second
to calculate the period (in milliseconds):
the accelerometer samples every 1000/8 = 125 millisecond
the gyro samples every 1000/266.4 = 3.75 millisecond
therefore they will meet every 125 * 3.75 = 469 millisecond