function [sine_signall, sampled_time] = sampled_sine_example_2150(amplitude, frequency, ...
      sampling_frequency, duration, phase_offset )   

% Example code for generating, plotting and sounding a sine wave. 
% To run use: 
% sampled_sine_example_2150(amplitude, frequency, sampling_frequency, duration, phase_offset)
% - amplitude is the peak value of the sine wave.
% - frequency is the frequency of the sine wave in Hz.
% - sampling frequency is the frequency at which the sine wave is sampled.
% - duration is the length of the sine wave in seconds
% - phase_offset is the phase shift in radians
% - the function also outputs the plots as .tif files using the print
%   command.
% - Revised 2/3/16, N. McGruer


T0=1/frequency;             % signal period is inverse of signal frequency 

dt=1/sampling_frequency;    % sampling interval is the inverse of sampling frequency

%total number of samples
N=round(duration/dt);

%sample_number
n=0:N;
sampled_time=n*dt;
discrete_frequency=dt/T0


sine_signall=amplitude*sin(2*pi*frequency*sampled_time+phase_offset);  % sampled sine signal
sine_signal2=amplitude*sin(2*pi*n*dt/T0+phase_offset);  % discrete time sampled sine signal

figure(1)
subplot(2,1,1)
plot(sampled_time,sine_signall,'b');
set(gca,'fontsize', 18);
xlabel('Time (s)');
ylabel('Amplitude');
title('Sampled sine signal with time as independent variable');
subplot(2,1,2)
stem(sampled_time,sine_signall,'b');
set(gca,'fontsize', 18);
xlabel('Time (s)');
ylabel('Amplitude');
print -dtiff sinewave1.tif

figure(2) 
subplot(2,1,1)
plot(n, sine_signal2,'r');
set(gca,'fontsize', 18);
xlabel('Sample Number (s)');
ylabel('Amplitude');
title('Sampled sine signal with sample number as independent variable');
subplot(2,1,2)
stem(n, sine_signal2,'r');
set(gca,'fontsize', 18);
xlabel('Sample Number (s)');
ylabel('Amplitude');
print -dtiff sinewave2.tif

%pause;
sound(sine_signall,sampling_frequency);

return;