# 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

# Selection of Capacitor and Resistor Values for Twin-T Notch Filter

A notch filter, also known as band-stop filter, is used to take away a single frequency out of a signal. In instrumentation and audio circuits it used to filter out the 50/60 Hz hum due to mains power supply frequency. I fount the Twin-T notch filter to be the best. The notch frequency formula is given as $1/ 2\pi R C$. Twin-T offers theoretically infinite attenuation at notch frequency due to pole-zero cancellation in transfer function with perfectly matched components.  I needed a 50Hz notch and tried to find out how close may I come close to designated frequency with off the shelf components. Programmed an excel sheet to make a table of values. I ended up using 68nF capacitor with 47k resistor to give 50Hz notch with 0.4% error. Below table shows the mantissa values of $1/ 2\pi R C$ with 10% tolerance components. A multiplication with proper powers of 10 would select the actual components.

## Table: R-C values selection with 10% tolerance

 10 12 15 18 22 27 33 39 47 56 68 82 10 15.915 13.263 10.61 88.419 72.343 58.946 48.229 40.809 33.863 28.421 23.405 19.409 12 13.263 11.052 88.419 73.683 60.286 49.122 40.191 34.007 28.219 23.684 19.504 16.174 15 10.61 88.419 70.736 58.946 48.229 39.298 32.153 27.206 22.575 18.947 15.603 12.939 18 88.419 73.683 58.946 49.122 40.191 32.748 26.794 22.672 18.813 15.789 13.003 10.783 22 72.343 60.286 48.229 40.191 32.883 26.794 21.922 18.55 15.392 12.918 10.639 88.223 27 58.946 49.122 39.298 32.748 26.794 21.832 17.863 15.114 12.542 10.526 86.686 71.886 33 48.229 40.191 32.153 26.794 21.922 17.863 14.615 12.366 10.261 86.123 70.925 58.816 39 40.809 34.007 27.206 22.672 18.55 15.114 12.366 10.464 86.828 72.873 60.013 49.767 47 33.863 28.219 22.575 18.813 15.392 12.542 10.261 86.828 72.048 60.469 49.798 41.296 56 28.421 23.684 18.947 15.789 12.918 10.526 86.123 72.873 60.469 50.751 41.795 34.659 68 23.405 19.504 15.603 13.003 10.639 86.686 70.925 60.013 49.798 41.795 34.419 28.543 82 19.409 16.174 12.939 10.783 88.223 71.886 58.816 49.767 41.296 34.659 28.543 23.67

The above table shows the value of 60Hz frequency with 0.02% error with component selection 39 and 68. One possibility might be 39k resistor and 68nF capacitor.

# Latex UMT Exam Template


Following is an exam template that was created for University of Management and Technology Lahore, typeset using pdflatex and Philip Hirschhorn's exam.cls: http://www-math.mit.edu/~psh/#ExamCls.
% Exam Template for University of Management and Technology Lahore
% Author: Abu Bakar Siddique
% The folder of this tex should also contains UMTLogo.jpg and exam.cls
%
% Exam Template for UMTYMP and Math Department courses
% Using Philip Hirschhorn's exam.cls: http://www-math.mit.edu/~psh/#ExamCls
%
% run pdflatex on a finished exam at least three times to do the grading table on front page.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\documentclass[11pt]{exam}
\RequirePackage{amssymb, amsfonts, amsmath, latexsym, verbatim, xspace, setspace}
\RequirePackage{tikz, pgflibraryplotmarks}
\usetikzlibrary{shapes.geometric,arrows,fit,matrix,positioning}
\tikzset
{
treenode/.style = {circle, draw=black, align=center,
minimum size=1cm, anchor=center},
}
\usepackage[none]{hyphenat}
\usepackage[margin=1in]{geometry}
\usepackage{multirow}
\usepackage{lipsum}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%            E X A M   I N F O R M A T I O N
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\newcommand{\courseCode}{EE210}
\newcommand{\courseTitle}{Data Structures And Algorithms}
\newcommand{\examDate}{April 09, 2013}
\newcommand{\examType}{Mid Term}
\newcommand{\RP}{Mr. Saleem Ata (Sec A \& E), Abu Bakar Siddique (Sec  B, C \& D)}
\newcommand{\semester}{Spring 2013}
\newcommand{\timeAllowed}{30 Minutes}
\newcommand{\totalMarks}{15}

\newcommand{\rowSpace}{1.2ex}

\singlespacing
% \onehalfspacing
% \doublespacing
% For an exam, single spacing is most appropriate

% For an exam, we generally want to turn off paragraph indentation
%\parindent 3ex

\title{\vspace{-7ex} University of Management \& Technology\vspace{-1ex}}
\author{Department of Electrical Engineering
}
\date{}

\begin{document}

\begin{tabular}{l c}
\multirow{4}{*}{ \includegraphics[width=.75in]{UMTLogo.jpg} }& \\
& {\Large  \textbf{University of Management \& Technology}}\\
&\large \textbf{School of Engineering}\\
& \textbf{Department of Electrical Engineering}\\ %[\rowSpace]
\end{tabular}

%-----------------------------------------------
%-----------------------------------------------
\vspace{2em}
\runningfooter{}{Page \thepage\ of \numpages}{}

\begin{flushright}
\begin{tabular}{p{1.5in} p{2in} p{.05in} p{1.2in} p{1in}}

\textbf{Student ID}&\hrule && \textbf{Section} & \hrule \\ [\rowSpace]
\textbf{Student Name}&\hrule && \textbf{Semester}& \semester\\ [\rowSpace]
\textbf{Student Signature}&\hrule&&&\\ [\rowSpace]
\textbf{Course Title}& \courseTitle && \textbf{Time Allowed} & \timeAllowed\\
\textbf{Exam Date}& \examDate && \textbf{Total Marks}& \totalMarks\\
\textbf{Exam}& \examType && & \\
\textbf{Resource Person(s)} & \multicolumn{4}{p{4.5in}}{\RP}\\
\end{tabular}\\
\end{flushright}
\begin{framed}
\small
\begin{center}
\textbf{DO  NOT  OPEN  THIS  EXAM  UNTIL  TOLD  TO  DO  SO}
\end{center}
\emph{The instructions below must be followed strictly. Failure to do so can result in serious grade loss.}\\
\textbf{You must}
\begin{itemize}
\item Switch off your mobile phones completely.
\end{itemize}

\textbf{Specific instructions}
\begin{itemize}
\item \textbf{Calculator Allowed, Closed Book, Closed Notes.}
\item \textbf{No extra sheet} will be given. Use the available space wisely.
\item \textbf{Use a blue or black} ball point or pen. Please do not use lead pencils.
\item \textbf{Provide final answers} in the space provided.You may use back blank sheets for rough work.
\end{itemize}
\end{framed}

\begin{center}
\textbf{Certificate to be filled at the time of exam}
\end{center}

I have counted all \numpages\ pages in this exam and no page is missing. \hfill \textbf{Student Signature}

\begin{center}
\vspace{0pt}
\cellwidth{3em}
\vqword{Questions}
\addpoints % required here by exam.cls, even though questions haven't started yet.

%\pointtable[h][questions]
%\end{minipage}
\end{center}

\begin{center}
\textbf{Certificate to be filled during paper viewing}
\end{center}

I have reviewed my paper and all \numquestions\ questions have been marked with\\ no
part left unmarked. Counting is also correct. \hfill \textbf{Student Signature}

\newpage % End of cover page

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%            Q U E S T I O N S
%
% See http://www-math.mit.edu/~psh/#ExamCls for full documentation, but the questions
% below give an idea of how to write questions [with parts] and have the points
% tracked automatically on the cover page.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{questions}

% Basic question
%\question[10] Differentiate $f(x)=x^2$ with respect to $x$.

\question[3] Write Pre-Order, In-Order and Post-Order traversals of following tree:

\begin{tikzpicture}[->,>=stealth',level/.style={sibling distance = 5cm/#1,
level distance = 1.5cm},scale=0.6, transform shape]

\node [treenode] {7}
child{
node [treenode] {5}
child{
node [treenode] {3}
child{ node [treenode] {1} }
child{ node [treenode] {4} }
}
child{ node [treenode] {6} }
}
child{
node [treenode] {8}
child{
node [treenode] {1}
}
child{
node [treenode] {2}
child{ node [treenode] {7} }
child{ node [treenode] {9} }
}
}
;
\end{tikzpicture}
\vspace{4in}

\question[2] A Binary Tree has 37 nodes. What is the minimum height of the tree that can take all of these nodes? Take height of a single node tree as 1.
\vspace{3in}

\question[3] Make structure of a binary tree that has following Pre-Order and In-Order traversals:
\begin{description}
\item[Pre-Order:] A, B, D, E, F, G, C
\item[In-Order:] D, B, F, E, G, A, C
\end{description}
\vspace{6in}

\question[1] How many comparisons would take place when finding a value in a sorted list of 1024 entries using binary search algorithm? (2 Marks)
\vspace{2in}

\question[4] Construct binary search tree when values are inserted in following order:\\
$\longrightarrow$ 9, 13, 12, 1, 7, 25, 4, 19, 3, 23, 11, 4, 27,6
\newpage

\question[2] Starting with empty stack, what would be the contents of the stack after following operations are performed.Draw the stack after the following operations
\begin{itemize}
\item Push(56)
\item Push(92)
\item Push(7)
\item Pop()
\item Push(5)
\item Pop()
\end{itemize}

\vspace{4in}

% Question with parts
%\newpage
%\question Consider the function $f(x)=x^2$.
%\begin{parts}
%\part[5] Find $f'(x)$ using the limit definition of derivative.
%\vfill
%\part[5] Find the line tangent to the graph of $y=f(x)$ at the point where $x=2$.
%\vfill
%\end{parts}

% If you want the total number of points for a question displayed at the top,
% as well as the number of points for each part, then you must turn off the point-counter
% or they will be double counted.
%\newpage
%\question[10] Consider the function $f(x)=x^3$.
%\noaddpoints % If you remove this line, the grading table will show 20 points for this problem.
%\begin{parts}
%\part[5] Find $f'(x)$ using the limit definition of derivative.
%\vspace{4.5in}
%\part[5] Find the line tangent to the graph of $y=f(x)$ at the point where $x=2$.
%\end{parts}

\end{questions}
\end{document}



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
}