moving some particular frequency bands with minim's fft library

edited August 2015 in Library Questions

Hello!

I hope anybody here can help me. I am trying to write an application for decoding AM-Signals and SSB-Signals on shortwave delivered by an Direct Conversion Receiver. The library which I use for analyse the soundcards frequency spectrum is minim's fft-library. I now how to get the amplitude of any frequency band an I know how to set the amplitude of any frequency band. I also know who to get the middle frequency of any frequency band, but I' am not able to move down some particular frequency bands in the sound spectrum.

This is what I tried, but it doesn't sound really good.

class InputOutputBind implements AudioSignal, AudioListener{ private float[] leftChannel ; private float[] rightChannel; InputOutputBind(int sample){ leftChannel = new float[sample]; rightChannel= new float[sample]; } // This part is implementing AudioSignal interface, see Minim reference void generate(float[] samp){ arraycopy(leftChannel,samp); } void generate(float[] left, float[] right){ arraycopy(leftChannel,left); arraycopy(rightChannel,right); } // This part is implementing AudioListener interface, see Minim reference synchronized void samples(float[] samp){
int index_band = 0; fft.forward(samp); for(int i = 0; i < 1024; i++){ if ((i >= index_lsb) && (i < index_usb)){float bandanteil = fft.getBand(i); fft1.setBand(index_band, bandanteil * 10.0); index_band += 1;} else if (i > index_usb){fft1.setBand(index_band, 0.0); index_band += 1;} } fft.inverse(samp); arraycopy(samp,leftChannel); } synchronized void samples(float[] sampL, float[] sampR){ arraycopy(sampL,leftChannel); arraycopy(sampR,rightChannel); }
}

Answers

  • You'll get a better response if you format your code. Here's how:

    http://forum.processing.org/two/discussion/8045/how-to-format-code-and-text

  • You'll get a better response if you format your code. Here's how:

    Thank you, I think you are right! So this should look better.

    Hello!

    I hope anybody here can help me. I am trying to write an application for decoding AM-Signals and SSB-Signals on shortwave delivered by an Direct Conversion Receiver. The library which I use for analyse the soundcards frequency spectrum is minim's fft-library. I now how to get the amplitude of any frequency band an I know how to set the amplitude of any frequency band. I also know who to get the middle frequency of any frequency band, but I' am not able to move down some particular frequency bands in the sound spectrum.

    This is my newest code:

    `

    import ddf.minim.*;
    import ddf.minim.analysis.*;
    Minim            minim;
    AudioInput       lineIn;
    AudioOutput      lineOut;
    InputOutputBind  audiosignal;
    FFT fft1;
    FFT fft2;
    int anzahl_samples = 4096;
    int samplerate = 22000;
    
    
    
    
    
    void setup() {
      size(1024, 800, P2D);
      minim = new Minim(this);
      lineIn = minim.getLineIn(Minim.STEREO, anzahl_samples, samplerate);
      lineOut = minim.getLineOut(Minim.STEREO, anzahl_samples, samplerate);
      audiosignal = new InputOutputBind(anzahl_samples);
      lineIn.addListener(audiosignal);
      lineOut.addSignal(audiosignal);
      fft1 = new FFT(anzahl_samples, samplerate);
      fft2 = new FFT(anzahl_samples, samplerate);
    }
    
    
    
    
    
    void draw() {
      background(0);
      stroke(255);
      float x = 0.0;
      fft1.forward(lineIn.left);
      fft2.forward(lineIn.right);
      for (int i = 0; i < lineIn.bufferSize (); i++) {
        float bandanteil_left = fft1.getBand(i) * 10.0;
        float bandanteil_right = fft2.getBand(i) * 10.0;
        line(x, (height/2.0), x, (height/2.0) - bandanteil_left);
        line(x, height, x, height - bandanteil_right);
        x += 0.25;
      }
    }
    
    
    
    
    
    
    
    
    
    class InputOutputBind implements AudioSignal, AudioListener {
      private float[] leftChannel ;
      private float[] rightChannel;
      InputOutputBind(int sample) {
        leftChannel = new float[sample];
        rightChannel= new float[sample];
      }
      // This part is implementing Audiosignal interface, see Minim reference
      void generate(float[] samp) {
        // arraycopy(leftChannel,samp);
      }
      void generate(float[] left, float[] right) {
        float[] leftChannel_neu = new float[leftChannel.length];
        float[] rightChannel_neu = new float[rightChannel.length];
        for (int i = 0; i < leftChannel.length; i++) {
          leftChannel_neu[i] = leftChannel[i] * 2.0;
          rightChannel_neu[i] = rightChannel[i] * 2.0;
        }
        arraycopy(leftChannel_neu, left);
        arraycopy(rightChannel_neu, right);
      }
      // This part is implementing AudioListener interface, see Minim reference
      synchronized void samples(float[] samp) {
        arraycopy(samp, leftChannel);
      }
      synchronized void samples(float[] sampL, float[] sampR) {
        arraycopy(sampL, leftChannel);
        arraycopy(sampR, rightChannel);
      }
    }
    
    

    `

  • You'll get a better response if you format your code. Here's how:

    Thank you, I think you are right! So this should look better.

    Hello!

    I hope anybody here can help me. I am trying to write an application for decoding AM-Signals and SSB-Signals on shortwave delivered by an Direct Conversion Receiver. The library which I use for analyse the soundcards frequency spectrum is minim's fft-library. I now how to get the amplitude of any frequency band an I know how to set the amplitude of any frequency band. I also know who to get the middle frequency of any frequency band, but I' am not able to move down some particular frequency bands in the sound spectrum.

    This is my newest code:

    `

    import ddf.minim.*;
    import ddf.minim.analysis.*;
    Minim            minim;
    AudioInput       lineIn;
    AudioOutput      lineOut;
    InputOutputBind  audiosignal;
    FFT fft1;
    FFT fft2;
    int anzahl_samples = 4096;
    int samplerate = 22000;
    
    void **setup**() {
      size(1024, 800, P2D);
      minim = new Minim(this);
      lineIn = minim.getLineIn(Minim.STEREO, anzahl_samples, samplerate);
      lineOut = minim.getLineOut(Minim.STEREO, anzahl_samples, samplerate);
      audiosignal = new InputOutputBind(anzahl_samples);
      lineIn.addListener(audiosignal);
      lineOut.addSignal(audiosignal);
      fft1 = new FFT(anzahl_samples, samplerate);
      fft2 = new FFT(anzahl_samples, samplerate);
    }
    
    void **draw**() {
      background(0);
      stroke(255);
      float x = 0.0;
      fft1.forward(lineIn.left);
      fft2.forward(lineIn.right);
      for (int i = 0; i < lineIn.bufferSize (); i++) {
        float bandanteil_left = fft1.getBand(i) * 10.0;
        float bandanteil_right = fft2.getBand(i) * 10.0;
        line(x, (height/2.0), x, (height/2.0) - bandanteil_left);
        line(x, height, x, height - bandanteil_right);
        x += 0.25;
      }
    }
    
    class InputOutputBind implements AudioSignal, AudioListener {
      private float[] leftChannel ;
      private float[] rightChannel;
      InputOutputBind(int sample) {
        leftChannel = new float[sample];
        rightChannel= new float[sample];
      }
      // This part is implementing Audiosignal interface, see Minim reference
      void generate(float[] samp) {
        // arraycopy(leftChannel,samp);
      }
      void generate(float[] left, float[] right) {
        float[] leftChannel_neu = new float[leftChannel.length];
        float[] rightChannel_neu = new float[rightChannel.length];
        for (int i = 0; i < leftChannel.length; i++) {
          leftChannel_neu[i] = leftChannel[i] * 2.0;
          rightChannel_neu[i] = rightChannel[i] * 2.0;
        }
        arraycopy(leftChannel_neu, left);
        arraycopy(rightChannel_neu, right);
      }
      // This part is implementing AudioListener interface, see Minim reference
      synchronized void samples(float[] samp) {
        arraycopy(samp, leftChannel);
      }
      synchronized void samples(float[] sampL, float[] sampR) {
        arraycopy(sampL, leftChannel);
        arraycopy(sampR, rightChannel);
      }
    }
    
    

    `

Sign In or Register to comment.