function [time, height] = buisanalyse(file, max_frame, framerate)
%1e inputargument: filenaam
%2e inputargument: vul het aantal frames in of iig groot genoeg
%3e inputargument: framerate
%het programma werkt als volgt:
%eerst vraagt het je om het filmpje (tot max_frame)af te spelen
%daarna vraagt het om een framedomein op te geven waarin de versnelling gebeurt
%dan vraagt het om aan de linker en rechterkant van de buis te klikken
%zodat de verhouding van het aantal pixels per meter kan worden bepaald
%daarna wordt gevraagd om een deel uit het filmpje te knippen waar de
%marker in zit
%daarna wordt gevraagd de randen van de sampleband op te geven
%daarna plot hij de hoogte in meter als functie van de tijd in seconde
%daarna de benaderde versnelling
%benodigde mfiles:
%avmovie, cutmovie, mark_square, avfmovie, polyplot

diameter_buis = 0.03;

%initial read
image_data = aviread(file, 1);
c_m = image_data.colormap;

%request if want to play movie
k = input('play movie? (y/n): ', 's');
if isequal(k, 'y')
    avmovie(file, max_frame, 0.01)
end

%request size and frames
output = input('what time? (input is [minframe, maxframe]): ');
minframe = output(1);
maxframe = output(2);

avmovie(file, [minframe,maxframe], 0.001)
image_data = aviread(file, minframe);
image(image_data.cdata)
colormap(image_data.colormap)
disp('click on both sides of the pipe to determine the amount of pixels')
[ymin, ymax, xmin, xmax] = mark_square;
p_per_m = (xmax-xmin)/diameter_buis;
disp('click twice to determine size of movie')
[ymin, ymax, xmin, xmax] = mark_square;
moviet = cutmovie(file, [ymin, ymax, xmin, xmax], [minframe, maxframe]);
movie = moviet.cdata;
moviet.colormap = c_m;
avfmovie(moviet, 1, 1)

%request sampleband
disp('click twice to determine size of the sampleband')
[ymin2, ymax2, iets, ietsanders] = mark_square;
sample_band = [ymin2, ymax2];
diff_s_b = sample_band(2)-sample_band(1);

%initialise moviepart and band
frame_1 = movie(:, :, 1);
movie_band =frame_1(sample_band(1):1:sample_band(2), :);
movie_size = size(movie);

%calculate best overlapping height
for frame = 1:1:(maxframe-minframe+1)
    for h = 1:1:(movie_size(1)-diff_s_b)
        movie_compare = abs(movie(h:1:h+diff_s_b, :, frame) - movie_band);
        compare(h) = sum(sum(movie_compare));
    end
    [iets, h_best(frame)] = min(compare);
end
polyintp = input('degree of interpolation?: ');
h = polyfit((minframe:1:maxframe)/framerate, h_best/p_per_m, polyintp);
[x, y] = polyplot(h, 1/framerate, (maxframe)/framerate, minframe/framerate);
time = (minframe:1:maxframe)/framerate;
height = h_best/p_per_m;
plot((minframe:1:maxframe)/framerate, h_best/p_per_m, x, y)
pause
h = polyfit((minframe:1:maxframe)/framerate, h_best/p_per_m, polyintp);
v = polyder(h);
a = polyder(v);
[x, y] = polyplot(a, 1/framerate, (maxframe)/framerate, minframe/framerate);
plot(x, y)
disp(max(y))
end