Monday, November 19, 2012

ADXL335 + Arduino + Processing: Low Pass Filtering


Further proof that I have no life :D

I had some spare time today and after spending about half a day doing a new compositional piece, I had to switch gears to do other things not music related. Oh wait, this is. :P

So far, the Teensy 2.0 has been great. After following the instructions from their website (copy udev files - whatever that is - and running the Teensyduino installer), the Arduino environment now has added options for the Teensy.

Everything appears to work as per the arduino. There is a teensy loader program that appears when you compile, and it appears to be the glue that installs the code into the μC.

One thing that caught me out was that the Teensy does not have a 3.3v output connector like the Arduino; I'd connected the ADXL335 to the 5V, then several minutes in something at the back of my mind told me.... adxl335... 3.3v.... Thankfully the accelerometer seemed unharmed by it's short dance with over-voltaging. Is voltaging a word?

I am not posting the code for this guy as it's mainly a test bed for my low pass filter tests; the code is basically mush. In any case, the current LPF implemented is the digital low pass filter straight off wikipedia. There are other things I want to try like supersampling, kernel based filtering, croissant eating, tea drinking, stuff like that.

The arduino simply sends CSV with 6 values; 3 values for the filtered and 3 values for the unfiltered. The processing sketch then opens a serial port, uses the java split() method to extract the data and then draws it on the screen.

Well, time for bed.

5 comments:

Ryan Tan said...

Hi, I have been viewing some of your projects and pretty impressed! Is it okay to ask for your email sir and ask for some advices regarding wind synthesis? I'm building a digital saxophone which can reproduce the sound of an actual saxophone and I really need some of your expert advices if it is okay sir. :)

Gallen Wolf said...

Hello! Thanks for the interest, I'm quite surprised people actually can find/read this blog :)

You sound like you are trying to create a synthesized saxophone instrument? I doubt I can help you but my email is "alvin yap vfx at geemail" - I'm sure you can figure that out :)

You may also want to take gander at other modelled wind instruments e.g.

Wallander and SampleModelling.
http://www.wallanderinstruments.com/
http://www.samplemodeling.com/en/products_sax.php

Ryan Tan said...

haha. okay thanks sir, will email you right now. I just read your reply. :)
i went to the website you referred but my group wants to make the artificial saxophone. We are going to use a pvc pipe. :)

Ryan Tan said...

Hi i'm working on a project that is called the "Electronic Saxophone" which can reproduce the sound of an actual saxophone. So far I was able to finish the button combinations code but was not satisfied of my work because my project doesn't sound like the actual saxophone even though I followed the exact frequency of each note of the Alto Saxophone. I found a project that was similar to ours but still doesn't sound even near the actual saxophone smiley-sad Any ideas on how to improve my project? I'm new to Arduino, just learned this for about 3 weeks. Hope you guys can help, thanks! smiley-grin smiley-grin
P.S.: My groupmate is still working on the microphone module to detect wind passing through the mic so I didn't integrate the code for the microphone yet.
We are using the Arduino ATmega644 by the way


#define NOTE_AS2 116.540
#define NOTE_B2 123.470
#define NOTE_C3 130.810
#define NOTE_CS3 138.590
#define NOTE_D3 146.830
#define NOTE_DS3 155.560
#define NOTE_E3 164.810
#define NOTE_F3 174.610
#define NOTE_FS3 185.000
#define NOTE_G3 196.000
#define NOTE_GS3 207.650
#define NOTE_A3 220.000
#define NOTE_AS3 233.080
#define NOTE_B3 246.940
#define NOTE_C4 261.630
#define NOTE_CS4 277.180
#define NOTE_D4 293.660
#define NOTE_DS4 311.130
#define NOTE_E4 329.630
#define NOTE_F4 349.230
#define NOTE_FS4 369.990
#define NOTE_G4 392.000
#define NOTE_GS4 415.300
#define NOTE_A4 440.000
#define NOTE_AS4 466.160
#define NOTE_B4 493.880
#define NOTE_C5 523.250
#define NOTE_CS5 554.370
#define NOTE_D5 587.330
#define NOTE_DS5 622.250
#define NOTE_E5 659.260
#define NOTE_F5 698.460

//Buttons 1-8
int swiPin [] = {23,24,25,26,27,28,29};
//Buttons 9-16
int swiPin2 [] = {4,5,6,7,9,10,11,12};
//Buttons 17-19
int swiPin3 [] = {22,30,31};

int speakerPin = 8;


//Grouping of combinations
int groupA,groupB,groupC;
void setup(){
//Circuit is normally high
for(int x = 0; x<7; x++){
pinMode(swiPin[x], INPUT);
pinMode(swiPin2[x], INPUT);
digitalWrite(swiPin[x], 1);
digitalWrite(swiPin2[x], 1);
}
for(int x = 0; x<2; x++){
pinMode(swiPin3[x], INPUT);
digitalWrite(swiPin3[x], 1);
}
Serial.begin(9600);
}

void check_fingering(){
//Check keys pressed

//Buttons 1-8
groupA = ~1*(digitalRead(swiPin[0])) + 2*(digitalRead(swiPin[1])) + 4*(digitalRead(swiPin[2])) + 8*(digitalRead(swiPin[3])) + 16*(digitalRead(swiPin[4])) + 32*(digitalRead(swiPin[5])) + 64*(digitalRead(swiPin[6])) + 128*(digitalRead(swiPin[7]));
//Buttons 9-16
groupB = ~1*(digitalRead(swiPin2[0])) + 2*(digitalRead(swiPin2[1])) + 4*(digitalRead(swiPin2[2])) + 8*(digitalRead(swiPin2[3])) + 16*(digitalRead(swiPin2[4])) + 32*(digitalRead(swiPin2[5])) + 64*(digitalRead(swiPin2[6])) + 128*(digitalRead(swiPin2[7]));
//Buttons 17-19
groupC = ~1*(digitalRead(swiPin3[0])) + 2*(digitalRead(swiPin3[1])) + 4*(digitalRead(swiPin3[2]));

}

void loop(){
check_fingering();

//Note: B flat = A#2
if ((groupA == 191)&&(groupB == 64)&&(groupC == 0)){
Serial.println("B Flat");
tone(speakerPin, NOTE_AS2 );
}

//Note: B = B2
else if ((groupA == 191)&&(groupB == 32)&&(groupC == 0)){
Serial.println("B");
tone(speakerPin, NOTE_B2 );
}

//Note: C =C3
else if ((groupA == 191)&&(groupB == 0)&&(groupC == 0)){
Serial.println("C");
tone(speakerPin, NOTE_C3 );
}

//I deleted the continuation of the code because it simply are all the note combinations and it would be such a long post
else{
noTone(speakerPin); //default note==c#5
}


}

also my friend is making the microphone module and although it is working it has problems because it gets data from wind blowing through the microphone
but also gets data from voice through the microphone, how can we get data only from wind?

Gallen Wolf said...

Hi Ryan,
I see you posted a fair bit of code, let me know if you want it deleted. I didn't go through it but I think emulating a saxophone's tone isn't as simply hunting down the fundamental frequencies for each note - a piano, flute, or marimba will have the same fundamental frequencies as well!

What separates them would be their attack and timbre. The timbre is - from what little understanding I have - comes from the type of overtones and harmonics. E.g. square waves sound very hollow, kinda like a clarinet. A sine or triangle will be closer to a flute.

For the attack portion, you probably need to check out ADSR for envelope controls. My project is meant to control synths, not to be a synth/generator itself.

As for using a microphone to collect the sound of wind, the first thing that comes to mind would be to use the volume of the signal to modulate the volume. I have my doubts the micro controller will be fast enough to run dsp code on the raw signal for processing but who knows :)

All the best!