Test and Measurement Forum

How to best create a pulse train with a fixed duty cycle?

Post your MATLAB discussions here

How to best create a pulse train with a fixed duty cycle?

Postby furuian » Sat Jan 14, 2017 2:02 pm

I'm trying to create a pulse train where the pulse consists of a sine wave (e.g. 20 KHz). The sine wave pulse lasts for 200ms, then there is zero output for 800ms, then the next sine wave pulse starts and so on.

I wrote a simple Matlab script implementing the above using Picoscope's software trigger function (to start a pulse of 200ms length) followed by Matlab's pause function (to wait until the next pulse is due) in a loop.
This works okay but besides generating the pulse train I also need to take data during some of these pulses, carry out FFT etc. All of this will mess up the timing in Matlab and I can't ensure the regular 200ms/800ms duty cycle if I do multiple things in one script.

Here are a few options to address this problem that I thought about:
1) Is there a way I can program the signal generator to tell it: "generate a sine wave for 200ms, then zero output for 800ms, then repeat" and then forget about it since the signal generator will automatically keep humming along in the background creating the pulse train? That would be the most elegant solution.
2) If the above is not possible, is there some sort of threading possible in Matlab such that I can have a separate thread running in the background triggering the pulses and focusing on the right timing while in another thread I carry out data taking, FFTs etc?
3) I suppose if no software solution is possible, I could use a periodic hardware trigger e.g. I could have an Arduino send a regular trigger signal once per second which will each time trigger a 200ms signal generator pulse. That should work but would be the least elegant solution since it would require additional hardware.

Any thoughts on the above? What would be the best way to achieve a periodic pulse train with a certain duty cycle (with the main program occasionally doing other things)?

Thank you,
Ian
furuian
Newbie
 
Posts: 0
Joined: Wed May 11, 2016 2:02 pm

Re: How to best create a pulse train with a fixed duty cycle

Postby Martyn » Sat Jan 14, 2017 4:24 pm

Depending upon exactly what frequency you needed for the 200ms sine wave burst, and which PicoScope device you have, it may be possible to design an AWG waveform that is output by the generator at a frequency of 1Hz. 20% of the buffer would represent the waveform, 80% would be a flat line giving the repeating signal you needed.
Martyn
Technical Specialist
Martyn
Site Admin
Site Admin
 
Posts: 2520
Joined: Fri Jun 10, 2011 8:15 am
Location: St. Neots

Re: How to best create a pulse train with a fixed duty cycle

Postby furuian » Sat Jan 14, 2017 8:01 pm

Thank you for your quick reply, Martyn - much appreciated!

I have two Picoscopes: a 5444A and a 5444B. I understand that only the latter one has an AWG. My 200ms sine wave bursts have to go up to 3 MHz. I take it that the AWG buffer can hold 48k samples. I don't have any experience with the AWG but it seems like it may not offer enough resolution to create a 3 MHz burst with cycle time 1 second.

The other thing is that I need to adjust the frequency of the pulses during script execution, e.g. I need to walk through pulses from 1 Mhz to 3 MHz in 1 KHz steps. From what I understand, the AWG approach would require to stop the scope and reload the buffer every time I change frequencies. I guess that would introduce some delay and make a 3000 step scan much longer. With the function generator I update the frequency by calling setSigGenBuiltIn which does not require restarting the scope from what I can tell.

Apologies, I should have provided the information above in my first post already. Given the additional input, what do you think is a feasible approach?
Last edited by furuian on Sun Jan 15, 2017 3:15 am, edited 1 time in total.
furuian
Newbie
 
Posts: 0
Joined: Wed May 11, 2016 2:02 pm

Re: How to best create a pulse train with a fixed duty cycle

Postby Martyn » Tue Jan 17, 2017 2:02 pm

There is not a simple solution so it will take a bit of working out, the AWG buffer would not be suitable as changing frequency would require a rewriting of the buffer.

The option would be to send out a set number of cycles (Shots) of the sine wave at the chosen frequency to achieve a 200ms burst, and have the signal generator trigger on an event which is running at 1sec. It may be possible to do this as a software trigger through Matlab on a timer, but I would need to check this out as Matlab is not my speciality.

Can you please email support@picotech.com with the details, I can then discuss this with others in the team.
Martyn
Technical Specialist
Martyn
Site Admin
Site Admin
 
Posts: 2520
Joined: Fri Jun 10, 2011 8:15 am
Location: St. Neots

Re: How to best create a pulse train with a fixed duty cycle

Postby furuian » Thu Jan 19, 2017 6:30 pm

Thanks for your input on this, Martyn.

I did a bit of research on Matlab and it turns that although there are timer functions available they will never by truly real time because at the end of the day Matlab remains single-threaded.

For us it is important that the signal is very regular without occasional deviations. So I decided to go with an option mentioned above: I will have a dedicated Arduino which will do nothing but time keeping: it will receive a certain frequency setting (e.g. 1/s) from Matlab via serial port and will then forever output a 5 V pulse exactly every period (e.g. every 1 s). This pulse will be used as an external trigger to the Picoscope function generator (as well as the scope which will start taking data after a 10 ms delay) which will then fire up a 200 ms long sine signal every time.
furuian
Newbie
 
Posts: 0
Joined: Wed May 11, 2016 2:02 pm


Return to MATLAB

Who is online

Users browsing this forum: No registered users and 0 guests