Frequency Response Analyzer

by nostromo-1 in Circuits > Arduino

1944 Views, 5 Favorites, 0 Comments

Frequency Response Analyzer

IMG_20210402_173801000.jpg
IMG_20210402_174119017 (2).jpg

Do you want to test the frequency response of an audio amplifier? Do you want to try a bass booster in your amplifier? This project proposes to build a means to measure and graphically show the frequency response of an audio amplifier.

It uses an Arduino as a microcontroller, which commands a DDS (Direct digital synthesis) board used to generate the input sine waves of different frequencies for the amplifier. The output of the amplifier is connected to a peak detector. The arduino sketch allows you to visualize the input of the peak detector (a small simple oscilloscope) in order to ensure that no clipping occurs. The output of the peak detector is measured by the Arduino, which can then display the evolution of the peak level with frequency.

The Arduino Controller Board

frequency response_bb.png

You will need an Arduino board (I use an Arduino nano). I propose to mount it on a breadboard, as this gives you flexibility to add and remove components for other Arduino projects.

As a means to communicate with the outside world, it needs a rotary encoder and a push button (some rotary encoders include a push button). It also needs a display, I use the SSD1306 (128x64), a 0.96" OLED display controlled via I2C.

I power the Arduino with the USB, which allows me to both power and program the board. Some SSD1306 displays need 3.3V as power supply, whereas others are specified up to 5V, as they have an on-board regulator. If yours does not accept 5V, you will need a level shifter (as is my case).

So the parts are:

  • Arduino nano. This model fits nicely into a breadboard.
  • A rotary encoder. This element is used as input to the Arduino. Unlike a potentiometer, it has no end stops. It generates a pulse that can be read from the Arduino each time you rotate it. I use an Alps encoder, with 24 pulses. It is connected to ground (pin in the middle) and to the Arduino (the other 2 pins, connected to pins D2 and D4 on the Arduino). The pins connected to the Arduino do not have a pull-up resistor, I use the internal Arduino pull-up resistor. These pins need a 100 nF capacitor, useful to avoid bouncing.
  • A push button. Some rotary encoders have a pushable shaft, so you can use it. It is connected to ground on one side and to pin D5 of the Arduino on the other side, It also needs a 100 nF capacitor at this pin.
  • A 128x64 SSD1306 display with I2C interface. It has 4 pins: VCC, GND, SCL and SDA. Some also have a reset pin. Be careful with the input voltage range. If it allows for 5V VCC input, perfect: connect it directly to the 5V of the Arduino. Otherwise, you have to connect it to the 3.3V pin of the Arduino, and use a level shifter for SCL and SDA.
  • A level shifter. Needed only if the SSD1306 does not accept 5V as VCC. I use a 4 channel one (though I only need 2 for this application). You connect its HV pin to 5V, the LV pin to 3.3V (of the Arduino), GND to ground, and then 2 pins to SCL and SDA on one side and to pins A5 and A4 of the Arduino respectively on the other side. These pins are the hardware I2C bus of the Arduino nano.

The Direct Digital Synthesis Board

AD9834.jpg

A Direct digital synthesis (DDS) is a method employed to generate a sinusoidal wave (or any other wave). The one employed in this project is the AD9834, in a board like the one in the picture above, which offers 2 sine wave outputs (OUT+ and OUT-) and a square wave output (Squ).

It can be programmed with the SPI interface from the Arduino. Its connections are:

  • VCC: Connected to the 5V pin of Arduino
  • GD: Connected to the GND pin of Arduino
  • FSY: Connected to pin D9 in Arduino. This is the Slave Select (SS) pin of the SPI bus.
  • CLK: Connected to pin D13 in Arduino. This is the clock (SCK) pin of the SPI bus.
  • SDA: Connected to pin D11 in Arduino. This is the output (MOSI) pin of the SPI bus.
  • OUT+: to the input of the audio amplifier. I soldered two cables from the SMA connector and connected them to the amplifier. This is OK for audio frequencies.

The SSD I use (see picture above) has a 75 MHz oscillator, which means it can generate sinusoidal signals up to about 25-30 MHz with very small distortion (the absolute limit is 37.5 MHz, the Nyquist frequency). Its resolution is 0.28 Hz. Perfect for our purposes.

The Audio Amplifier

LM386.jpg

This will be out DUT (Device Under Test). The input signal comes from the DDS board. Its output is connected to the input of the peak detector. I soldered two wires to the loudspeaker, which are then my amplifier output.

You can use any amplifier. I use a LM386 board which I built for listening to audio signals in my projects. You can use any amplifier you have, there are many instructables about amplifiers (like this one, based on LM386). It is better if the amplifier has a volume potentiometer, because we want to make sure that the output is a clean sine wave with no clipping (which occurs if the output volume is too high).

In my amplifier, I have a low-pass RC filter at the input (a 1200 ohm resistor and a 15 nF capacitor), in order to limit the noise at higher frequencies. This also allows me to see a nice frequency response curve, instead of a boring horizontal line if the amplifier is too good....

The Peak Detector

peak detector2_bb.png
peak schema.png

The output of the amplifier (ie, the loudspeaker) is connected to the input of the peak detector (signal and ground). This circuit creates an output voltage (the green wire, connected to pin A0 in Arduino) which corresponds to the peak voltage of the sinusoid at the input. The yellow wire (connected to pin A1 in Arduino) is the signal that is fed into the peak detector, which is used by Arduino to check that the input signal is not clipped, in a small oscilloscope, at the start of the sketch.

The parts used are:

  • An operational amplifier. It can be a LM324, LM358, or any other with single supply capability (ie, its common mode input must range to ground, and the output must reach down to ground level). I use the TLC272. There is no specific demand on slew rate, as the circuit does not place the opamp into slew rate limitations.
  • 4 schottky diodes, like BAT54 or BAT85
  • Capacitors: 100 nF, 1 uF
  • Resistors: 2M, 390k, 220k, 100k, 100, 39 ohm
  • A trimmer or potentiometer, 1k ohm

Using the Sketch

IMG_20210402_174119017 (2).jpg
IMG_20210402_174149319 (2).jpg
IMG_20210402_174005963 (2).jpg
IMG_20210402_174037976 (2).jpg

OK, so now all elements are connected. Arduino controls the DDS module, which outputs a signal fed into the amplifier. The output of the amplifier is connected to the input of the peak detector. The two signals from the peak detector are connected to Arduino.

You can download the sketch from github. It needs a AD9834 library and another one for the SSD1306 display. I use the u8g2 library, as it is very configurable and demands a low amount of RAM memory.

Now, you can switch power on. When the Arduino is powering up, press the push button and maintain it pressed. The sketch enters into SINGLE output mode, where it generates a single tone, which you should hear from the loudspeaker of the amplifier.

You can change the frequency by rotating the rotary encoder. It changes by 500 Hz each detent; if you press the push button when rotating, it changes by 50 Hz each detent.

So everything seems to be working fine. Yu can now press reset on the Arduino, and start the sketch again, this time do not press the push button for SINGLE mode.

You should get into the oscilloscope mode. The DDS generates a 1 KHz tone and Arduino displays the signal fed from the amplifier into the peak detector. You can use the volume control of the amplifier and/or the potentiometer of the peak detector to get a clean signal, with no clipping: a good sine wave. The vertical scale is 0.5 V each mark.

When you are happy, press the push button. The sketch enters SWEEP mode, and it generates a sweep from 60 Hz to 20 KHz, and samples the output of the peak detector for each frequency. It then displays a graph with the frequency response of the amplifier, and a -3 dB line for reference. The horizontal scale is 1 KHz each mark. Note that the scale is linear, not logarithmic.