Event triggered square-wave

hi,
I generate square wave signal with this ;
freq_Hz = 30;
t = 0:0.0001:10;
y = square(2*pi*freq_Hz*t);
plot(t,y);
axis([0 10 -1.5 1.5]);
xlabel('Seconds');
ylabel('Amplitude');
But I want to trigger each duty cycle with an external event. Like this in pseudo ;
for i:1:100
if event1=1
pwm(i) = high
if event2=0
pwm(i) = low
plot(i,pwm)i)
but can't interfere to square function.
I am sure experienced users will provide some insight.

Answers (1)

Walter Roberson
Walter Roberson on 22 Nov 2011
I just wrote several paragraphs with specific references to why it cannot be done. You deleted the question out from underneath me, so my write-up was lost. This is frustrating to say the least. So you can dig the reasoning out yourself, and you are lucky I still had the documents in my cache.

4 Comments

I am terribly sorry that wasn't my intention. I thought people couldn't exactly understand my problem due to my way of presentation.
I understand why it can't be done the way I expressed the problem. But I think I figured out a workaround ; using RECTPLUS function, generating ZERO for 'event1' and ONE for 'event2', at the end of the FOR loop I can sum all recplus'es. Do you think it's worth the shot ?
I don't think it is worth pursuing that yet.
What is the hardware for your event detector? Specific detector model please; and exactly what kind of bus have you connected it to? What kind of hardware do you plan to run MATLAB on for this purpose -- e.g., 4.5 GHz Pentium V, or 1.67 GHz Core i5 ? What is your memory type and memory speed and size? Which MATLAB version are you using, and 32 or 64 bit version?
If you use MATLAB with standard PC hardware and without any of the MATLAB toolboxes, about the maximum event rate you are likely to be able to achieve is 40 Hz, with 167 Hz (6 millisecond) achievable if you go through some difficulty.
If you use a very good quality A/D card and the Instrument Control Toolbox, you can probably get about 1000 Hz if you work at it, with most people reporting that in practice they cannot get more than 2000 interrupts per second. The maximum theoretically supported with the Instrument Control Toolbox is 5000 interrupts per second, but users have reported that even with active help from MathWork's developers directly, they have not been able to reach nearly that.
http://www.mathworks.com/matlabcentral/answers/1352-dual-channel-capture-with-high-end-sound-card
PC (laptop);
Intel Core2Duo 2.6 Ghz
4GB OCZ Ram (2x2GB)
Nvidia 9300M GS Graphics Acc (CUDA)
Data Acqusition ;
Arduino uno board interfaced with LTC2485CDD via SPI(24bit ADC). Running at 115200 as serial object.
Environment ;
Matlab 2011a 32bit, Slackware Linux 13.37. System is multilib but I prefer 32bit version.
I can't get data acquisition working through the DATA AQ toolbox, I read data the conventional way (m-file).
I use Psychtoolbox (PTB3) to blink the screen (visual stimulus) at a determined frequency and correlate the results obtained from data acquisition. Is there a way to blink the screen flash (fullscreen) at a determined frequency without using a toolbox ? I am sure matlab is capable of doing this, I just couldn't figure out how to. PTB3 introduces too much delay between functions and I just use it to blink the screen.
I need max of 300samples/sec (300Hz), it shouldn't be that hard I suppose ?
The LTC2485CDD normally runs at a maximum of 60 Hz, though there seems to be a "2x speedup mode" possible with it. You will not be able to obtain 300 Hz with it.
MATLAB has no facilities to blink the screen.
PTB3 claims up to 2 KHz sample rate (12 bit) sample rate with a Measurement Computing USB-based interface; see http://docs.psychtoolbox.org/Daq
What is the maximum frame rate for your display? It was never very common to find a CRT with higher than 85 Hz (except for the 120 Hz stereo modes), and most LCD are 60 Hz or lower. CRT often require a notable time to reconfigure to different frame rates (which often require resolution changes), and on most monitors the workable frame rates are a fairly small list. If you have an especially forgiving monitor sometimes you can design custom front porch timings and the like to fine-tune frame rates; Linux does seem to be the OS to use for that kind of work, but it can be tricky work and risks monitor damage if you get it wrong; a high level of attention to detail is necessary. Custom video formats pretty much have to be designed in advance.
Switching video formats using the official mechanisms is not a light-weight change, as the X11 driver has to be notified of the changes and reconfigures its ideas of your screen sizes, perhaps repositions your icons, etc.

Sign in to comment.

Asked:

on 22 Nov 2011

Community Treasure Hunt

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

Start Hunting!