Pages

spectrum analyser

Spectrum analyzers are used to output the frequency content of an arbitrary input signal. It was our opinion that such a system could be implemented on a microcontroller, almost fully in software.  Doing this, however, necessitated some knowledge of standard Digital Signal Processing techniques, namely sampling, analog-to-digital conversion and most importantly constructing digital filters. We believed that a spectrum analyzer could be fully described by providing and/or implementing three main components: sampling & A/D conversionfiltering and output.
    Hardware was essential to our project.  The ATMEL AT90S8535 provided a sampling and Analog-to-Digital module which greatly facilated the capturing of analog signal for subsequent processing.   Of course, using this particular microcontroller put constraints on the capacity and capability of our spectrum analyzer. Due to these constraints, we had to design the analyzer within the appropriate limits.   The main constraints imposed by the microcontroller were the maximum sampling frequency (of approximately 9 kHz), RAM and Program Memory.   All three factors contributed to limiting the bandwidth, performance and resolution of the analyzer.
    In essence, we believed that a spectrum analyzer could be realized through chaining a series of bandpass filters, through which an input signal would traverse during the filtering process.  Hence, the major portion of this project involved coding up and testing the various filters that later become the 'frequency points of interest' of our analyzer.  We tried several filter design techniques to  implement a reliable bandpass filter, i.e. a filter with a relatively short passband and sharp roll-off.   The two main classes of filters we explored were IIR and FIR filters (please see section entitled 'Filter Concepts' for futher detail).   However, progressively filtering an input signal was insufficient to establish the presence of a particular frequency (or range of frequencies).  Therefore, we had to include some thresholding on the final filtered output to determine the presence of a specific frequency.
    Nevertheless, we managed to implement a spectrum analyzer that can process and output the frequencies present in an input signal, with reasonable accuracy. Further issues regarding the consequences of hardware constraints, FIR bandpass filter effects and thresholding will be discussed in subsequent sections. 



Central to the spectrum analyzer are the various bandpass filters at the different critical frequencies which process samples of input signals. Assuming a A/D module (which, in our case, was supplied by the AT90S8535 microcontroller), we basically had to implement the various filters for signal processing. 
 

Infinite Impulse Response Filters

    Essentially, we constructed the filters from the following, generic transfer function: 
 

Note that the above transfer function implements an Infinite Impulse Response filter. Basically, an IIR filter takes as inputs previous outputs as well as current and previous inputs to produce the current, filtered output. Hence, a feedback loop is present. The above transfer function transforms, in the time domain, to a difference equation. The 'a's and 'b's in the above transfer function translate to the coefficients of the various terms in the difference equation. As we can see from the above, H(z) gives an expression for an n-th order filter.
    Values for and b above can be determined from computing the poles of the above transfer function.
p0 and p1 are the poles of this 2nd order band-pass filter while the z's represent the zeroes. '*' denotes complex conjugation. Hence, a two pole filter with nonzero a coefficient values and 3 b values  can be formed by expanding the denominator and numerator respectively of the above equation. The poles p are of the form
where A is the magnitude and theta is the angle made by the whole in the unit circle z = 1 in the complex plane. Poles p were calculated based on the following relationship:

where fs is the sampling frequency of the system - 9 kHz in our case. fc is the desired critical frequency. 
 

Finite Impulse Response (FIR) Filters

    FIR filters were the most prevalent aspect of our design. Basically, FIR transfer functions derive from impulse responses that are finite in duration. FIR filters exhibit several properties, namely: 
 
  •  The phase response can be made linear, i.e. FIR filters exhibit Generalized Linear Phase whereas IIR filters do not. Linear phase provides less phase distortion (and is thus more manageable) than non-linear phase.
  • The impulse response exhibits symmetry about the midpoint, thus simplifying computation requirements.


The transfer function of an FIR filter transforms, in the time domain, to a difference equation that depends only on the current and previous input values. Hence, feedback is not present in the construction of FIR filters. This further simplifies computation. Essentially, the FIR filter transfer function gives rise to the following:

where the b values are the respective coefficients in front of n (thus, an n-th order FIR filter) input samples.
FIR filters also have the property that they are not prone to instability, i.e. due to the finite-length impulse responses, the poles of the transfer function H(z) are guaranteed to be at 0 within the unit circle in the complex plane. Hence, stability of the filter is guaranteed. Stability is not always guaranteed in IIR filters, and this was most clearly noted when several filtered output values  'blew up'.
The figure below illustrates the magnitude and phase responses of Finite Impulse Response filters:

Note the linear phase response in the lower plot. 
 

Actual Implementation

Initially, we designed and implemented (in software) a 2-pole Infinite Impulse Response bandpass filter (with a critical frequency at 400 Hz). As described in the 'Results' section, we observed a very flat pass-band and large transition region, i.e. the roll-off was not sharp enough. We designed this filter using the equations stated in the above section entitled 'Infinite Impulse Response Filters'. To further support our design, we tried constructing a 2-pole Butterworth bandpass filter from MATLAB

We noticed further that Butterworth filters are characterized by a magnitude response that is maximally flat in the passband and monotonic overall. 
Butterworth filters sacrifice rolloff steepness for monotonicity in the pass- and stopbands. Unless the smoothness of the Butterworth filter is needed, an elliptic or Chebyshev filter can generally provide steeper rolloff characteristics with a lower filter order.

Furthermore, due to the feedback loop present in implementing IIR filters, we decided that Finite Impulse Response filters would better suit our purposes. This belief was strengthened by the idea that FIR filters are not succeptible to instability.
After making the signal processing system to non-realtime, we decided to construct a 100-length FIR filter. This was done with aid of MATLAB. We noticed that MATLAB designs an FIR filter using the window method. The window method begins with an ideal lowpass filter, whose impulse response is of infinite duration, and truncates it, producing a finite impulse response.



   Most of the filter design is done in software because of the extensive computations.   However, since we are getting inputs directly from a waveform generator to the AT90S8535 microcontroller, we added 2 circuits to protect the chip and to avoid aliasing. 
 

Hardware List for Basic Spectrum Analyzer with RS232 link

  • Atmel AT90S8535 microcontroller:  4 MHz clock, 512 bytes SRAM, 2k by 8 Flash memory, UART and 10 bit A/D converter.
  • STK 200 microcontroller development board.
  • Null modem cable to PC COM port.
  • LM 741 operational amplifier for two pole low pass filter circuitCircuit schematic.
  • Diode clipper circuit to limit input voltage into the A/D converter input.   Circuit schematic.

 

Testing Equipment

  • Waveform generator that produces sine, square and triangular waveforms.  The voltage range of the A/D converter is 0 to VDD, hence we used waveforms that have DC offset = 2V and amplitudes = 1.50V.   We set AREF  = 4.096V so as to represent 4mV per bit.

Circuits

  •     Two pole op-amp low pass filter.


    This filter has cut off frequency of 3333.33Hz.    Two poles are used instead of a single RC circuit to get flatter frequency response at lower frequencies.  To achieve a gain of 1, we connected the inverting input of the op-amp to the output.   With a constant sampling frequency of 9 kHz, the maximum input frequency has to be 1/2 of 9kHz (from Nyquist Rate).   For our purposes, the cut-off at 3.33kHz is sufficient to keep the higher harmonics of non-sine waves from aliasing.  In addition, our target frequency range of 200 - 1600 Hz is sufficiently smaller than the cut-off, so that they lie under the flattest region of the curve, with the biggest possible gain of approximately 1.0. 
 

Bode Plot Sketch for the Low Pass Filter

 
  
  
 

  •     Twin diode voltage regulator circuit


    The Atmel Microcontroller has a 10 bit Analog-to-Digital Converter (ADC).   In order to prevent unnecessarily large voltages or currents (e.g. from the -12V, +12V DC power source) from damaging the chip, we regulated the voltage from the output of the op-amp before it reaches channel A0 of the ADC.  When voltages exceed VDD (5V) or become negative, the diodes will be activated and draw all current to VDD or GND respectively. 
  




 In essence, the software portion of this project consists of implementing the chain of bandpass filters, that constitute the core of our spectrum analyzer. 
Initially, we intended to have the spectrum analyzer operate in real-time, i.e. process a sample of input through the filters before the next sampled input arrives. However, we encountered two important issues with the hardware used, which eliminated the possibility of real-time signal processing:

  • The AT90S8535 A/D Converter can only operate at a maximum frequency of 4 Mhz/32, i.e. at the chip clock frequency prescaled by 32.
  • Sampling (in the Free Run Mode) takes roughly 14 clock cycles
In effect, these two constraints resulted in a maximum usable sampling frequency of approximately 9000 Hz, or about one sample every 0.11 ms. This time interval proved insufficient for chaining several bandpass filters together, as the neccesary computation overhead incurred by the filters would exceed the alloted 0.11 ms. Because of this, we opted for an offline processing of input signals. The general outline of the program is as follows:
  1. 1. Sample input signal, sampling frequency = 9 kHz.
  2. 2. Take about 250 samples and store them in RAM (the number of samples depends on available memory space).
  3. 3. Call subroutine DiffEq on the samples to compute the filter output.
  4. 4. Determine if filtered output amplitude is above treshold. Repeat for all 250 samples. Store number of outputs (counts) above threshold.
  5. 5. Loop at #3 and #4 until all samples have been processed by all filters.
  6. 6. Compare stored count values to a predefined number. If count is greater than number, then frequency is present in original signal.
  7. 7. Output results.


    The subroutine DiffEq (short for Difference Equation) basically implements the difference equation described in the 'Filter Concepts' section. The coefficients required by the difference equation is supplied by an include file, "Coeffs. asm."   This contains 101 coefficients each for the 8 FIR bandpass filters constituting the spectrum analyser.  The filter frequencies are centered at: 200Hz, 400Hz, 600Hz, 800Hz, 1000Hz, 1200Hz, 1400Hz and 1600Hz.   These coefficients were obtained from MATLAB, and hard-coded into program memory.


    Finally, thresholding was implemented, to establishe a basis for determining the relative strengths of the selected frequencies in a signal.  This became more essential later in our project when we observed that cascading bandpass filters produced regions of 'filter overlap.'  The overlaps in the frequency responses  produce frequencies of intermediate strength not really present in the original input signal (please see section entitled 'Results').   In our design, we decided to set all the threshold levels as equal, somewhere around 20% of the full swing voltage.  This low threshold value provides the resolution needed at all frequency points of interest. 
 

State Transition Diagram

 







 The initial phase of our design which was the design and implementation of a single Infinite Impulse Response (IIR) filter yielded results which can be best summarized by the following plots:

 
The figure above describes a 2nd-order Butterworth filter with critical frequency of 400Hz. This constituted the initial phase of our spectrum analyzer design. Note the extreme flatness and attenuation of the magnitude of the frequency response. This corresponded with our observations, in that we had to reduce threshold levels significantly before even observing any output. In addition, the amplitudes of the filtered outputs were very low, specifically, less than 0.3V. Also, we believe the non-linearity present in the phase response contributed to the overall distortion of the filtered output, yielding no definite transition boundaries. In short, we could not get clean filtered output at 400Hz.
Due to the above, we decided to switch emphasis to Finite Impulse Response (see 'Filter Concepts') filters.
In comparison to the above 2-pole IIR filter (Butterworth), we present a 2-pole FIR filter. Notice the sharper roll-off, less attenuation and linear phase. These three factors, amplified by increasing the order of the filter (in our case, 100), contributed to our decision to use FIR filters:

 

In addition, we observed the  frequency response of a 100th-order FIR filter. This is shown below:

We noticed an actual 'bump' at around 400Hz (0.09 in the above magnitude plot) and linear phase around the very same region. Hence, we implemented bandpass filters at 200Hz, 600Hz, 800Hz, 1000Hz, 1200Hz, 1400Hz and 1600Hz in addition. This essentially constituted our spectrum analyzer. 
 

Real Results of our Spectrum Analyzer

    We performed a frequency sweep of the spectrum analyzer and obtained the following results. Frequency Sweep Results
Note the overlapping of the various bandpass filters (denoted by the different colored lines). This overlapping was the result of a non-log spacing between adjacent filter critical frequencies. As we see in the theoretical plot described in Filter Transfer Functionsthe measured data matched predicted responses rather well. The theoretical plot describes the overlapping between different passbands. Hence, as we sweep through intermediate frequencies, the spectrum analyzer does not register a strong affirmation for the presence of that frequency in the original signal.
    Next, we also tested the analyzer with a square wave input and obtained the following Square Waves result. Square waves contain odd harmonics in its Fourier Series expansion. Apart from the initial frequencies, we observed a decrease in amplitude of higher harmonic frequencies present in the input square wave as we performed a sweep. A telling example would be the response of the analyzer to a square wave with a fundamental frequency of 200Hz. In this case, three upper harmonics were visible, and all three displayed monotonic decreasing amplitudes.
    Finally, we also performed a same frequency sweep but using a triangle wave as an input. The results are here: Triangle Waves


Much emphasis has been placed in fine-tuning the filters and figuring out meaningful observations from the raw y[n] data.   If given more time and resources, we would really like to add the following to our project: 
  
 

Filter Design

  • Variable thresholding for each filter for more resolution.  To be able to extract all the frequencies within 200-1600Hz that are contained in square waves and triangle waves, the thresholding has to reflect the different  fourier series coefficients.
  • Expand on the target frequency range beyond 200-1600Hz.  Use EEPROM and other sources of memory.
  • Experiment with bigger filter lengths (>100 coefficients).  This will narrow the pass-band and make filters sharper, reduce filter overlap.
  • Digital-to-Analog-Converter to convert y[n] output into analog waveforms.

Display

  • A stand-alone display, such as LCD.  So that our spectrum analyzer can be a unit by itself.  The LCD will display yes/no answers to whether a signal contains a specific frequency.
  • A program in high-level language to automatically generate spectrum plots, obtaining data from the RS232 serial port.
 In conclusion, our project performed as expected. We learned a lot of Digital Signal Processing techniques from this project. Although certain facets of our design did not display results at the level of accuracy we expected, we subsequently deduced the cause of most major discrepancies in the observed data. Hardware and equipment constraints (not to mention time!!) further limited the scope of this implementation.
    We would like to thank Prof. Bruce Land for his advice, patience and willingness to help. Also, we would also like to thank Jing Deng for his assistance and support.  A special thanks to Prof. Bernie Hutchins for his input on filter design. 

0 comments:

Post a Comment

Share your knowledge

Related Posts Plugin for WordPress, Blogger...

Popular Projects

program for Dual DAC 8051 Microcontroller Based DC Motor Control A Microcontroller Based Turbidity Meter A m -Controller Based Thermostat ASCII to BCD conversion in 8051 AT90LS8515 Digital Message Machine Audio Frequency Response Analyzer Audio Homing Robot Automated Juice Mixer Automated Pet Feeder Autonomous Car Autonomous Parallel Parking RC Car Autonomous Search Robot Autonomous Tank Autonomous Vehicle Contrast Following Rover Autonomous navigating robot BCD number to ASCII in 8051 Balance Bot Blind Bot Blood Pressure Monitor Bloodshed Dev-C++ 5 Compiler/IDE Breath Alcohol Tester Converters on TI MSP430 CrossStudio MSP430 IDE Design of a Real-Time Digital Guitar Tuner Digital Oscilloscope Digital Stethoscope Digital clock project using PIC16C54A microcontroller Digital thermometer ECG monitoring system GPS Data Logger with Wireless Trigger Handwriting Recognition Systm Home Security System Home energy managment IAR Embedded Workbench IDE INFRARED TRACKING SYSTEM IntelliBOT Laser Communications System Line following van MSP-EXP430FG4618 Development Tool and the eZ430 kits MSP430FG4618 device implement a Buzzer tone generator MSP430FG4618 device implement a Real Time Clock MSP430FG4618 device implement a voltage ramp generator MSP430FG4618 device present a message on the LCD Basic Microcontroller(8051) Lab Mivo- RFID based mobile payment system Multi-Zone Fire Alarm System PC based temperature control PIC 16f877 RPM Meter PIC16C54 dual dice electronic project circuit PIC16F84A digital thermometer microcontroller project PIC16F886 horn driver PWM motor contoller with MSP430 Program Block data transfer in 8051 Program to add two BCD numbers in 8051 Program to check whether a 4th bit of a byte is 1 Program to convert ASCII to hex in 8051 Program to count from 0-9 in 8051 Program to count number of 1's in a given data byte in 8051 Program to divide an 8 bit no by another 8 bit number in 8051 Program to find largest of n numbers in 8051 Program to find the LCM of two numbers in 8051 Program to find the square of an 8 bit number in 8051 Program to generate 50msec delay in 8051 Program to implement BCD counter to count from 0-99 in 8051 Program to implement BCD counter to count from 99-0 in 8051 Program to interchange two blocks of data in 8051 Program to multiply 16 bit number by 8 bit number in 8051 Program to search an element in an array in 8051 Program to sort an array of 10 elements in 8051 Programming the ez430 Proximity Security System RAMP wave in 8051 RC Car Controller RObo Dog Radio-controlled Truck Retina color tracker Robotic Arm Controller with GUI Robotic Car Traction Control Safety-sensor vehicle Security Entrance System Self-Powered Solar Data Logger Snake Arm Ultrasonic Positioning Control System Store FFh if 1 Super Train Controller TI MSP430 Microcontrollers Timers on the MSP430 TouchPad Drawing Board Ultra-Sonic Parking Assistant Ultrasonic Parking Controller Ultrasonic Range finder Voice Activated Alarm Clock Voice Recognition Robotic Car Voting Machine Weather Station Web-Monitored Thermostat Wireless Drawing Device Wireless Telemetry Wireless message Communicator Write a C program to display the code of the key pressed in 8051 Zigbee Wireless Relay Control and Power Monitoring System add two multibyte numbers in 8051 convert a decimal number to hex number in 8051 convert an 8bit Hex number to decimal number in 8051 convert hex number to ASCII number in 8051 eZ430-F2013 Development Tool use SD16_A ADC eZ430-RF2500 Development Tool use ADC10 else store 00 in the same location in 8051 find the GCF of two numbers in 8051 find the average of 10 numbers in 8051 generate Fibonacci series in 8051 metal detector project microcontroller using IAR Embedded Workbench program for Elevator Interface in 8051 program for Stepper motor interface in 8051 spectrum analyser square wave in 8051 triangle wave in 8051 voice recognition security system

Sites U missed

Hint

Open Pictures in new page by right click on it, if it is not shown full image.