matlab 코딩 해석점요.. 급해요 빠르게좀..ㅠㅠ부탁드릴께요

soniya의 이미지

안녕하세요...

저는 대학교에 다니는 공학도 입니다..

matlab을 처음 배우는데요... 프로젝트 발표를 하는데..

멧렙으로 음악연주하기를 하고싶어서 소스를 구했는데요..

해석이 안됩니다. 다른사람들도 이해할수 있게 해석을 해야 하는데.

제가 만든 코딩이 아니라서 어떻게 설명해야 되고

뭔지도 잘 모르겟습니다.

그래서 해석좀 부탁드립ㄴ디ㅏ.

2. playtone

function x = playtune(str,cf,cb)
% Play musical tune.
% [x] = playtune(str,[cf],[cb])
%
% Notation:
% [CDEFGAB] keys, 5 full octaves
% [12345678] key/rest duration,
% with the default [1] semiquaver, [2] quaver, [4] crochet and [8] minim
% [#] sharp / [b] flat / [.] rest / [^] raise octave / [_] lower octave
%
% Examples:
% C major -- playtune('^2CDEFGAB^C_BAGFEDC');
% F major -- playtune('^2FGABb^CDEFEDC_BbAGF');
% B minor (harmonic) -- playtune('^2B^C#DEF#GA#BA#GF#EDC#_B');
% F# minor (melodic) -- playtune('^2F#G#AB^C#D#E#F#EDC#_BAG#F#');
% Doe-a-deer -- playtune('^^6C2D6E2C4EC8E6D2EFFED8F.');
%
% Advanced features:
% CF is a (N,2) matrix where the first column contains the frequency and
% the second column the corresponding scaling coefficient. The simplest
% choice of CF would be cf = [1 1] which generates a pure sine wave. The
% default CF is cf = [1 1; 1.001 0.33; 1.002 0.2; 0.999 0.33; 0.998 0.2]
% which generates a tone resembling the flute.
% CB is a (1,9) vector containing the duration of that particular symbol (1-9).
%
% v2.0, Alan Tan (weechiat@gmail.com)

if nargin < 2 | isempty(cf), cf = [1 1; 1.001 0.33; 1.002 0.2; 0.999 0.33; 0.998 0.2]; end
if nargin < 3 | isempty(cb), cb = [1:9]; end

% Set constants.
Fc = 65.4064;
Fs = 2^13;
Ts = 1/Fs;
Td = 0.1;
c1 = 2*pi*Fc;
c2 = 2.^([0:60]/12);

% Convert string to score.
d = -ones(1,length(str));
d(find(str == 'C')) = 0;
d(find(str == 'D')) = 2;
d(find(str == 'E')) = 4;
d(find(str == 'F')) = 5;
d(find(str == 'G')) = 7;
d(find(str == 'A')) = 9;
d(find(str == 'B')) = 11;
d(find(str == '^')) = 0;
d(find(str == '_')) = 0;
d(find(str == '.')) = 0;
u1 = find(str == 'b');
d(u1-1) = d(u1-1)-1;
u2 = find(str == '#');
d(u2-1) = d(u2-1)+1;
str([u1,u2]) = [];
d([u1,u2]) = [];

% Construct vector.
x = [];
oc = 1;
Tu = Td;
t = [Ts:Ts:Tu];
L = length(t);
th = zeros(size(cf,1),1);
for k = 1:length(str)
if d(k) == -1
Tu = cb(str(k)-48)*Td;
t = [Ts:Ts:Tu];
L = length(t);
else
switch str(k),
case '^', oc = oc+12;
case '_', oc = oc-12;
case '.', x(end+L) = 0;
otherwise
wt = c1*c2(oc+d(k))*t;
x(end+(1:L)) = transpose(cf(:,2))*sin(cf(:,1)*wt+th(:,ones(1,L)));
th = rem(cf(:,1)*wt(end)+th,2*pi);
end
end
end

% Set output.
if ~nargout
soundsc(x,Fs);
clear x;
end

--------------------------------------------------------------

이것인데요...

어떻게 만들어 졋는지 너무 궁금합니다.

cf나 cb soundsc u 값등이 어디서 나왔으며 어떻게 어떻게 만들고 해석해서 설명해야 할지 알고싶습니다..

이것을 다른 사람한테 설명해야 하는데..

도와주세요..

전반적인해석좀 부탁 드립니다

전반 적인 해석이요!.... ㅠㅠ 감사합니다.

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.