Advertisement
prog

BasicDSP

Jul 22nd, 2011
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 3.58 KB | None | 0 0
  1. # slider1 = Frequency
  2. # slider2 = Fine tunning
  3. # slider3 = Tone
  4. # slider4 = Volume
  5.  
  6. # set the samplerate to 48000 samples per second
  7. samplerate = 48000
  8.  
  9. # down-convert to 1st IF:
  10. # z is a sawtooch oscillator
  11. # (ai,aq) form the mixer output
  12. # (ini, inq) are the soundcard's inputs
  13. z = mod1(z+slider1+slider2/10);
  14. ai = ini * cos1(z) - inq*sin1(z)
  15. aq = inq * cos1(z) + ini*sin1(z)
  16.  
  17. # filter IF:
  18. # samplerate: 48000 band-pass order: 130 cutoffs: 20 - 2000 Hz
  19. # http://mshook.appspot.com/z/firkernel.htm
  20. # I branch filter
  21. ai = fir(ai,-0.001512,-0.0014883,-0.0014579,-0.0014203,-0.0013755,-0.0013241,-0.0012686,-0.0012137,-0.0011669,-0.0011384,-0.0011414,-0.001191,-0.0013031,-0.0014933,-0.0017746,-0.0021559,-0.0026395,-0.0032202,-0.0038833,-0.0046052,-0.0053529,-0.0060859,-0.0067587,-0.0073236,-0.0077349,-0.0079535,-0.0079509,-0.0077139,-0.0072473,-0.006577,-0.0057501,-0.0048345,-0.0039157,-0.0030925,-0.0024705,-0.0021544,-0.0022396,-0.0028032,-0.0038952,-0.0055318,-0.0076888,-0.0102987,-0.0132499,-0.016389,-0.0195268,-0.0224466,-0.0249159,-0.0266994,-0.027574,-0.0273439,-0.0258547,-0.0230068,-0.0187652,-0.0131666,-0.0063221,0.0015843,0.0103015,0.0195224,0.0288972,0.038051,0.0466032,0.0541871,0.0604705,0.0651732,0.0680831,0.0690681,0.0680831,0.0651732,0.0604705,0.0541871,0.0466032,0.038051,0.0288972,0.0195224,0.0103015,0.0015843,-0.0063221,-0.0131666,-0.0187652,-0.0230068,-0.0258547,-0.0273439,-0.027574,-0.0266994,-0.0249159,-0.0224466,-0.0195268,-0.016389,-0.0132499,-0.0102987,-0.0076888,-0.0055318,-0.0038952,-0.0028032,-0.0022396,-0.0021544,-0.0024705,-0.0030925,-0.0039157,-0.0048345,-0.0057501,-0.006577,-0.0072473,-0.0077139,-0.0079509,-0.0079535,-0.0077349,-0.0073236,-0.0067587,-0.0060859,-0.0053529,-0.0046052,-0.0038833,-0.0032202,-0.0026395,-0.0021559,-0.0017746,-0.0014933,-0.0013031,-0.001191,-0.0011414,-0.0011384,-0.0011669,-0.0012137,-0.0012686,-0.0013241,-0.0013755,-0.0014203,-0.0014579,-0.0014883,-0.001512)
  22.  
  23. # Q branch filter
  24. aq = fir(aq,-0.001512,-0.0014883,-0.0014579,-0.0014203,-0.0013755,-0.0013241,-0.0012686,-0.0012137,-0.0011669,-0.0011384,-0.0011414,-0.001191,-0.0013031,-0.0014933,-0.0017746,-0.0021559,-0.0026395,-0.0032202,-0.0038833,-0.0046052,-0.0053529,-0.0060859,-0.0067587,-0.0073236,-0.0077349,-0.0079535,-0.0079509,-0.0077139,-0.0072473,-0.006577,-0.0057501,-0.0048345,-0.0039157,-0.0030925,-0.0024705,-0.0021544,-0.0022396,-0.0028032,-0.0038952,-0.0055318,-0.0076888,-0.0102987,-0.0132499,-0.016389,-0.0195268,-0.0224466,-0.0249159,-0.0266994,-0.027574,-0.0273439,-0.0258547,-0.0230068,-0.0187652,-0.0131666,-0.0063221,0.0015843,0.0103015,0.0195224,0.0288972,0.038051,0.0466032,0.0541871,0.0604705,0.0651732,0.0680831,0.0690681,0.0680831,0.0651732,0.0604705,0.0541871,0.0466032,0.038051,0.0288972,0.0195224,0.0103015,0.0015843,-0.0063221,-0.0131666,-0.0187652,-0.0230068,-0.0258547,-0.0273439,-0.027574,-0.0266994,-0.0249159,-0.0224466,-0.0195268,-0.016389,-0.0132499,-0.0102987,-0.0076888,-0.0055318,-0.0038952,-0.0028032,-0.0022396,-0.0021544,-0.0024705,-0.0030925,-0.0039157,-0.0048345,-0.0057501,-0.006577,-0.0072473,-0.0077139,-0.0079509,-0.0079535,-0.0077349,-0.0073236,-0.0067587,-0.0060859,-0.0053529,-0.0046052,-0.0038833,-0.0032202,-0.0026395,-0.0021559,-0.0017746,-0.0014933,-0.0013031,-0.001191,-0.0011414,-0.0011384,-0.0011669,-0.0012137,-0.0012686,-0.0013241,-0.0013755,-0.0014203,-0.0014579,-0.0014883,-0.001512)
  25.  
  26. # down-convert to audio using a second mixer
  27. y = mod1(y+0.0275)
  28. af = ai*cos1(y) - aq*sin1(y)
  29. audio = audio - slider3*(audio - af)
  30.  
  31. # send audio to output of soundcard
  32. # slider3 controls the volume
  33. uitL = audio * slider4 * 100
  34. uitR = audio * slider4 * 100
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement