Work Portfolio

Job #1: Real-Time Implementation in Digital Signal Processing

Digital Signal Processing


Digital Signal Processors are a source of introducing excellence to the computing work and fulfill the needs of today’s digital world. The digital technology has brought enhancements to differing applications extending from sensors to servers. The vital part that digital technology has been playing in signal processing is commendable, and virtually the effect of digital technology has been somewhat exciting, and the evidence is that it will be considerably more so later. One of the essential focal points to digital rather than analog signal processing systems is the enormous adaptability that digital signal processing offers and due to this adaptability, digital signal processing strategies have discovered applications in a substantial or wide assortment of zones.

Implementation of Digital Signal Processing in the Real World

There are countless examples of the implementation of digital signal processing in real life and practical processes. Digital signal processing has provided infinite opportunities to simplify some rather complex methodologies. The fundamental difference between microcontrollers and digital signal processors is that microcontrollers are specially designed and optimized to control, time and supervise tasks while DSPs are designed to perform real-time signal processing tasks. DSPs are utilized in coding/decoding of speech, audio/video signal processing, compression/decompression, encryption/decryption, mixing audio and video and sound synthesis.

The performance measurement for any processor can be done using the calculation for the time required to perform a specific set of instructions, more commonly known as computation time which may be calculated using the processor clock period, several clock cycles to complete the instructions and the number of directions.

Traditional DSP applications work with practical examples, for instance, sound and radio waves that instigate in analog form. In sound recording and processing, it gives a chance to some exceptionally complex processing and development. Case in point, a DSP can channel the clamor from a signal, evacuate undesirable interference, intensify various frequencies while dimming others, encode data, or examine an inconceivable wave structure into its spectral segments. In plainer dialect, DSPs can clean the crackle and murmur from music recordings.


Pretty much every microcontroller accompanies one or sometimes more implicit clock(s)/counter(s), and these are to a significant degree valuable to the embedded. The term clock/counter itself signifies the way that the essential counter equipment can typically be arranged to check either customary clock pulses (timer) or occasional irregular pulses (counter). A counter turns into a clock when the approaching pulses are at an unchanging and known frequency.

Importance of a Timer in the Microcontroller

Timers and counters are significant to the point that you will discover numerous cases in which they are used and play a vital role in the operation of the microcontroller. Examples are controlling the brightness of Light Emitting Diodes, getting sensor information which is transmitted in PWM (Pulse Width Modulation), controlling the servo shafts, making a clock, or just basically adding a period variable to your microcontroller activity.

Timers are the heart of any real-time digital signal processing application which requires a constant evaluation of the code and subsequent implementation. Timers are helpful in executing a specific set of instructions after a particular interrupt. These are the invaluable contributions that a timer makes to the digital signal processing applications which make them indispensable. Real-time examples include but are not limited to active noise cancellation techniques rendering the output to be utterly desirable.

Timers may be used to perform exceedingly significant roles. Sometimes, timers are used to generate waveforms utilizing a lookup table. Each time the timer runs out, it resets and updates the pointer to the wavetable buffer, which in turn locates the new value and updates it in the output. This way, timers are used for signal generation and many other things.

Timers are exceptionally adaptable, having the capacity to gauge time periods, to focus pulse width, to quantify pace, to quantify recurrence, or to give yield signals. Sample applications may incorporate measuring the rpm of an automobiles motor, timing a precise period, for example, to time the velocity of a shot, creating tones to make music or to drive the spark ignition arrangement of an internal combustion engine.

Timers vs. Delay Functions

In real time applications of digital signal processing, there are some instances where the use of timers with microcontrollers is preferred over the use of delay functions. Timers, in some cases, may be the best suitable method to introduce delays or interrupts.

Take for example an ARM CPU that is used for an operating system. Now, if the execution on the entire chip is blocked to achieve the time delay functionality, the chip would be wholly occupied for the duration of the delay, resulting in an entirely useless phenomenon for a user-interactive system. Timers are useful in such situations and prevent such occurrences.

Timers are helpful because they dodge the blocking circumstance. The CPU kept executing code and bounced back to a handler routine once the timer exceeds the maximum value. When the maximum value is exceeded, an asynchronous operation that considers a great deal more adaptable code occurs.

For another example, consider a Light Emitting Diode which is programmed to blink at a fixed interval and display the time interval on a specific display device. Using delay functions, in this case, will make the microcontroller to wait for one delay to finish. For instance, if seconds are increased, it takes one cycle, but it needs to be checked that when the number of seconds increases from that of a minute (i.e., 59), the seconds need to be zeroed again and increase the minutes. Increasing the minutes will add to the tasks of the microcontroller that it performs every minute. However, if a timer is used to count the pulses of the clock, the timer automatically monitors the seconds and the minutes and displays the correct time interval; hence, the microcontroller is free to perform another function at the same time while the timer is counting the number of seconds and minutes. Therefore, it is better to use timers.

Pulse Width Modulation

Pulse Width Modulation (PWM) is a procedure for getting analog results with digital signals. Digital control is u to make a square wave, and a sign exchanged in the middle of on and off. This on-off example can reproduce voltages in the middle of on and off by changing the segment of the time the signal invests on versus the energy that the signal spends off. The period of "on time" is known as the pulse width.

There indeed are a few solid explanations for the interest in using PWM signals and there are a few applications where a few of these reasons meet up. Some of those reasons are mentioned below.

    Several circuits can "average" an on-off signal to control their operation. It is clear-cut to focus the needed duty cycle accomplishing a preferred mean value from a signal with predetermined high and low magnitudes. Cases incorporate LEDs and inductive loads, for example, engines and solenoids.

    Circuits with switches tend to have lower power consumption because these devices are quite often off (low current means low power). Standard circuits that use this highlight incorporate switch mode power supplies, speakers, and engine drivers. As often as possible, these circuits use semi-analog techniques (ramps and comparators) rather than digital techniques, yet the benefits are still there.

    PWM signals are trouble-free to produce. Numerous advanced microcontrollers incorporate PWM equipment inside of the chip; utilizing this equipment frequently takes next to no consideration from the microchip, and it can keep running out of sight without meddling with executing code. On the other hand, PWM signals are simple to generate from code, regularly obliging just counting and comparing operations.

    PWM can work successfully, as a digital to analog converter, especially joined with suitable filtering. The way that the duty cycle of a PWM signal can be precisely controlled by basic counting techniques is one of the reasons why PWM signals can be utilized to achieve digital to analog transformation.

Simple Digital to Analog Converter using Filtered PWM Signal by RC Circuit

The primary reason for a PWM signal to be filtered is the modulation from the combined signal. The decision of the type of filter to be used, for the most part, does not depend that much, on the sort of circuit or chip used to produce the source signal. Subsequently, it does not rely on upon whether the source is a DSP, a CPLD, an ARM processor, a Freescale processor, an Atmel processor, a Microchip processor, or even discrete logic.

The selection of the analog low pass filter is one of the most critical decisions that need to be taken to utilize the PWM signal as a digital to analog converter. When considering filter performance, active filters are most often thought of, which are built with op-amps, as compared to passive filters which are composed exclusively of inductors, capacitors, and resistors. The impedance loading problems that passive filters face, where filter properties may be altered due to the up or downstream impedances; may be prevented by using active filters.

One of the fundamentals on which the selection of the filter is based on is the step response. Every filter has a step response; however, the step response of one filter may differ from that of the other. The other significant property that needs to be monitored when the selection of filters is concerned is the pulse response of those filters.

The response of Filters to PWM Signal

Practical observations have led to specific results which are identical each time that the practical is performed. These are:

    If the provided PWM frequency is high enough, and the filter is given adequate time to settle, the filter output will be very close to the average of the PWM signal.

    The filter output will be the same as if the filter was being driven by a simple step having an amplitude equal to the PWM average, provided that the ripple is ignored.

    If the duty cycle is changed suddenly, the filter output will remain the same with the initial level equal to the PWM initial average and the final level equal to the final PWM average.

    Generally, it could be said that the PWM filter will treat PWM modulation in the same way as if the modulation was being applied directly to the filter.

    If the PWM frequency is high enough that the peak-peak ripples are less than the peak-peak amplitude of the PWM input signal, then the only thing that is affected by the PWM frequency is the ripple frequency and ripple amplitude.

    Ripple amplitude is highest when the duty cycle is 50%. Ripple amplitude is zero at duty cycles of 0 & 1. Ripple amplitude varies smoothly between these values and the value at 50% duty cycle without any peaks or dips.

    The maximum ripple amplitude, if the PWM frequency is high enough that the ripple is essentially triangular, is given by V ≃S * A * π/ 2, where S is the peak-peak amplitude of

the PWM signal and A is the attenuation (actually "gain") of the filter at the PWM fundamental frequency. If the filter roll-off occurs at high frequencies, it is steeper, and then the amplitude could be closer to

V ≃S * A * π/ 2

Where V = Peak – peak ripple amplitude

    S = Peak – peak amplitude of PWM signal

    A = Filter attenuation at fundamental PWM frequency

However, if a filter with a much higher filter attenuation is used, the relation becomes,

V = S * A * 4/π

Selection of the Filter

After knowing all the rules of thumb, it is possible to get close to the best possible filter and make the decision to pick up the most useful filter. There are a few factors that need to be kept in mind when going for the selection of the appropriate filter.

First of them is the PWM repetition frequency which is a slightly easier one to pick. Second, the modulation frequency is also required and should be within the appropriate range depending on the application. The third is the maximum ripple amplitude. The lower the ripple amplitude, the favorable it is. The final specification, i.e., the Passband Flatness is not as easy to pick as the other three, but it also needs to be determined based on the application.

A graph may be constructed to further help in the procedure of picking up a suitable filter. Draw a rectangular graph with frequency on the x-axis and decibels (dB) on the y-axis. Mark the PWM frequency on the graph. Figure out the required attenuation using the seventh rule of thumb. Next, mark the output signal response. Check and evaluate first order filter fit.

Waveform Lookup Table

Wavetable music synthesis is as a straightforward digital sine wave synthesis; however, there are a couple of notions that need to be considered. In the first place, the waveform lookup table contains tests for not merely a single period of a sine function, but also for a single period of a more generic waveform. Second, a component exists for alterably changing the waveform as the musical note advances, hence producing a quasi-periodic function in time.

Creating a Sine Wave using a Lookup Table

This section will discuss the generation of a sine wave signal by changing the duty cycle of PWM in sinusoidal fashion utilizing a lookup table. An example to the waveform lookup table particularized to the sine wave (however, this method is not limited to generating sine waves and could be used to generate square waves and even other waveforms) which is a standout amongst the most principal and mainstream routines for sine wave generation. In this system, the qualities used to calculate a sine wave are stored in memory. There are three possibilities in the look-up table technique. The primary technique includes the combination of sine waves with frequencies which are products of the basic repetition for which the table components are figured. The second system consists of the union of sine waves with frequencies which are fragmentary products of the principal repetition for which the table components are computed. In the third method, the synthesis can be completed for sine waves of non-integer multiples.

Particularizing this method to the theme of the idea being discussed indicates that the lookup table could be used to provide unique values. PWM signal is generated, and each interrupt is set to, for example, changing the duty cycle by going to the next value of the table each time. So, if a 256-value lookup table is being used, each time the PWM changes to the next value of the table, thereby propagating towards the end of the table. The output is then filtered using an RC circuit, and a simple digital to analog converter may be prepared in this manner.

Direct Digital Frequency Synthesizer

The direct digital frequency synthesizer is the device that works on the principle of Direct Digital Synthesis (DDS). It is a method used to produce a frequency and phase tunable output signal regarding a fixed precision clock source utilizing digital data processing blocks. Signal generators that use digital synthesizers create signals at exact frequencies through special memory access and timing module, which contrasts from the conventional technique for yielding every specimen in the array of which the waveform is saved. Digital Synthesizers give the wave generator the capacity to pick which form to produce from memory.

Benefits of DDS

DDS technology offers total digital power to alter the tuning resolution of the output frequency in Microhertz. It also gives the ability for very fast hopping speed while tuning the output frequency. This digital infrastructure offers analog synthesizer solutions to eradicate the necessity of manual system tweaking and tuning. It provides the ability to remotely control the systems within processor control with the digital interface. It offers unrivaled matching and control of I and Q synthesizers when utilized as a quadrature synthesizer.


Numerically Controlled Oscillators (NCOs) are used to store samples of a sine wave in a lookup table and produce them at the desired frequency. The direct digital synthesizer (DDS) utilizes a clock, an address counter, a memory (usually a PROM), a digital to analog converter and sometimes a low pass filter. The PROM functions as the sine lookup table. The address counter accesses the memory locations of the PROM and provides the contents to the DAC, which generates an analog sine wave. The frequency of the output is dependent upon the frequency of the clock and the step size of the sine wave. Subsequently, a phase accumulator is introduced into this architecture which renders it into a Numerically Controlled Oscillator (NCO).


The accumulator helps in going through the addresses of the lookup table more swiftly with a larger step size, which in turn produces a sine wave of a higher frequency. The accumulator also consists of a fractional part, which allows for greater frequency control. A number of fractional bits in the accumulator should be selected depending on the maximum acceptable frequency error as the frequency may suffer from a large error due to the step size. While addressing the lookup table, only the whole accumulator output is utilized and not the fractional bits resulting in the truncation of the phase which is harmful to the spectral purity of the produced sine wave.

Circular Buffers

A circular buffer, also known as a cyclic or ring buffer is similar in working to its name, i.e., it works in a circle or an end to end pattern. It uses a single buffer of a fixed size.

Circular buffers process groups of inputs by implementing the algorithm and producing the output in the form of groups. The latest input in a circular buffer is stored in place of the oldest value which is now replaced with the latest value. When this value moves to the next spot, the previous value takes the present spot of this value, and this sequence is carried out in a circle or the form of a ring.

A circular buffer is a memory designation map where memory is reused when a value is written over a previously occupied location. The newest value takes the place of the oldest value which is then trashed or thrown out. A circular buffer needs four pointers to work. One which quantifies the actual buffer in memory, the second which quantifies the size of the buffer, third which points to the start of the data and another which point to the end of the data.

A circular buffer is a decent system for productively keeping up a sliding/moving rundown of qualities/things in an arranged manner. One sample may be to keep up a sliding average of the N values. Assume, it is needed to track the normal expense of the last 100 operations of processing some value. Without a circular buffer, an unreasonable system for doing this in C would be to have a variety of 100 components. Every time another expense is figured, you could move the 99 components down and put the new one in at the last position which is expensive. Utilizing a circular buffer would be simpler to track the end of the buffer. It would stamp the position of the most recently entered values.



Plucked String (Karplus-Strong) Algorithm

To understand the Karplus-Strong algorithm, firstly the plucking of a guitar string should be analyzed and what is happening when the guitarist plucks the string. When the string is first plucked, the guitarist delivers a certain amount of energy to the string which makes the string to vibrate. Initially, the string vibrates very vigorously, but with the passage of time (time in milliseconds) the vibration lessens and ultimately stops due to the friction in between the air and the string. This vibration, in case of an acoustic guitar, produces a sound which echoes in the hole and becomes audible. However, in case of an electronic guitar, an algorithm, known as the Karplus-Strong algorithm is used which analyzed the energy supplied to the string and simulated the sound which would be produced if a natural guitar was used.

Keeping in view how the plucked string mechanism works in nature, the writers of the Karplus-Strong algorithm (i.e. Alex Strong, who invented this algorithm to model a plucked string back in 1978, and Kevin Karplus, who performed the first analysis of the performance of this algorithm which was named “Digitar” after the digital guitar), tried to simulate the very idea behind plucking the string which was primarily vigorous behavior (i.e. higher harmonics) at start and then diminishing with time.

What the inventors extracted from the observation of the plucked string phenomenon was the dynamic behavior at the start which reduced with time and eventually gone on to become zero where the waveform becomes flat by calculating the average of the two adjacent samples and delivering a slow decay of the waveform along with it. Mathematically, this averaging operation may be written as:


The testing that was done with this algorithm produced unexpectedly high-quality results.  The sound that was recorded using this algorithm was close to the original guitar. The higher harmonics faded away rather quickly as compared to the lower harmonics which prevailed over a longer period.

The averaging mechanism was the fundamental reason behind the success of the algorithm. By employing the averaging technique, the fading away of the noise or the strong energy was modeled.

Thoroughly understanding the Karplus-Strong algorithm should be understood stepwise. The first step is to fill the memory buffer with random values (which represents the noise or energy that is delivered to the string with the strong pluck). The pluck provides the wild behavior to the string which may also be called as excitation. The excitation is nothing but a random amount of energy at varying frequencies. These frequencies are modeled, in this algorithm, like white noise; which is nothing but a set of ‘n’ number of displacements of the string with a random magnitude between the numbers -1/2 to +1/2 (It may also be -1 to +1). The second step is to simulate this random movement of the string characterized by a random waveform using a circular buffer. A circular buffer is employed to provide the next values to the algorithm once it has gone through the ‘n’ values that were the random values provided at the start. Using a circular buffer would keep on providing random values as the output, and the waveform would never unify. Here’s when the averaging mechanism comes to the rescue. The new values that are fed to the ring buffer are not random values but the average of the first two samples from the initial ‘n’ random samples. This way, the dynamic behavior of the waveform gradually keeps on reducing and eventually comes to a rest.

Summing it all up, it could be said that the initial behavior of the string is simulated by a set of random values fed to the buffer, and the gradual diminishing of the behavior of the string is simulated using the averaging mechanism with a circular buffer which keeps on performing the same function round and round again until the waveform comes to a rest.

Skimming through the complete implementation of the algorithm could be easily identified that the pillars of the success of this algorithm are two focal points; i.e., the averaging mechanism and the ring buffer feedback mechanism.

The C code for this algorithm runs for over 200 cycles at a sampling rate of 8000 Hz to generate the simulation for one pluck of the string. A MATLAB program may also be written for this mechanism. Using synthesized waveforms, i.e., saw-tooth, triangle or sine wave, with this algorithm increases the variety of sounds that may be simulated using MATLAB or C, but the C code for this takes about 380 cycles.

Several alterations or modifications were made to this algorithm keeping in view the adaptability and outstanding results of the algorithm. The decay time can be altered making it shorten or stretch. The decay time is also the answer to the question that how this algorithm produces close to real time results. There are different ways in which the implementation of the wavetable synthesis and the decay algorithm could be done. Two of the most exciting algorithms are decreasing counter and circular buffer techniques.


There exist a few different algorithms that are simple but adequate to produce better results in the implementation on different processors and synthesizers. However, the Karplus-Strong algorithm is still one of the best mechanisms to simulate plucked string instruments such as acoustic and electric guitars, banjos, kotos and even drum-like timbres.


Smith, Steven W. The Scientist and Engineer's Guide to Digital Signal Processing. [San Diego, Calif.]: California Technical Pub., 2002. Print.

Karplus, K., and A. Strong. 1983.” Digital Synthesis of Plucked-String and Drum Timbres.” Computer Music Journal 7(2)

Openheim, Alex. Lecture 1: Digital Signal Processing. 1975. Web. 12 May 2015., 'What Is Digital Signal Processing (DSP)? - Definition from Whatis.Com'. N.p., 2015. Web. 12 May 2015., 'Arduino - PWM'. N.p., 2015. Web. 12 May 2015.