Monday, 31 October 2016

Different Thaats of Indian Classical Music

Here's the ChucK file of different Thaats (scales, though not in the most exhaustive sense) of North Indian (Hindustani) Classical Music.

The file has three different functions, the Thaat function which has a sinusoidal wave playing the different thaats, a Tanpura function which serves as the drone and a Taal function, for beat. Also, at different points whenever Thaat changes, its name is printed on the Console Monitor.

Here's the soundcloud link.

Thaat is the base scale of a set of scales dependent on the particular Thaat. While North Indian Hindustani Classical Music has 10 different Thaats, South Indian Carnatic Classical Music has 72!

The different Thaats are:

  1. Bilawal: Comparable to the western Ionian mode
  2. Kalyan: Comparable to the western Lydian mode
  3. Khamaj: Comparable to the western Mixolydian mode
  4. Bhairav
  5. Purvi
  6. Marwa
  7. Bhairavi: Comparable to the western Phrygian mode
  8. Asavari: Comparable to the western Aeolian mode
  9. Kafi: Comparable to the western Dorian mode
  10. Todi
Different Ragas are subset of these Thaats. Some Ragas may be belong to two of the thaats. Therefore, it is not a very good way of classifying the Ragas, but, that's how it is.

Friday, 21 October 2016

Control of a servo motor with an ultrasonic sensor

This is a project which aims at development of an interactive interface in which the movement of a hand (or another obstacle) can control a servo motor. The project can be extended to execute projects in robotic control and newer interfaces for musical expressions.

Components:

1.      Arduino Uno
2.      Jumper wires (male to male)
3.      16 X 2 display LCD
4.      Ultrasonic Sensor HC SR-04
5.      Arduino Servo Motor
6.      USB Cable
7.      Compatible laptop with Arduino sketch installed on it.

A brief description of the different components is given as follows:

Arduino Uno

Arduino Uno is a microcontroller board based on the Atmega328P microcontroller. It has 6 analog inputs (A0 to A5), a 16 MHz quartz crystal (acts like a metronome for Arduino), a USB connection (to connect to the laptop), a power jack (to power it using AC to DC adapter), an ICSP header (to edit the In Circuit Serial Programming ports), 14 digital input/output pins (of which 6 can be used as PWM outputs), and a reset button.

Pinout diagram of Arduino Uno (https://arduino-info.wikispaces.com/QuickRef)

16 X 2 LCD Display

LCD or liquid crystal display is an electronic display extensively used to display relevant information. A 16 X 2 LCD means it can display 16 characters per line in the two lines. In this LCD each character is displayed in 5 X 7 pixel matrix. This LCD has two registers, Command and Data. We have displayed the distance of object from ultrasonic sensor on LCD.

Figure shows the LCD with its different pins:

16 X 2 LCD pins

It has 16 pins and function of each pin is defined in the following table:

S.No.
Pin Name
Pin function
1
VSS
Connected to ground
2
VDD
Connected to +5V
3
V0
Used to set contrast of the text appearing
4
RS
Used to select the register in which data is being written
RS = 0 => Command Register
RS = 1 => Data Register
5
RW
Used to select between reading/writing in the registers
0 => Write
1 => Read
6
E
Enable Pin
7 - 14
D0 - D7
Pins where data is written/read interpreted by LCD in ASCII
15
A
Backlight(Connected to +5V)
16
K
Backlight(Connected to ground)

Out of these RS, RW, E and D0 - D7 are connected to the Arduino pins. Because in our project we only need to write data into registers, that's why instead of connecting RW to a pin we directly connect it to ground. We can either use all 8 data pins (D0 - D7) or only 4 data pins (D4 - D7). For our case all the text that is to displayed can be represented by 4 bits. That's why we only use D4 - D7 pins of LCD.

Ultrasonic Sensor HC SR-04

An ultrasonic sensor is a sensor that uses sound waves to detect an object in front of it. It sends out a high frequency sound pulse and then detects the echo generated from an object in path. We can measure the time taken by the wave to travel forth and back. By having this information together with the speed of wave we can determine the distance of object from the sensor. Figure shows the ultrasonic sensor.

HC-SR04 ultrasonic sensor (http://www.ezdenki.com/ultrasonic.php)

The sensor has 4 pins - VCC, GND, TRIG and ECHO. VCC is connected to +5V. GND is connected to ground. TRIG and ECHO are connected to Arduino pins. TRIG is used to send high frequency sound wave and ECHO is used to detect the ECHO that comes back from object in path. A pulse which is HIGH for a minimum of 10us has to be given to TRIG. When done so, it sends out a 40Khz sonic burst of 8 cycles. ECHO pin sets itself HIGH the moment TRIG pin is HIGH. If there is an object in the path of wave it will reflect the wave. When ECHO detects the reflected wave it again sets itself to LOW as shown in the figure. In absence of any object there is no reflected wave and the ECHO remains HIGH until the next cycle.

The process involved (https://alselectro.wordpress.com/2013/03/08/arduinoultrasonic-sensor-for-distance-measurement/)

Servo Motor

Servo motor works on the principle of servomechanism. Basically, servo is given the input signal, corresponding to which the motor moves. It is a closed loop system with a controlled device (motor), an output sensor (inbuilt) and a feedback system (positional control). Servo motor is controlled through a PWM pulse. Servo motor comes with 3 pins:
  1. GND - Connected to ground
  2. Control - PWM pulse is supplied here
  3. VCC - Connected to +5V


Angle of rotation of servo is determined by the duration for which pulse is HIGH. For every servo motor, there is a minimum duration of pulse for which angle is minimum and there is maximum duration of pulse for which angle is maximum. Example is shown in figure below:

Figure shows the pulse duration with respect to rotation

Connections:

The connections have been made using Proteus. The voltmeter has been added so that we can see in simulation the voltage going to the test pin.




Tuesday, 4 October 2016

DSP - types of sequences

In the last post, I demonstrated plotting of analog and digital signals. It may be noted that the plotted sine wave is basically a combination of a lot of discrete values, as can be seen from the code.

In this post, I shall be focusing on different sequences, namely, impulse, unit step, exponential, sinusoidal, random and periodic sequences. Most of the DSP operations are carried out on these sequences. So, we move forward one by one.

  • Unit Impulse signal, also known as a unit sample sequence. The value of such a signal is unity at n = 0, that is the home position (in context of robotics). Consider a clap. A clap is like an impulse signal, momentary, maximum value at one point in time. The following figure shows the impulse signal. Here's the code.


  • Unit step signal - Simply, consider switching on a fan. It starts working. The analogy can be extended to understanding unit step signal. Therefore, until a certain point in time, the value of a signal is zero, and after that time, the signal's value is 1. The following figure shows a unit step signal. Here's the code.
  • Exponential signal - Consider population explosion, humans were hardly near 500 million people near 1600 AD and we rose to nearly 2 billion in 300 years (1900 A.D.) which plummeted to 6 billion in just 100 more years. Such an increase is exponential in nature. The plot below shows a real valued exponential signal. Code. Complex exponential signals' code can be seen here. As you'll see on implementing, it is sinusoidal in nature (Euler's formula).
  • Sinusoidal signal - Consider the transmitting of signals in AC systems. The signals show a sinusoidal variance with respect to time. The following figure shows a sinusoidal variation. Here's the code.
  • Random sequences - Most of the stuff happening around us is random in nature. The following figure shows a random curve. Here's the code.
  • Periodic sequences - These are the sequences which repeat after a certain amount of time. A sinusoidal signal is periodic sequence. Each periodic signal has a period, which is the time after which the signal repeats. For the sinusoid given above, the period is (2*pi/5 = 1.257) approximately 1.26 seconds.

Monday, 3 October 2016

DSP - basic introduction

In the coming few days I shall upload MATLAB codes of basic DSP implementations. But before getting started, I will explain what exactly is DSP and why it is so important, especially in the realm of music technology.

DSP is an abbreviation for Digital Signal Processing. Let us decode it. 

What is a signal?

Signal is anything carrying information. You say your name, that is a signal. The noise produced by a moving fan is a signal. So, signals can be useful or not useful/undesirable/unwanted/useless. In the terms of DSP, noise is an unwanted signal, and it needs to be attenuated to the extent that it is completely removed, so, we can get the desired signal.

Noise interferes with the original, desired signal.

In order to extract the original signal, we need to 'process' it in such a way that we can get it in a desired manner. Consider the following scenario:



In order to reach the audience, the meek lady's voice alone won't suffice. So, she uses a microphone to be audible to everyone in the auditorium. What does the microphone do? It takes a signal, processes it (amplifies) and sends signals to the speakers in the auditorium. It is a basic form of signal processing.

There are two types of signals: Analog and digital. Analog signals vary continuously in amplitude with time. There is no least time frame that you can identify and isolate in it. Figure shows an analog sinusoidal signal. Find MATLAB code here.


Digital signals, or discrete time signals take one of the finite number of values at specific points in time. Thus, they can be stored in the form of bits of information (streams of zero or 1). Consider a digital signal consisting of first 10 natural numbers, incrementing every second starting from zero. Figure shows a plot for the signal. Find MATLAB code here.


There is little flexibility in processing analog signals. The equipment is expensive, and passive components, whose properties vary with time, such as capacitors, transistors are used. 

So, now it can be understood that we need to convert an analog signal to a digital signal, process it, and convert it back to analog signal to get the desired signal. How does this take place? Steps:
  1. Input an analog signal to the processor.
  2. The first step in the processor is an anti-aliasing filter. What is aliasing? It is the distortion of the signal if it is sampled at a frequency less than twice the sampling frequency. The filter conditions the analog signal to prevent aliasing. So, what it does is that it restricts the bandwidth of the signal to satisfy the condition of sampling frequency being more than twice the sampling frequency (sampling theorem). The filter is used before sample-r, or the Analog to Digital converter.
  3. ADC discretizes the analog input.
  4. This digital signal is then processed, in a computer/microprocessor. The processing is primarily either analysis or filtering (removing noise, etc.).
  5. A digital to analog convertor, or a DAC converts the signal to an analog signal (the signal is in the form of a staircase now).
  6. The signal is then fed into a post-filter to smoothen the DAC output.