Skip to content
Mikhail Panko edited this page Sep 2, 2013 · 4 revisions

Test each new function on couple different "toy" inputs to make sure it runs correctly; don't assume that if code does not throw an error, it executes correctly.

For example, let's say I have a MATLAB script that detects the peaks of a signal from 20-40 Hz, get_peaks(). Try feeding your script a 30 Hz sinusoid, then plot the detected peak times on top of the input. It's always good to use "toy" inputs where you know what the answer should be (ideally you should be able to confirm numerically, not just visually, that the answer is correct).

% sr is the sampling frequency
% time_points is a vector of sample points to compute the sinusoid over
sin_30hz=2*pi*30/sr*time_points; 
peaks=get_peaks(sin_30hz);
figure();
plot(sin_30hz)
hold on;  
plot(peaks,sin_30hz(peaks),'r*');

This will plot some red stars on top of the sinusoid at the detected peak times. It should be obvious now if something is wrong with your script.

Clone this wiki locally