Description

Guitar and Audio technology blog

Monday 20 December 2010

Biquad notch filter


Following the last blog post more code has been written making a functioning biquad notch filter.  Although there is some aliasing produced the filter acts a notch filter with the peak around the 8khz range.  The filter works very well as a high pass filter as it cuts all low frequencies.  Switch statements are used to make sure the correct samples for previous inputs and outputs are used. The code is as follows:

void Laneycub10::processReplacing (float** inputs, float** outputs, VstInt32 sampleFrames)
{
float* in = inputs[0];
float* out1 = outputs[0];
float* out2 = outputs[1];

float a0 = 1;
float a1 = 0;
float a2 = -1;
float b1 = 0.1;
float b2 = 0.9;
float xn0 = 0;
float xn1 = 0;
float xn2 = 0;
float yn1 = 0;
float yn2 = 0;
while (--sampleFrames >= 0)
{
float x = *in++;
switch (xcursor) {
case 0:
xn0 = xbuffer[xcursor];
xn1 = xbuffer[2];
xn2 = xbuffer[1];
break;

case 1:
xn0 = xbuffer[xcursor];
xn1 = xbuffer[0];
xn2 = xbuffer[2];

break;

case 2:
xn0 = xbuffer[xcursor];
xn1 = xbuffer[1];
xn2 = xbuffer[0];

break;

}

switch (ycursor) {
case 0:

yn1 = ybuffer[2];
yn2 = ybuffer[1];
break;

case 1:

yn1 = ybuffer[0];
yn2 = ybuffer[2];

break;



}


float y = a0*xn0 + a1*xn1 + a2*xn2 - b1*yn1 - b2*yn2;
xbuffer[xcursor++] = x;
ybuffer[ycursor++] = y;


if (xcursor == size)
xcursor = 0;
if (ycursor == size) //failsafe W cursor should never reach size
ycursor = 0;

*out1++ = y;

Saturday 11 December 2010

Chebyshev polynomial soft clipper

After an intial set up with the VST template, the max/msp chebyshev experiment has been repeated adding the harmonics with the polynomials using the VST sdk.  The code from the previous experiment has been modified to give each chebyshev polynomial its own variable which is calculated separately and then mixed (added) together at output.  This seems to produce stronger harmonic content and reduces clipping.  The nature of the chebsyhev polynomials are to scale the output values between 1 and -1.  The first five (including the initial frequency) harmonics are produced and from the waveform the frequency difference can clearly be seen.  The image below contains the effected output waveform above and the original source below.





Code:



void Laneycub10::processReplacing (float** inputs, float** outputs, VstInt32 sampleFrames)
{
       float* in = inputs[0];
       float* out1 = outputs[0];
       float* out2 = outputs[1];

       while (--sampleFrames >= 0)
       {
              float x = *in++;


              float y = ((2 * (x*x)) -1);
              float y2 = ((4*(x*x*x))-(3*x));
              float y3 = (8 * (x*x*x*x)) - (8 *(x*x)) + 1;
              float y4 = ((16 * (x*x*x*x*x)) - (20 * (x*x*x)) + (5*x));
              *out1++ = y + y2 + y3 + y4 + x;
              *out2++ = y + y2 + y3 + y4 + x;

              }

Filter analysis

Part of the initial experiment was to analyse the tone stack output of the amplifier and how the controls (marked 0 – 10 under ‘tone’) varied the frequency response of the amplifier.  To measure the response white noise consisting of a full band of frequencies were generated and used as an input source for the amplifier.  The tone control was then moved from the 0 position to 10 and a recording of the output was made.  To record the amplifier a Rode NT5 condenser microphone was used due to its flat frequency response, although as standard a shure sm57 may be used for a guitar recording, the microphones specific frequency response boosts certain guitar friendly frequencies, for the experiment however the aim was to reduce the colouring of the microphone by as much as possible(Fig1 Rode nt5 frequency response).  An important aspect to take into consideration is the frequency response of the speaker in the amplifier as it also adds a great deal of colouration to the tone (Fig2 Celestion Tube 10 speaker frequency response).  Although less important in the tone stack analysis as all frequencies are considered the speakers frequency response is a vital consideration for the waveshaping algorithm design.  In Fig 3 (Frequency plot of amplifier with noise) the top line, representing the tone control at 10, almost identically represents the frequency plot of the speaker specification (for example the drop in dB around the 10kHz area).  The bottom line in Fig 3 represents the tone control at 0 so the difference between the two lines can be seen as the response of the tone stack as its controls are adjusted from 0 to 10 (minimum to maximum).  There is a huge boost of around 30dB in the low frequency spectrum and an average of around a 15dB boost in the mid and high range frequency spectrums.  More detailed designs of the tone stack can now be completed based on these findings.  


Rode NT5 frequency plot

Celestion Tube 10 frequency plot

Laney Cub 10 tonestack plot with white noise
The spectrum tool used is a great freeware plug-in from blue cat audio and can be downloaded from: http://www.bluecataudio.com/Products/Product_FreqAnalyst/

Commercial constraints

It has come to my attention during my initial specification that the research I am completing may well have some commercial relevance and hence I am going to have to restrict the information I post on the blog.  I will however update with progress and provide the final plug-in however I will be unable to provide code or specific details on the code.