Guitar Tuning Stability Code

From DDL Wiki

(Difference between revisions)
Jump to: navigation, search
(New page: == Introduction == This page contains all the MATLAB files necessary to run the tuning analysis we did. In order to run the code, copy the text from each section into its own MATLAB file...)
Current revision (01:34, 5 December 2008) (view source)
(Removing all content from page)
 
(One intermediate revision not shown.)
Line 1: Line 1:
-
== Introduction ==
 
-
This page contains all the MATLAB files necessary to run the tuning analysis we did.  In order to run the code, copy the text from each section into its own MATLAB file (named for the title of the section).  Put all these files in the same directory, then run them in MATLAB.  These functions were written in MATLAB 2007b with the symbolic math toolbox, and may or may not run in other versions.  The files are completely automated, no user input is necessary. 
 
-
 
-
To run the analysis, simply open MATLAB, and run the bridge_analysis.m file.  All other files are helper functions. 
 
-
 
-
 
-
== bridge_analysis.m ==
 
-
% Jeremy Ozer
 
-
% November 8th, 2008
 
-
% Engineering Design II
 
-
 
-
close all;
 
-
clear all;
 
-
clc;
 
-
 
-
global stiffness k ten0 def;
 
-
 
-
stiffness = 2e11;
 
-
k = [46.2/5.63 49.0/3.99 57.4/2.21 59.3/3.46 62.5/2.74 65.7/2.53]*1000; % Spring constants in N/m
 
-
ten0 = [46.2 49.0 57.4 59.3 62.5 65.7];    % Neutral string tensions
 
-
def = [5.63 3.99 2.21 3.46 2.74 2.53] / 1000;    % Neutral string deflections
 
-
 
-
theta = linspace(0,5,1000)*pi/180; % Create set of angles we are evaluating between 0 and 2 degrees
 
-
 
-
% Shifting Saddle Analysis
 
-
 
-
m = sin(theta)*0.0254;
 
-
ot = offtune(theta);
 
-
figure;
 
-
plot(1000*m, ot);
 
-
title('Comparison of Saddle Slippage to Tune Shift');
 
-
xlabel('Saddle offset (mm)');
 
-
ylabel('Frequency Error (Cents)');
 
-
legend('e','B','G','D','A','E');
 
-
 
-
 
-
% Now twisting Analysis
 
-
 
-
theta = linspace(0,90,1000)*pi/180;
 
-
dia = [229 279 406 610 813 1067]*10^-6;
 
-
 
-
l0 = 25.5*0.0254;
 
-
for i=1:length(theta)
 
-
    ltwist(i,:) = l0+pi*dia*theta(i);
 
-
end
 
-
% figure;
 
-
% plot(theta, ltwist);
 
-
 
-
delta = ltwist-l0;
 
-
for(j=1:length(theta))
 
-
    for i=1:6
 
-
        t(j,i) = ten0(i) + k(i)*delta(j);
 
-
    end
 
-
end
 
-
 
-
% figure;
 
-
% plot(theta,t);
 
-
 
-
ml = [1.67 3.16 5.88 10.84 20.33 38.10]*10^-4;
 
-
ml = ml.*[1 1 1 0.902 0.886 0.867];
 
-
 
-
for(j=1:length(theta))
 
-
    for i=1:6
 
-
        tunes(j,i) = 1/2*(t(j,i)./(ml(i)*l0)).^0.5;
 
-
    end
 
-
end
 
-
 
-
% figure;
 
-
% plot(theta,tunes);
 
-
 
-
f0 = tune(0);
 
-
 
-
sharp = [349.23 261.63 207.65 155.56 116.54 87.31];
 
-
for j=1:length(theta)
 
-
    for i=1:6
 
-
        n(j,i) = 1200*log2(tunes(j,i)/f0(i));
 
-
    end
 
-
end
 
-
cents = n;
 
-
 
-
 
-
nx = [0 100];
 
-
n = [100 100];
 
-
figure;
 
-
hold on;
 
-
plot(theta*180/pi, cents);
 
-
title('Comparison of Ball End Rotation to String Tune');
 
-
xlabel('Ball End Rotation (degrees)');
 
-
ylabel('Frequency Error (Cents)');
 
-
legend('e','B','G','D','A','E');
 
-
plot(nx,n,'r--',nx,2*n,'r--',nx,3*n,'r--');
 
-
axis([0 90 0 400]);
 
-
hold off;
 
-
 
-
 
-
% Prototype 2 Analysis
 
-
a = atan(0.0015/0.75);
 
-
lextra = 0.2*sin(a)*0.0254
 
-
l0 = 25.5*0.0254;
 
-
t = zeros(1);
 
-
delta = lextra;
 
-
for i=1:6
 
-
    t(i) = ten0(i) + k(i)*delta;
 
-
end
 
-
t
 
-
% figure;
 
-
% plot([0 a], [ten0;t]);
 
-
 
-
tunes = zeros(1);
 
-
for i=1:6
 
-
    tunes(i) = 1/2*(t(i)./(ml(i)*(l0+delta))).^0.5;
 
-
end
 
-
% figure;
 
-
% plot([0 a], [tune(0); tunes]);
 
-
 
-
f0 = tune(0);
 
-
sharp = [349.23 261.63 207.65 155.56 116.54 87.31];
 
-
for j=1:length(theta)
 
-
    for i=1:6
 
-
        n(i) = 1200*log2(tunes(i)/f0(i));
 
-
    end
 
-
end
 
-
cents = n;
 
-
 
-
 
-
nx = [0 100];
 
-
n = [100 100];
 
-
figure;
 
-
hold on;
 
-
plot([0 180/pi*a], [zeros(1,6);cents]);
 
-
title('Comparison of Ball End Rotation to String Tune');
 
-
xlabel('Ball End Rotation (degrees)');
 
-
ylabel('Frequency Error (Cents)');
 
-
legend('e','B','G','D','A','E');
 
-
% plot(nx,n,'r--',nx,2*n,'r--',nx,3*n,'r--');
 
-
% axis([0 90 0 400]);
 
-
hold off;
 
-
 
-
 
-
== eten.m ==
 
-
function tension = eten(theta)
 
-
global stiffness k ten0 def;
 
-
 
-
 
-
% orig_length = string_length(0);
 
-
% lengths = string_length(theta);
 
-
% delta = orig_length - lengths;
 
-
% t = zeros(length(theta),6);
 
-
% for(j=1:length(theta))
 
-
%    for i=1:6
 
-
%        if delta(j) < def(i)
 
-
%            t(j,i) = ten0(i)-slope(i).*delta(j);
 
-
%        else
 
-
%            t(j,i) = 0;
 
-
%        end
 
-
%    end
 
-
% end
 
-
% tension = t;
 
-
 
-
l0 = string_length(0);
 
-
l = string_length(theta);
 
-
delta = l-l0;
 
-
for(j=1:length(theta))
 
-
    for i=1:6
 
-
        t(j,i) = ten0(i) + k(i)*delta(j);
 
-
    end
 
-
end
 
-
 
-
tension = t;
 
-
 
-
 
-
== hands.m ==
 
-
function fhand = hands(theta)
 
-
lhand = 0.127;
 
-
lstring = 0.01346962;
 
-
lspring = 0.0254;
 
-
 
-
fspring = spring(theta);
 
-
tensions = eten(theta);
 
-
fstring = tensions(:,1)+tensions(:,2)+tensions(:,3)+tensions(:,4)+tensions(:,5)+tensions(:,6);
 
-
fstring = fstring';
 
-
fhand = (-fstring.*lstring+fspring.*lspring)./lhand;
 
-
 
-
 
-
 
-
== offtune.m ==
 
-
function cents = offtune(theta)
 
-
 
-
f0 = tune(0);
 
-
f = tune(theta);
 
-
 
-
% Frequencies from http://www.phy.mtu.edu/~suits/notefreqs.html
 
-
sharp = [349.23 261.63 207.65 155.56 116.54 87.31];
 
-
for j=1:length(theta)
 
-
    for i=1:6
 
-
        n(j,i) = 1200*log2(f(j,i)/f0(i));
 
-
    end
 
-
end
 
-
cents = n;
 
-
 
-
 
-
== spring.m ==
 
-
function tension = spring(theta)
 
-
hstring = 0.01346962;
 
-
hspring = 0.0254;
 
-
kspring = 7100.59;
 
-
initial_stretch = 0.0254;
 
-
 
-
tension = kspring.*spring_stretch(theta)+kspring*initial_stretch;
 
-
 
-
 
-
% stens = eten(theta);
 
-
% stenst = zeros(1);
 
-
% for i=1:length(theta)
 
-
%    stenst(i) = sum(stens(i,:));
 
-
% end
 
-
%
 
-
% tension = stenst*hstring/hspring;
 
-
 
-
 
-
== spring_stretch.m ==
 
-
function stretch = spring_stretch(theta)
 
-
stretch = 0.0254*sin(theta);
 
-
 
-
 
-
== string_length.m ==
 
-
function lengths = string_length(theta)
 
-
 
-
l0 = 25.5;
 
-
m = sin(theta); % Find horizontal offset
 
-
l = (m.^2+l0^2).^0.5+(1-cos(theta));
 
-
lengths  = 0.0254*l; % Convert inches to meters
 
-
 
-
 
-
== tune.m ==
 
-
function frequency = tune(theta)
 
-
orig_length = string_length(0);
 
-
lengths = string_length(theta);
 
-
delta = lengths - orig_length;
 
-
l = string_length(theta);
 
-
T = eten(theta);
 
-
density = 7800;
 
-
% a = [4.10 6.13 12.9 29.2 51.9 89.4]*10^-8;
 
-
% m = a*7800;
 
-
m = [1.67 3.16 5.88 10.84 20.33 38.10]*10^-4;
 
-
m = m.*[1 1 1 0.902 0.886 0.867];
 
-
% length(T(1,:))
 
-
% length(m)
 
-
% length(l(1))
 
-
% length(.5.*(T(1,:)./(m.*l(1))).^0.5)
 
-
 
-
f = zeros(length(theta),6);
 
-
for i=1:length(theta)
 
-
    f(i,:) = 1/2.*(T(i,:)./(m.*l(i))).^0.5;
 
-
end
 
-
frequency = f;
 

Current revision

Personal tools