# Wazifa Counter using Speech Processing in Matlab

A friend asked some time before to develop a tool which counts the number of times a wazifa has been recited. It had to use only voice input when hands were not free such as during driving. Here is a version-0 of an attempt at solving the problem. A program is written in Matlab script that uses only the cross correlation function to search the number of times a particular sentence has been spoken.  This is offline version. Two *.wav files are input to the program. “darood1.wav” contains one sample of the wazifa to be searched. “darood5.wav” is the file to be searched for occurrences of the wazifa.

[al ar] = audioread('darood1.wav'); % Load sample wazeefa file (recited one time)
c = xcorr(al(:),bl(:)); % perform cross correlation on two files (Use just one channel of stereo recorded input)

t = 1:length(c); % Horizontal index vector for plotting purposes
z = envelope(c,50000,'peaks'); % Detect major lobes in cross-correlation output
plot(t,z)

[pks,locs,w,p] = findpeaks(z,'MinPeakDistance',5000) ; % Detect peaks but ignore that are colser than 5000 samples
findpeaks(z,'MinPeakDistance',5000) % Here to plot data with peaks
count = size(pks( pks>(.1*mean(pks)) )); % Count number of significant peaks
count = (count-1)/2 % Display number of recitations



## Result:

Result were good enough for this crude program and off-line recordings.

## Future Work:

• Improve the program efficiecy by working on feature rather than the direct samples
• Make the processing real time

# Pakistan Flag Dimensions

With 14 August 2016 coming tomorrow I am studying the dimensions of the Pakistan flag as recommended in [3]. The results are shown in above figure. All dimensions are with reference to the height of the flag “H”. Width of the flag is one and half times H, shown as “3H/2” in dimension. The white strip is 1/4th of the total width that translates to 3/8th of height. The outer arc of crescent is a circle with center at center of the green portion with radius thirty percent of flag height. The five pointed star is circumscribed by circle of radius 1/10 H and touches the first circle from inside towards the top right corner. One point of the star is aligned towards top right corner. The inner arc radius is 11/40 times the height with center on off-diagonal line at a distance of 13/20 H from  top right corner. The flag is colored in Pakistan green having standard RGB values (red = 0, green = 102, blue = 0) or with hex triplet #006600 or the HSV value = (h = 120, s = 100, v = 40). The left strip, the star and  the crescent are painted in white. The flag is supported from left white side. The flag is not to be flown vertically. The below figure shows an example with height taken as 20.

Programmed tikz to draw the flag in latex.


\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric}
\begin{document}
\definecolor{green}{RGB}{0, 100, 0}
\noindent\begin{tikzpicture}
% Use wikipedia's dimensions

\fill[green] rectangle (12, 8);%G=8, L=12, L=1.5 G
\fill[white] (.01,.01) rectangle (2.98, 8);%G=8, L=12, L=1.5 G

\fill[white] (7.5,4) circle (2);
\fill[green] (7.9,4.4) circle (1.6);
\node[star,fill=white, minimum size=1.7cm, rotate=25, star point ratio=2.617,inner sep=0pt] at (8.9,5.5) {};
\end{tikzpicture}
\end{document}


## National Assembly Passed the Design on 11 August 1947

That this assembly resolves that the national flag of the federation of Pakistan be of the following description.

“A dark green rectangular flag in the proportion of length and width 3:2 with a white vertical bar at the mast, the green portion bearing a white crescent in the centre and a five-pointed white heraldic star. The size of the white portion being one-fourth the size of the flag, nearest the mast, the remainder three-fourths being dark green. the dimensions of the crescent and star are obtained as follows:

“Draw the diagonal from the top right hand corner to the bottom left corner of the green portion. On this diagonal establish two points ‘A’ and ‘B’. Point ‘A’ at a distance equidistant from top right and bottom left hand corners of the green portion, i.e. the centre of the green portion. Point ‘B’ at a distance from the top right hand corner equal to 13/20th the width of the flag. With centre point ‘A’ and radius 1.1/4th the width of the flag describe a second arc. The enclosures made by these two arcs form the crescent. The dimensions of the five-pointed white heraldic star are determined by drawing a circle 1/10th the width of the flag. The circle surrounds the five points of the heraldic star. The star lies with one point on the diagonal at a point where the larger arc of the crescent, if completed, cuts the diagonal.”

## Flag Construction References:

In earlier days of the internet, Iqbal Cyber Library was among the first sites that hosted Urdu ebooks. The books, however, were not available in the form of Unicode or searchable text in simple words. The individual book pages were hosted in the form of images, probably created using Inpage Urdu editor. The site allowed downloading of these books with httptrack, a tool to copy complete website on computer hard disk for offline reading. I preferred saving all the ebook pages in one folder with extension pnnnn.gif, nnnn being the 4-digit page number. Then I  programmed little javascript code to view all pages in that folder, navigating with left and right arrow keys.

<html>
<title> HTML Ebook </title>

<style type="text/css">
div{
transform: rotate(0deg);
-ms-transform: rotate(0deg); /* IE 9 */
-webkit-transform: rotate(0deg); /* Safari and Chrome */
}
</style>

var imgN=1;
return Array(Math.max(digits - String(number).length + 1, 0)).join(0) + number;
}

function nextImg(){
imgN++;
//document.images[0].style.msTransform='rotate('+((0=++0%4)*90)+'deg)';
document.images[0].css("-webkit-transform", "rotate(40deg)");
}

function prevImg(){
imgN--;
//document.images[0].style.msTransform='rotate('+((0=++0%4)*90)+'deg)';
}

document.onkeydown = checkKey;

function checkKey(e) {
e = e || window.event;
if (e.keyCode == '37') {
// left arrow
document.body.scrollTop = document.documentElement.scrollTop = 0; //Scroll up page
nextImg();
}
else if (e.keyCode == '39') {
// right arrow
document.body.scrollTop = document.documentElement.scrollTop = 0; //Scroll up page
prevImg();
}
//left key code = 37
//up key code = 38
//right key code = 39
//down key code= 40
}

<body bgcolor="#FFFFFF" dir=rtl>

<INPUT TYPE="button" VALUE="< Previous Page" ONCLICK="prevImg()">
<INPUT TYPE="button" VALUE="Next Page>" ONCLICK="nextImg()">
<!--<INPUT TYPE="text" VALUE="" ONCLICK="goToImage(text)">-->
</body>
</html>


# Phase Portraits of Differential Equations

Phase portraits of differential equations help visualize the response of a system to initial conditions and when represented in state-space form, how do the system space vector gets effected for zero input response as function of time.


% Matlab Code for Phase Portraits
% Author: Abu Bakar Siddique
% Dated: 25-Mar-2016

clear all; close all; clc

[x1,x2] = meshgrid(-4:.5:4,-4:.5:4);

x1 = x1(:)'; x2 = x2(:)';

A1 = [-1 0; 0 -4];
A2 = [-2 -1; -2 -3];
A3 = [-2 0; 0 1];
A4 = [-3 -2; 2 2];
A5 = [-1 1; -1 -3];
A6 = [-2 1; 0 -2];
A7 = [2 -3; 6 -4];
A8 = [-1 2; -5 1];
A9 = [-3 1; 0 -2];
lineWidth = 3;

subplot (241);
xdot = A1*[x1; x2];x1d = xdot(1,:); x2d = xdot(2,:);mag = sqrt(x1d.^2 + x2d.^2);quiver(x1,x2,x1d./mag, x2d./mag,'b');
hold on; quiver([0 0],[0 0],[1 0], [0 1],'r','linewidth',lineWidth); hold off
axis tight equal; title('A_1')

subplot (242)
xdot = A2*[x1; x2];x1d = xdot(1,:); x2d = xdot(2,:);mag = sqrt(x1d.^2 + x2d.^2);quiver(x1,x2,x1d./mag, x2d./mag,'b');
hold on; quiver([0 0],[0 0],[1 1], [-1 2],'r','linewidth',lineWidth); hold off
axis tight equal; title('A_2')

subplot (243)
xdot = A3*[x1; x2];x1d = xdot(1,:); x2d = xdot(2,:);mag = sqrt(x1d.^2 + x2d.^2);quiver(x1,x2,x1d./mag, x2d./mag,'b');
hold on; quiver([0 0],[0 0],[1 0], [0 1],'r','linewidth',lineWidth); hold off
axis tight equal; title('A_3')

subplot (244)
xdot = A4*[x1; x2];x1d = xdot(1,:); x2d = xdot(2,:);mag = sqrt(x1d.^2 + x2d.^2);quiver(x1,x2,x1d./mag, x2d./mag,'b');
hold on; quiver([0 0],[0 0],[-2 1], [1 -2],'r','linewidth',lineWidth); hold off
axis tight equal; title('A_4')

subplot (245)
xdot = A5*[x1; x2];x1d = xdot(1,:); x2d = xdot(2,:);mag = sqrt(x1d.^2 + x2d.^2);quiver(x1,x2,x1d./mag, x2d./mag,'b');
hold on; quiver([0 0],[0 0],[-1 -1], [1 1],'r','linewidth',lineWidth); hold off
axis tight equal; title('A_5')

subplot (246)
xdot = A6*[x1; x2];x1d = xdot(1,:); x2d = xdot(2,:);mag = sqrt(x1d.^2 + x2d.^2);quiver(x1,x2,x1d./mag, x2d./mag,'b');
hold on; quiver([0 0],[0 0],[1 1], [0 0],'r','linewidth',lineWidth); hold off
axis tight equal; title('A_6')

subplot (247)
xdot = A7*[x1; x2];x1d = xdot(1,:); x2d = xdot(2,:);mag = sqrt(x1d.^2 + x2d.^2);quiver(x1,x2,x1d./mag, x2d./mag,'b');
% hold on; quiver([0 0],[0 0],[1 1], [-1 1],'r'); hold off
axis tight equal; title('A_7')

subplot (248)
xdot = A8*[x1; x2];x1d = xdot(1,:); x2d = xdot(2,:);mag = sqrt(x1d.^2 + x2d.^2);quiver(x1,x2,x1d./mag, x2d./mag,'b');
% hold on; quiver([0 0],[0 0],[1 1], [-1 1],'r'); hold off
axis tight equal; title('A_8')

ha = axes('Position',[0 0 1 1],'Xlim',[0 1],'Ylim',[0
1],'Box','off','Visible','off','Units','normalized', 'clipping' , 'off');

text(0.5, 1,'\bf Phase Portrait Plots submitted by Abu Bakar Siddique: 2013-Phd-Elect-008)','HorizontalAlignment' ,'center','VerticalAlignment', 'top')



quiver(X,Y,U,V) plots velocity vectors as arrows with components (u,v)
at the points (x,y). The matrices X,Y,U,V must all be the same size
and contain corresponding position and velocity components (X and Y
can also be vectors to specify a uniform grid). quiver automatically
scales the arrows to fit within the grid.