Filters and MIDI with Matlab Using BF533 EZ Kit Lite and Visual DSP++ Donna Vigneri 12/12/2009 Florida Institute of Technology ECE 3551: Microcomputer Systems I Instructor: Veton Kepuska Filters and MIDI with Matlab Table of Contents I. II. III. IV. V. VI. VII. Problem Statement Literature Review of Various Solutions Selected solution and Implementation Results Concluding Remarks Bibliography and References Appendices Donna Vigneri Page 2 Filters and MIDI with Matlab Problem statement Design a low pass and high pass filter in Matlab that can be used to filter audio. Of specific concern are the magnitude, impulse, and pole-zero graphs, as well as the order. Then, create a MIDI file using MIDI toolbox in Matlab to be played through the Blackfin board using the base project “Talkthrough.” Donna Vigneri Page 3 Filters and MIDI with Matlab Literature Review of Various Solutions Matlab, filtering, and MIDI Through previous labs, we have used ‘fdatool’ in Matlab to create high pass and low pass Chebyshev Type II filters. The filters typically have an order of less than ten, but we may deviate slightly from that for this project. A problem arises when considering the order of the filter. Luckily, during my experimentation, I found that higher order filters seem to sound better, and since the highest order I worked with was seven, I may try for something a few places higher to get the effect I want. Also available in Matlab is a MIDI toolbox that I have used to create very simple (so far) MIDI files to be played through the board. While the file creation has little to do with Blackfin hardware, it is a unique addition to my project. There is an option for using FM synthesis to create the files as well as a random function that can generate random scores of notes. Both may be played through the filter to observe the effects. The first type of MIDI file could be a scale, starting at a lower tone and ending at a higher tone. The second type of file is the random note file mentioned, in which random notes are played at random times and volumes. Synthesis instructions used to create the files in Matlab are available in the Appendix section of this report. Matlab m-files are generated by Ken Schutte (see References). Blackfin Datasheet for hardware: BF533 EZ-Kit Lite The same type of algorithm can be used for this project as was used for Lab 5, in which we processed audio through the same type of filters; however, for my purposes, Process_data.c will need a change in order to work to my satisfaction. Also, as it has been some time since I programmed buttons and LEDs, they present a small hurdle. Donna Vigneri Page 4 Filters and MIDI with Matlab Selected Solution and Implementation Selected Solution I will use Matlab to create simple MIDI files (instead of more complicated synthesis files) because of a restriction on time. Process_data.c will need to have the added condition of normal audio passing, because its default is set at filtering mode, which means I can only turn the filtering with audio passthrough on and off. Implementation Project execution will proceed as follows: 1. 2. 3. 4. 5. 6. The board will be turned on and connected. Program will be run. Audio initiated, and playing through speakers. Press PF8, LED4 on. This button controls the low pass filter. Press PF9, LED5 on. This button controls the high pass filter. The filters should result in audio that still has a recognizable sound according to the original. Donna Vigneri Page 5 Filters and MIDI with Matlab Results In the Appendices section you will find a transcript of my lab troubleshooting after my initial code was completed. Most of my troubleshooting landed in the areas of filtering and LED programming. The buttons on the board are finicky and the board must be reset between runs because the LEDs refuse to go off again. The SIC_IMASK register had to be reset because it was masking the wrong interrupt(s). Donna Vigneri Page 6 Filters and MIDI with Matlab Concluding Remarks Conclusion This project was simple, but afforded me a better understanding of Matlab, filtering, and of MIDI, in which I am very interested because of the nature of my senior design project. Ken Schutte’s information has led me to the level of understanding I need of synthesis and MIDI. I have also gained a strong grasp of the registers, interrupts, and functions needed to use the Blackfin properly. I wish that the main point of my project had focused more on the hardware than on the software, but it is likely that my pulse width modulation project could be done by next week. All in all, the project was successful and I am proud of myself for completing it in only two days. Overall, programming the Blackfin has been rewarding and exciting, to say the very least! Donna Vigneri Page 7 Filters and MIDI with Matlab Bibliography and References “MATLAB and MIDI.” Ken Schutte. <http://www.kenschutte.com/midi> Used to assist in generating MIDI using MATLAB. Also contains sexy piano-roll info that just looks cool. Also contains information for generating scores of random MIDI notes. “MIDI toolbox.” Tuomas Eerola, Petri Toivianen. University of Jyväskylä in Finland. http://users.jyu.fi/~ptee/publications/3_2004.pdf used to understand toolbox already available in MATLAB for MIDI processing… “The Melisma Music Analyzer.” Sleator, Temperly. http://www.link.cs.cmu.edu/music-analysis/ for analyzing music and extracting information from it “Tutorials: C language.” Exforsys, Inc. http://www.exforsys.com/tutorials/c-language.html. I used this website to learn more about style and basic C manipulation, such as array usage and programming details. Donna Vigneri Page 8 Filters and MIDI with Matlab Appendices A. Transcript of Matlab synthesis >> %----------------------------------------------------------------------------->> % Generate 13 notes in a scale >> %initialize matrix >> N = 13; %number of notes >> M = zeros(N,6); >> >> M(:,1) = 1; % all in track 1 >> M(:,2) = 1; % all in channel 1 >> M(:,3) = (60:72)'; % note numbers: one ocatave starting at middle C (60) >> M(:,4) = round(linspace(80,120,N))'; % lets have volume ramp up 80->120 >> M(:,5) = (.5:.5:6.5)'; % note on: notes start every .5 seconds >> M(:,6) = M(:,5) + .5; % note off: each note has duration .5 seconds >> >> midi_new = matrix2midi(M); >> writemidi(midi_new, 'testout.mid'); >> >> %----------------------------------------------------------------------------->> >> %create 200 random notes with random start times and volumes >> >> % initialize matrix: >> N = 200; >> M = zeros(N,6); >> >> M(:,1) = 1; % all in track 1 >> M(:,2) = 1; % all in channel 1 >> M(:,3) = 30 + round(60*rand(N,1)); % random note numbers >> M(:,4) = 60 + round(40*rand(N,1)); % random volumes >> M(:,5) = 10 * rand(N,1); >> M(:,6) = M(:,5) + .2 + rand(N,1); % random duration .2 -> 1.2 seconds >> >> midi_new = matrix2midi(M); >> writemidi(midi_new, 'testout2.mid'); >> >> %------------------------------------------------------------------------------ Donna Vigneri Page 9 Filters and MIDI with Matlab >> >> % analyze the MIDI file I created ('testout.mid') >> >> midi = readmidi('testout.mid'); >> midiInfo(midi); -------------------------------------------------Track 1 -------------------------------------------------- 0 500000 0:0.000 meta Set Tempo microsec per quarter note: 0 0:0.000 32nd notes=24/8 meta Time Signature 4/2, clock ticks and notated 1 300 0:0.500 Note on nn=60 vel=80 1 300 0:1.000 Note on nn=60 vel=0 1 0 0:1.000 Note on nn=61 vel=83 1 300 0:1.500 Note on nn=61 vel=0 1 0 0:1.500 Note on nn=62 vel=87 1 300 0:2.000 Note on nn=62 vel=0 1 0 0:2.000 Note on nn=63 vel=90 1 300 0:2.500 Note on nn=63 vel=0 1 0 0:2.500 Note on nn=64 vel=93 1 300 0:3.000 Note on nn=64 vel=0 1 0 0:3.000 Note on nn=65 vel=97 1 300 0:3.500 Note on nn=65 vel=0 1 0 0:3.500 Note on nn=66 vel=100 1 300 0:4.000 Note on nn=66 vel=0 1 0 0:4.000 Note on nn=67 vel=103 1 300 0:4.500 Note on nn=67 vel=0 1 0 0:4.500 Note on nn=68 vel=107 1 300 0:5.000 Note on nn=68 vel=0 1 0 0:5.000 Note on nn=69 vel=110 1 300 0:5.500 Note on nn=69 vel=0 1 0 0:5.500 Note on nn=70 vel=113 1 300 0:6.000 Note on nn=70 vel=0 1 0 0:6.000 Note on nn=71 vel=117 1 300 0:6.500 Note on nn=71 vel=0 1 0 0:6.500 Note on nn=72 vel=120 1 300 0:7.000 Note on nn=72 vel=0 - 0 0:7.000 meta End of Track >> Donna Vigneri Page 10 Filters and MIDI with Matlab >> >> %midiInfo also returns a matrix of size Nx8, where N is the number of notes in the file. The 8 colunms indicate: 1. track number 2. channel number 3. note number (midi encoding of pitch) 4. velocity 5. start time (seconds) 6. end time (seconds) 7. message number of note_on 8. message number of note_off >> >> >> midi = readmidi('testout.mid'); >> Notes = midiInfo(midi,0); >> whos Notes Name Notes Size Bytes 13x8 832 Class Attributes double >> % creates the following matrix: >> >> Notes(1:5,:) ans = 1.0000 1.0000 60.0000 80.0000 0 0.5000 3.0000 4.0000 1.0000 1.0000 61.0000 83.0000 0.5000 1.0000 5.0000 6.0000 1.0000 1.0000 62.0000 87.0000 1.0000 1.5000 7.0000 8.0000 1.0000 1.0000 63.0000 90.0000 1.5000 2.0000 9.0000 10.0000 1.0000 1.0000 64.0000 93.0000 2.0000 2.5000 11.0000 12.0000 >> >> >> % Create "piano roll" >> >> %% compute piano-roll: Donna Vigneri Page 11 Filters and MIDI with Matlab >> [PR,t,nn] = piano_roll(Notes); >> >> %% display piano-roll: >> figure; >> imagesc(t,nn,PR); >> axis xy; >> xlabel('time (sec)'); >> ylabel('note number'); >> >> %Description of m-files from Ken Schutte: * readmidi.m: reads MIDI file into a Matlab structure * midi2audio.m: convert the Matlab midi structure into an audio vector * midiInfo.m: display detailed information about MIDI Matlab structure * synth.m: synthesize a single note * getTempoChanges.m: finds times of all tempo changes * midi2freq.m: convert MIDI note number (0-127) to frequency in Hz * matrix2midi.m: create MIDI Matlab structure from a matrix with information on individual notes * writemidi.m: write a MIDI Matlab structure (such as created by readmidi) to a MIDI file B. Transcript of Troubleshooting Process Run 1: Runs and compiles ok. There is no sound/audio passing through. PF8 press gets small noise, nothing more. PF8 turns this small noise on and off. No significance. Run 2: Found that DMA1 interrupt not set, but referred to. Change value of SIC_IMASK. Run 3: Filter order was low at 5 – change back to order 7 temporarily. Run 4: Transmits audio – hallelujah! Buttons do not work properly – look at buttons in ISR.c. Run 5: Make sure there are only two options (toggle) for each button PF8 and PF9. Counters should be appropriately set; look at errors in logic. Run 6: Change Tx/Rx information to include filtering action at the appropriate moments. Run 7: It works!!! Now, to create more amazing filters. Donna Vigneri Page 12