(New page: %Dan Morris %drmorris@purdue.edu %EE 301 Hw1.1 clear;clc; %define sampling rate as 20 kHz delta=1/20000; %now define the duration of each note, take quater note (q) to be 172 bpm. q=60/...) |
(I don't know enough about wiki to get the text to look like it should.) |
||
Line 1: | Line 1: | ||
− | %Dan Morris | + | %Dan Morris |
− | %drmorris@purdue.edu | + | %drmorris@purdue.edu |
− | %EE 301 Hw1.1 | + | %EE 301 Hw1.1 |
+ | clear;clc; | ||
+ | %define sampling rate as 20 kHz | ||
+ | delta=1/20000; | ||
− | + | %now define the duration of each note, take quater note (q) to be 172 bpm. | |
− | % | + | q=60/172; %quater |
− | + | h=2*q; %half | |
+ | w=4*q; %whole | ||
+ | e=q/2; %eighth | ||
+ | dotq=3/2*q; %dotted quater | ||
+ | doth=3*q; %dotted half | ||
− | %now define the | + | %now define the note frequencies |
− | + | x=3/5*440; %(440=5x/3 => x=3*440/5 => x=264) | |
− | + | A=5/3*x; | |
− | + | B=15/8*x; | |
− | + | C=x; | |
− | + | D=9*x/8; | |
− | + | Db= 277.18; | |
+ | E=5/4*x; | ||
+ | F=4/3*x; | ||
+ | G=3/2*x; | ||
+ | Gb= 369.99; | ||
− | %now define the | + | %now to define the song using arrays |
− | + | notes=[A,B,Db,D,E,Gb,Gb,G,G,G,D,E,F,Gb]; | |
− | A | + | duration=[h,q,q,dotq,e,q,q,q,e,e,q,e,e,doth]; |
− | B | + | |
− | + | ||
− | D | + | |
− | + | ||
− | E | + | |
− | F | + | |
− | + | ||
− | + | ||
− | %now to | + | %A) now to play the song at normal speed |
− | notes= | + | for n=1:length(notes) |
− | + | time=1:delta:duration(i); | |
+ | song=sin(2*pi*notes(i)*time); | ||
+ | sound(song, 1/delta); | ||
+ | end | ||
− | + | pause(3) | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | %B) now to play the song at twice as fast | |
+ | for n=1:length(notes) | ||
+ | time=1:delta:0.5*duration(i); | ||
+ | song=sin(2*pi*notes(i)*time); | ||
+ | sound(song, 1/delta); | ||
+ | end | ||
− | + | pause(3) | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | %C) now play the song x(t) scaled to y(t) = x(2t) | |
− | + | for n=1:length(notes) | |
− | %C) now play the song x(t) scaled to y(t) = x(2t) | + | time=1:delta:duration(i); |
− | for n=1:length(notes) | + | song=sin(2*2*pi*notes(i)*time); |
− | + | sound(song, 1/delta); | |
− | + | end | |
− | + | ||
− | end | + |
Revision as of 11:19, 4 September 2008
%Dan Morris %drmorris@purdue.edu %EE 301 Hw1.1
clear;clc; %define sampling rate as 20 kHz delta=1/20000;
%now define the duration of each note, take quater note (q) to be 172 bpm. q=60/172; %quater h=2*q; %half w=4*q; %whole e=q/2; %eighth dotq=3/2*q; %dotted quater doth=3*q; %dotted half
%now define the note frequencies x=3/5*440; %(440=5x/3 => x=3*440/5 => x=264) A=5/3*x; B=15/8*x; C=x; D=9*x/8; Db= 277.18; E=5/4*x; F=4/3*x; G=3/2*x; Gb= 369.99;
%now to define the song using arrays notes=[A,B,Db,D,E,Gb,Gb,G,G,G,D,E,F,Gb]; duration=[h,q,q,dotq,e,q,q,q,e,e,q,e,e,doth];
%A) now to play the song at normal speed for n=1:length(notes) time=1:delta:duration(i); song=sin(2*pi*notes(i)*time); sound(song, 1/delta); end
pause(3)
%B) now to play the song at twice as fast for n=1:length(notes) time=1:delta:0.5*duration(i); song=sin(2*pi*notes(i)*time); sound(song, 1/delta); end
pause(3)
%C) now play the song x(t) scaled to y(t) = x(2t) for n=1:length(notes) time=1:delta:duration(i); song=sin(2*2*pi*notes(i)*time); sound(song, 1/delta); end