Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 9 of 9

Thread: Draw filter curves on the display

  1. #1

    Draw filter curves on the display

    I am bad at arithmetic. That's why I need some support to draw filter curves on the display. I found an example and changed something. The curve looks like a low pass with a strong response. I need the waveform for some filters such as LowPass, BandPass and HighPass.

    My example of drawing a LowPass
    Code:
    //*************************************************************************
    // draw_filter_curves
    //*************************************************************************
    void draw_filter_curves (void)
    {
    	/* Original calculation
    	 uint8_t x = 80;
    	 uint8_t y = 50;
    	 uint8_t cx = 80;
    	 uint8_t cy = 80;
    	 int rx	= 10;
    	 int ry = 10;
    	 for (float i = 0; i < 1 * pi; i += .05) {
    		 x = cx + sin(i) * rx;
    		 y = cy + cos(i) * ry;
    		 disp.drawPixel(x, y, ST7735_WHITE);
    	 }
    	 */
    	
    	// my calculation for an LowPass with strong resonance
    	uint8_t x = 80;
    	uint8_t y = 50;
    	uint8_t cx = 80;
    	uint8_t cy = 80;
    	int rx	= -10;
    	int ry = -15;
    	for (float i = 0; i < 1 * pi; i += .05) {
    		y = cx + sin(i) * ry;
    		x = cy + log(i) * rx;
    		disp.drawPixel(160 - x, y, ST7735_WHITE);
    	}
    }
    Draw on Display


    Thanks for help

  2. #2
    Senior Member
    Join Date
    Jul 2020
    Posts
    463
    Filter responses are calculated from the poles and zeroes of the filter. Are we talking about
    analog filters or digital?

  3. #3
    They are digital filters. The filter curve is only symbolic and is controlled by the parameters Cutoff and Resonance.

  4. #4
    Senior Member
    Join Date
    Jul 2020
    Posts
    463
    Then you need to have your frequency variable i, and cos and sin to convert that into position on the unit circle,
    all that remains is to evaluate that z value for all the poles and zeroes, multiply by the overall gain factor to get the
    response for an arbitrary filter. This is direct application of the filter's equation (a rational in z).

  5. #5
    Thanks for your information. It's complicated.

  6. #6
    Senior Member
    Join Date
    Jul 2020
    Posts
    463
    Actually its complex (maths joke...)

  7. #7
    Member
    Join Date
    Feb 2020
    Location
    Dublin, Ireland
    Posts
    46
    Hi,
    You'll find code to calculate biquad filter response here:
    https://forum.juce.com/t/draw-freque...nction/20669/2

  8. #8
    Hi Alan

    I wrote my own code. The basis is a special sine table for drawing the filter curve.

    Code:
    //*************************************************************************
    // draw_filter_curves to LCD
    //*************************************************************************
    void draw_filter_curves (void)
    {
    	// clear old curve
    	disp.fillRect(20,48,112,38,ST7735_BLACK);
    	
    	// draw filter lowpass curve ------------------------------------------
    	
    		const uint8_t x_plot = 68;
    		const uint8_t y_plot = 85;
    		uint8_t x = 40;
    		uint16_t r = 0;
    		uint8_t y = 0;
    		uint8_t y_ = 0;
    		uint8_t i = 0;
    		uint8_t i_ = 0;
    		uint8_t q_typ = 12;			// Filter Q
    		uint16_t resonance = 0;
    		// pot_1 cutoff value
    		// pot_2 resonancy		
    		
    		for (i = 0; i < 48; i++)
    		{
    			resonance = (Filter_curve[(i * 8)]);
    			resonance = (((resonance >> 2) * pot_2) >> 7); 
    			r = (x + r - y) + resonance;
    			y = r / q_typ;
    			disp.drawLine((pot_1 / 2) + x_plot - i_,(y_plot - y_ / 2), (pot_1 / 2) + x_plot - i, (y_plot - y / 2),ST7735_RED);
    			i_ = i;
    			y_ = y;
    		}
    		disp.drawLine(20, (y_plot - y_ / 2), 20 + (pot_1 / 2), (y_plot - y_ / 2), ST7735_RED);
    
    }
    
    
    
    // Sine filter curv ----------------------------
    const byte Filter_curve[385] PROGMEM = {
    	1,      2,      2,      3,      2,      3,      3,      4,
    	5,      4,      7,      5,      9,      7,     10,     11,
    	11,     13,     13,     17,     16,     18,     21,     21,
    	23,     25,     27,     28,     32,     31,     36,     36,
    	39,     41,     43,     46,     48,     51,     53,     55,
    	57,     62,     63,     65,     70,     70,     75,     76,
    	81,     82,     85,     89,     92,     94,     97,    100,
    	104,    107,    109,    112,    116,    119,    122,    124,
    	129,    130,    135,    137,    140,    144,    147,    148,
    	154,    155,    158,    163,    163,    169,    169,    174,
    	177,    178,    182,    185,    187,    191,    192,    195,
    	199,    200,    203,    205,    209,    210,    212,    216,
    	216,    220,    221,    223,    226,    227,    230,    230,
    	233,    235,    235,    239,    238,    241,    242,    243,
    	245,    245,    246,    249,    247,    251,    249,    252,
    	251,    252,    253,    253,    253,    254,    254,    254,
    	253,    255,    254,    253,    253,    254,    252,    253,
    	251,    251,    250,    250,    248,    248,    246,    246,
    	245,    242,    243,    240,    239,    238,    236,    234,
    	233,    231,    230,    226,    226,    224,    221,    219,
    	217,    215,    212,    211,    208,    206,    202,    201,
    	198,    196,    192,    190,    188,    184,    182,    179,
    	177,    173,    170,    168,    164,    162,    158,    156,
    	153,    149,    147,    143,    141,    136,    135,    131,
    	128,    125,    122,    118,    116,    113,    109,    106,
    	104,    101,     96,     95,     92,     88,     85,     83,
    	80,     77,     74,     71,     69,     66,     63,     61,
    	57,     56,     53,     50,     49,     45,     43,     42,
    	38,     37,     35,     32,     31,     29,     26,     26,
    	22,     22,     20,     19,     16,     16,     13,     14,
    	11,     10,     10,      8,      8,      6,      6,      5,
    	4,      5,      2,      3,      2,      2,      2,      3,
    	0,		0,		0,		0,		0,		0,		0,		0,
    	0,		0,		0,		0,		0,		0,		0,		0,
    	0,		0,		0,		0,		0,		0,		0,		0,
    	0,		0,		0,		0,		0,		0,		0,		0,
    	0,		0,		0,		0,		0,		0,		0,		0,
    	0,		0,		0,		0,		0,		0,		0,		0,
    	0,		0,		0,		0,		0,		0,		0,		0,
    	0,		0,		0,		0,		0,		0,		0,		0,
    	0,		0,		0,		0,		0,		0,		0,		0,
    	0,		0,		0,		0,		0,		0,		0,		0,
    	0,		0,		0,		0,		0,		0,		0,		0,
    	0,		0,		0,		0,		0,		0,		0,		0,
    	0,		0,		0,		0,		0,		0,		0,		0,
    	0,		0,		0,		0,		0,		0,		0,		0,
    	0,		0,		0,		0,		0,		0,		0,		0,
    	0,		0,		0,		0,		0,		0,		0,		0,
    	0,
    };


    A little video of my synth project: https://youtu.be/ffCMaR70G6g
    Sound from my Handy (not so nice).

    Greetings Rolf

  9. #9
    Thanks for the link. Its very intresting

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •