% Simple Demonstration of Aliasing using Matlab and Music
%   Written by Justin Zepp and John Cimbala, February 2010
%   Revised by Denny Kriczky, Andrew Homich, Dave Corbin, and Erik Denlinger, February 2013
%   Revised by Michelle Kehs, Brett Cowan, Nick Mercurio, October 2014

% This program records an audio clip input into the microphone jack,
% and then plays it back using the computer's speaker system.

% Set the sampling frequency in Hertz and the duration of the recording in seconds.
% Note: The standard sampling rate for music is 44100 Hz.

clear;
clc;

Fs = 44100;              % Sampling frequency in Hz
t  = 5;                 % Duration of sampling in seconds

% Record the audio by setting y = audiorecorder(sampling rate,# of bits(8),# of channels(1))
fprintf('Recording... \n'); 
y = audiorecorder(Fs,8,1);  % set up to record audio to y at sampling rate Fs
disp('Start of recording.');
recordblocking(y,5);        % record the audio
disp('End of recording.');
disp('Play back will occur in 5 seconds');
pause(5);
disp('Playing back');
play(y);                    % play back the audio

close all;
% To run this program, click on Cell, then Evaluate Current Cell
% or simply press <Ctrl>Enter with your cursor inside the M-File.