Sync Video TTL pulses to another signal
20 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have a signal (neural recording) and a video recording of the experiment. The camera captures frames at 30 fps and can send a trigger to a device every single time it captures a frame. I have recorded both the signal and the camera trigger on the same DAQ (which is recording at 12k Hz). I would like to:
- downsample my signal using the camera trigger (each frame is represented as a TTL pulse which is ~5ms, drops to zero and then rises again for the next frame). Ideally, I want the program to average the signal over a single TTL pulse and return the average signal and the mid point (time stamp) of that TTL pulse, and do this for the entire recording so by the end of it all I will have the same number of signal data points as the frames in my video.
I am really lost because while I can do this with a for loop, the file is too large (50GB). I would like to use some basic matrix methods that can do the job quicker.
0 commentaires
Réponses (1)
Sathvik
le 3 Mai 2023
Hi Deepika
You can start off by creating an array of the indices of rising edges of the TTL Pulses. Your code could look something like this
rising_edges = find(diff(trigger > threshold) == 1);
Calculate the start and end indices of each TTL Pulse which will then help you reshape the signal into a matrix.
pulse_starts = rising_edges;
pulse_ends = [rising_edges(2:end)-1; length(trigger)];
num_pulses = length(pulse_starts);
pulse_length = pulse_ends(1) - pulse_starts(1) + 1;
signal_matrix = reshape(signal(pulse_starts(1):pulse_ends(end)), pulse_length, num_pulses)';
Once the signal is in form of a matrix, you can use the ‘mean’ function to calculate average signal of the TTL Pulse and then obtain the mid point by taking the mean of the start and end indices arrays and multiplying this with dt (time between samples)
avg_signal = mean(signal_matrix, 2);
dt = 1/sample_rate;
mid_points = (pulse_starts + pulse_ends)/2 * dt;
Hope this helps
0 commentaires
Voir également
Catégories
En savoir plus sur Signal Generation, Manipulation, and Analysis dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!