Difference between revisions of "Music notes"

From Wikiid
Jump to: navigation, search
Line 26: Line 26:
 
     notch    = lowpass + highpass ;  // Optional!
 
     notch    = lowpass + highpass ;  // Optional!
 
   }
 
   }
 +
 +
== Another Low-pass filter ==
 +
Leaving aside the sophisticated design methods based on Z transformation with its extensive math, this idea uses another approach based on a recursive equation. You calculate each output-signal sample as the sum of the input signal and the previous output signal with corresponding coefficients. A recursive equation defines a single-pole lowpass filter as: Y[n]=X[n]×a0+Y[n–1]×b1, where X[n] and Y[n] are input and output values of sample [n], Y[n–1] is an output value of the previous sample [n–1], and a0 and b1 are weight coefficients that decrement δ controls. The coefficients have the value of 0<δ<1, a0=1–δ, and b1=δ. Physically, δ is the amount of decay between adjacent output samples when the input signal drops from a high level to a low level. You can directly specify the value of δ or find it from the desired time constant of the filter, d, which is the number of samples it takes the output to rise to 63.2% of the steady-state level for a lowpass filter. A fixed relationship exists between d and δ: δ=e–1/d, where e is the base of natural logarithms. The preceding equations yield Y[n]=Y[n–1]+(1–δ)×(X[n]–Y[n–1]).
 +
 +
Instead of multiplying a decimal-point number, 1–δ, it is more convenient for assembler programming to divide by the reciprocal integer, F=1/(1–δ): Y[n]=Y[n–1]+(X[n]–Y[n–1])/F. Thus, you can determine the digital filter’s parameters using the following steps:
 +
 +
  1. Choose the parameter F. For assembler, it is convenient to perform division as right shifts. For right shifts, the value of F should be 2S, where S is the number of shifts. Let F equal 8, which you reach after three right shifts.
 +
  2. Calculate the decrement: δ=1–1/F=1–1/8=0.875.
 +
  3. Calculate the time constant as d=–1/lnδ=–1/ln0.875=7.49 samples.
 +
 +
The equation Y[n]=Y[n–1]+(X[n]–Y[n–1])/F determines the design of the microcontroller’s algorithm for the filter
  
 
{{Arduino}}
 
{{Arduino}}

Revision as of 14:02, 5 January 2009

Miscellaneous notes about computer music

Ode To Joy

This is a handy quicky test:

 int odeToJoy[] = { F2S,QUARTER, F2S,QUARTER, G2 ,QUARTER, A3 ,QUARTER,
                    A3 ,QUARTER, G2 ,QUARTER, F2S,QUARTER, E2 ,QUARTER,
                    D2 ,QUARTER, D2 ,QUARTER, E2 ,QUARTER, F2S,QUARTER,
                    F2S,DOTTED_QUARTER, E2,EIGHTH, E2,HALF,
                    F2S,QUARTER, F2S,QUARTER, G2 ,QUARTER, A3 ,QUARTER,
                    A3 ,QUARTER, G2 ,QUARTER, F2S,QUARTER, E2 ,QUARTER,
                    D2 ,QUARTER, D2 ,QUARTER, E2 ,QUARTER, F2S,QUARTER,
                    E2 ,DOTTED_QUARTER, D2,EIGHTH, D2,HALF, 
                    E2 ,QUARTER, E2 ,QUARTER, F2S,QUARTER, D2 ,QUARTER,
                    E2 ,QUARTER, F2S,EIGHTH,  G2,EIGHTH, F2S,QUARTER, D2 ,QUARTER,
                    E2 ,QUARTER, F2S,EIGHTH,  G2,EIGHTH, F2S,QUARTER, E2 ,QUARTER,
                    D2 ,QUARTER, E2 ,QUARTER, A,QUARTER, REST,ETERNITY } ;

Digital filter

 filter ( input, tunefactor, damping )
 {
   lowpass  += tunefactor * bandpass ;
   highpass  = input - lowwpass  - damping * bandpass ;
   bandpass += tunefactor * highpass ;
   notch     = lowpass + highpass ;  // Optional!
 }

Another Low-pass filter

Leaving aside the sophisticated design methods based on Z transformation with its extensive math, this idea uses another approach based on a recursive equation. You calculate each output-signal sample as the sum of the input signal and the previous output signal with corresponding coefficients. A recursive equation defines a single-pole lowpass filter as: Y[n]=X[n]×a0+Y[n–1]×b1, where X[n] and Y[n] are input and output values of sample [n], Y[n–1] is an output value of the previous sample [n–1], and a0 and b1 are weight coefficients that decrement δ controls. The coefficients have the value of 0<δ<1, a0=1–δ, and b1=δ. Physically, δ is the amount of decay between adjacent output samples when the input signal drops from a high level to a low level. You can directly specify the value of δ or find it from the desired time constant of the filter, d, which is the number of samples it takes the output to rise to 63.2% of the steady-state level for a lowpass filter. A fixed relationship exists between d and δ: δ=e–1/d, where e is the base of natural logarithms. The preceding equations yield Y[n]=Y[n–1]+(1–δ)×(X[n]–Y[n–1]).

Instead of multiplying a decimal-point number, 1–δ, it is more convenient for assembler programming to divide by the reciprocal integer, F=1/(1–δ): Y[n]=Y[n–1]+(X[n]–Y[n–1])/F. Thus, you can determine the digital filter’s parameters using the following steps:

  1. Choose the parameter F. For assembler, it is convenient to perform division as right shifts. For right shifts, the value of F should be 2S, where S is the number of shifts. Let F equal 8, which you reach after three right shifts.
  2. Calculate the decrement: δ=1–1/F=1–1/8=0.875.
  3. Calculate the time constant as d=–1/lnδ=–1/ln0.875=7.49 samples.

The equation Y[n]=Y[n–1]+(X[n]–Y[n–1])/F determines the design of the microcontroller’s algorithm for the filter


Wikiid Pages relating to Arduino (edit)
Arduino
Command line Arduino
Startup code for Arduino
Low level functions for Arduino
Putting data in flash on the Arduino
External resources for Arduino
Board schematics for Arduino
Misc notes: Circuit notes, Music notes, Stepper motors