Skip to content


A Wordle of my Thesis

I’ve not posted to this blog in a while now. I’ve been busy with other things (mainly my PhD). Still, the good news is I’ve just passed my viva, so now I can pick up where I left off with my projects. In an earlier post I made a Wordle of my 9 month progress report, so I decided to do another Wordle of my thesis. However, this time I’ve decided to take another approach to generating the Wordle, which uses a PERL script.

First off, here is the generated Wordle:

A Wordle of my PhD Thesis

A Wordle of my PhD thesis. The size of the word represents the frequency with which that word is used within my thesis.

Now, here is the PERL script I used to convert the LaTeX into a list of words:

#!/usr/bin/perl
#

use strict;

# An array of subroutine references, which will be called in order
# on each line of latex during the parseLatex subroutine.

our @functions = (
	\&removeComments,
	\&ignoreFigures,
	\&ignoreMath,
	\&removeInlineMaths,
	\&readInclude,
	\&removeEmph,
	\&removeSectionHeader,
	\&removeRefs,
	\&removeCommands,
	\&spaceToNewLine

);

if(@ARGV < 0)
{
	print STDERR "Please specify a file to start reading.\n";
	exit;
}

&parseLatex($ARGV[0]);

sub parseLatex { my($file) = @_;

	my $fh;
	open $fh, "<$file";

	while(<$fh>)
	{
		my $line = $_;

		foreach my $code (@functions)
		{
		
			$line = $code->($line, $fh);

		}

		print $line;
	}

	close $fh;
}

sub removeComments { my ($line) = @_;
	$line =~ s/([^\\])?%.*/$1/;
	$line
}

sub removeEmph { my ($line) = @_;

	$line =~ s/\\emph\{([^\}]+)\}?/$1/g;

	$line;
}

sub readInclude { my ($line) = @_;
	
	my $file = "";
	if( $line =~ m/\\include\{([^\}]+).tex\}/)
	{
		$file = "$1.tex";
		&parseLatex($file);
		"";
	}
	elsif( $line =~ m/\\include\{([^\}]+)\}/)
	{
		$file = "$1.tex";
		&parseLatex($file);
		"";
	}
	if( $line =~ m/\\input\{([^\}]+).tex\}/)
	{
		$file = "$1.tex";
		&parseLatex($file);
		"";
	}
	elsif( $line =~ m/\\input\{([^\}]+)\}/)
	{
		$file = "$1.tex";
		&parseLatex($file);
		"";
	}
	else
	{
		$line;
	}
}

sub ignoreFigures { my ($line, $fh) = @_;

	if($line =~ m/\\begin\{(((figure)|(table)|(equation)|(align))\*?)\}/)
	{
		# ignoreFiguresSub will keep reading until we find the matching
		# \end{...} command.
		&ignoreFiguresSub($fh, $1);
		"";
	}
	else
	{
		$line;
	}
}

sub ignoreFiguresSub { my ($fh, $until) = @_;
	while(<$fh>)
	{
		&ignoreFigures($_,$fh);
		if( $_ =~ m/\\end{$until}/)
		{
			last;
		}
	}
	"";
}

sub removeInlineMaths { my ($line) = @_;
	$line =~ s/\$[^\$]*\$//g;

	$line;
}


sub ignoreMath{ my ($line,$fh) = @_;

	if($line =~ m/\\\[/)
	{

		while(<$fh>)
		{
			if( $_ =~ m/\\\]/)
			{
				last;
			}
		}
		"";
	}
	else
	{
		$line;
	}
}

sub removeSectionHeader{ my ($line) = @_;

	$line =~ s/\\(sub)*section\{([^\}]+)\}/$2/;
	$line =~ s/\\chapter\{([^\}]+)\}/$1/;

	$line;
}

sub removeRefs{ my ($line) = @_;

	$line =~ s/([A-Za-z]+~)?\\(auto)?ref\{[^\}]*\}//g;

	$line =~ s/\\cite[a-z]*\{[^\}]*\}//g;
	$line =~ s/\\label\{[^\}]*}//g;

	$line;
}


sub removeCommands { my ($line) = @_;
	$line =~ s/\\[^ ]+//g;

	$line;
}

sub spaceToNewLine { my ($line) = @_;
	$line =~ s/\s+/\n/g;

	$line;
}

Finally, with the above PERL saved to a file named striptex.pl inside the same folder as my main latex file (Thesis.tex), I used the following pipeline:

./striptex.pl Thesis.tex | tr A-Z a-z | sort | sed "s/[^a-zA-Z0-9]//g" > words.txt

Thanks to Colin Williams for his improvements to the script. Have fun.

Posted in Programming, Research.

Tagged with , , , .


Javascript Syntax Highlighting for Verilog

In writing my last two posts (here and here), I needed to develop a new brush for SyntaxHighligther — a javascript library that performs syntax highlighting — for the Verilog HDL. I thought other people might find this useful, so I’ve decided to upload it to here. Examples of it in use can be seen in any of the two posts linked above, and I’ve provided a very quick example of it below, along with the source code and a download link.

Quick Example

`preprocessor directive
$print(some function);


always @ (posedge clock or negedge something)
begin
// this is a comment
/* so
 is this */
end

Continued…

Posted in Programming.

Tagged with , , , , .


DCMs and Clock Division on the Xilinx Spartan6 FPGA

Last week, I wrote an article about my first project on an FPGA — building a counter and displaying the output on LEDs. However, it involved a bit of a hack in order to make the changing LEDs visible. Basically, it counted to 2^32 at 100MHz, while only actually displaying the values of the 8 most significant bits. This week, I’ve been learning about digital clock managers, which are primitives provided by Xilinx that use specialist hardware within the FPGA to multiply or divide clock frequencies. This article will discuss what I’ve learnt, and will update the code from last week in order to generate a 1Hz clock signal, that will be used to have our counter update once every second.

There are a couple of digital clock manager (DCM) primitives for the Xilinx Spartan6 — DCM_SP, and DCM_CLKGEN. In this article, I’ll introduce the DCM_CLKGEN primitive and describe its functionality. I’ve gone into some detail about some of the relevant clock primitives, but this is mainly to provide some intuition as to how these things are actually working. If you’d like to skip straight to the implementation then you can click here. I’ve chosen to focus on the DCM_CLKGEN primitive rather than the DCM_SP because the former focuses mainly on scaling clock frequencies, whereas the latter does a similar job but has much more flexibility in terms of controlling the phase offset between the output and input clocks — added complexity which I do not need yet. However, before I get into that, I’ll introduce a couple of other primitives used to buffer global clock signals — BUFG, and BUFIO2 — which must be used to pass a clock signal from an external pin to any DCM.
Continued…

Posted in Electronics, FPGA.


Counting LEDs on a Digilent Atlys

Just yesterday I took delivery of my first ever FPGA board, and I thought I’d document my first program — a counter which displays its output using the 8 on-board LEDs!

The Digilent Atlys board has a Xilinx Spartan 6 FPGA on board. Consequently some of the Verilog code I’ve got in this article is Xilinx specific. Furthermore, the pin specifications, and peripherals described in this article are specific to the Digilent Atlys board.

For those who have not come across the term FPGA before, it stands for ‘field programmable gate array’. It can be thought of as a large collection of logic gates (and, or, nor, xor, etc.), which can be dynamically configured, allowing developers to build logic circuits. They’re incredibly versatile, with the ability to create circuits that do basic logical operations, or the ability to create entire processor cores and embedded peripherals.

However, first things first. Let’s create a small project that simply counts and displays its output on the 8 on-board LEDs.
Continued…

Posted in Electronics, FPGA, Programming.

Tagged with , , , , , , , , , , .


AVR Programming: Flashing LEDS

I’ve had an arduino for a while now, and I’ve done a few projects that I would like to deploy.  Rather than using an arduino at about £16 per board, I decided I’d try to learn how to program AVR chips, the price of which varies, are in the range of £2-£5/chip.  This tutorial will discuss what I’ve done so far — namely, the chip equivalent of “hello world” (flashing an LED) and using the timers for PWM (pulse-width modulation), which will be coming up in another tutorial.

The AVR chip I’m using in this tutorial is the ATMega48, which I’m programming using the USBTinyISP, which I bought in kit form from Adafruit.  Below is a photograph of my setup.

USBTinyISP wired to an ATMega48

My USBTinyISP wired to my ATMega48 chip


Continued…

Posted in Arduino, AVR, Electronics, Programming.

Tagged with , , , , , .


A PERL script to generate LaTeX documents

I write a lot of LaTeX in my work.  In fact, after most experiments, I write up a quick latex document to describe my results.  As a result I tend to start a lot of latex documents, and as such I wanted a quick way to generate a skeleton document that I can quickly fill out.

So, rather than just producing a template and making a copy of that, or using a latex IDE, I decided I’d write a PERL script — its the obvious thing to do really…

Basically, inside the script there are a load of default options which you can set if there are settings you commonly use, then for anything else there are command line options.  The latex is output to standard out, and you can simply pipe that into a file.  Magic :o

Here’s the code:

#!/usr/bin/perl

use Getopt::Long;
use Data::Dumper;

# Defaults

	my $authorName = "Freud";
	my $authorEmail = '...';
	my $documentClass = "article";
	my %documentOptions = {"article" => ""};

	my @packages=( "url","hyperref","graphicx" );

# End of Configuration

	my $overrideOptions;
	my $packageString = "";
	my $docopts = "";
	my $title = "";

	# Specify default options for each document type here.

	# Allow grouping of options into single blocks like -abc etc (although that wouldnt work here anyway
	# we'll put it here just to make it easier for future Harries to edit this document and not break thigns).

	Getopt::Long::Configure('bundling_override');
	GetOptions(	'a|author=s' => \$authorName,
			'e|email=s' => \$authorEmail,
			'c|class=s' => \$documentClass,
			'o|options=s' => \$overrideOptions,
			'oo|appendOptions=s' => \$appendOptions,
			'u|usepackage=s' => \@packages
		);

	foreach (@packages)
	{
		my $options = "";
		if($_ =~ m/([^\[]*)(\[.+\])?/)
		{
			$package = $1;
			$options = $2;

			$packageString .= "\\usepackage$options\{$package\}\n";
		}
	}

	if($#ARGV < 0)
	{
		print STDERR "Please specify a title as the final command line argument.";
		die;
	}

	$title = $ARGV[0];

	if(exists($documentOptions{$documentClass}))
	{
		$docopts = $documentOptions{$documentClass};
	}

	if(length($overrideOptions) > 0)
	{
		$docopts = $overrideOptions;
	}

	if(length($appendOptions) > 0)
	{
		$docopts = "$docopts,$appendOptions";
	}

	if(length($authorEmail) > 0 && length($authorName) > 0)
	{
		$authorEmail = "\\thanks{$authorEmail}";
	}

	print STDOUT <<OUTPUT;
\\documentclass[$docopts]{$documentClass}

$packageString

\\author{$authorName$authorEmail}
\\title{$title}
\\begin{document}
	\\maketitle

\\end{document}
OUTPUT

Posted in Programming, Research.

Tagged with , , , , , , .


A Wordle of my Research

A month or so ago I handed in the first report of my PhD in which I described the work I had been doing so far. I just put my report into wordle (after some processing), and here is the output. See if you can guess what my area of research is :P

A Wordle generated from the content of my 9 month report.

A Wordle generated from the content of my 9 month report.

If its of any use to anybody, the pipeline I used to generate the input to wordle is…
cat report | gawk 'BEGIN{RS=" "}{print $0}' | gawk '/^[a-zA-Z]/{print $0}' | sed 's/[^0-9A-Za-z]//g' | tr '[A-Z]' '[a-z]' | sort | gawk '{printf "%s ", $0}' > toWordle

Posted in Research.

Tagged with , , , , , .


Writing External C/C++ Functions for MATLAB

Anybody who has ever used MATLAB before will probably be aware that using loops is incredibly slow.  It is advised that you write as much of your code as possible using matrices and vectors.  However, if like me, your brain gets easily tangled into knots by multiple dimensions, or you want to do something particularly complicated, using matrices may not seem like a particularly attractive prospect.  I came across this problem (not for the first time) earlier today, and I decided I’d have a go at trying to solve it.

In these situations, execution time can be greatly reduced by writing and compiling C or FORTRAN functions, which you then call from MATLAB.  The form I will discuss here are C MEX files.  Simply by porting a loop from MATLAB to C, I managed to reduce the execution time of a simulation I was running from over 260 seconds, to about 20 (I’m working on getting it down to less than 10).
Continued…

Posted in Programming.

Tagged with , , , , , , , .


South Lettings and South Residential: New Developments

Just a quick update on the South Lettings/South Residential saga.  They have agreed to use the dispute resolution service, which is good of them. Hopefully we’ll be able to get this all sorted (and even more hopefully, the guys at the deposit protection place will find in my favour :-P ).

Before I continue, may I just apologise for the recent down-time this site experienced.  It would appear the web-server wasn’t feeling up to hosting this site, so I’ve moved it to its own server, which should hopefully cope better (fingers crossed).

This afternoon I visited some solicitors just to confirm my legal rights with regards to the charges being imposed by South Lettings (if you haven’t heard the saga so far check out my other post).  I was told that it sounded like what they were doing was trying to impose new terms in the contract after it had been signed (the new terms being the new charges).  A relevant case in UK law is that of ‘Thornton vs Shoe Lane Parking Ltd‘, which basically seems to boil down as follows…

Mr Thornton parked in a car park, received a ticket to park, then upon returning to his car was injured.  To my understanding, Shoe Lane Parking claimed they were not liable to pay compensation because on the ticket was written words to the effect of ‘Terms and Conditions Apply’.

The judge ruled that because Mr Thornton had not been made aware of the terms before entering in to the contract (which was concluded by him accepting the ticket), he is not bound by them.

To quote

He was committed at the very moment when he put his money into the machine. The contract was concluded at that time. It can be translated into offer and acceptance in this way: the offer is made when the proprietor of the machine holds it out as being ready to receive the money. The acceptance takes place when the customer puts his money into the slot. The terms of the offer are contained in the notice placed on or near the machine stating what is offered for the money. The customer is bound by those terms as long as they are sufficiently brought to his notice before-hand, but not otherwise. He is not bound by the terms printed on the ticket if they differ from the notice, because the ticket comes too late. [cited from http://en.wikipedia.org/wiki/Thornton_v_Shoe_Lane_Parking_Ltd]

In my case, I believe the contract was entered in to when I signed the tenancy agreement (some time in August), and although I didn’t even receive the letter referring to the £35 fees, it was dated mid-September, and therefore came after the contract had been entered into (and as for the £15, there was no mention on that even in the letter detailing the £35 fee as far as I can tell).

Anyway, more updates to come soon :)

Posted in Reviews.

Tagged with , , , , , , , , , , .


South Lettings and South Residential Estate Agents — Nothing but trouble

Before I start this rant, I want to make clear that these views are my own, and do not necessarily reflect the views of my University.  While I’ve tried to ensure all facts are accurate, shamefully I’ve not been keeping a detailed log, so where possible please try to verify any claims with your own research, rather than just taking my at my word (i.e. please don’t try to libel me…).

I strongly advise anyone against renting from South Lettings (aka South Residential it would seem). Ever since I signed my contract with them I’ve had nothing but problems. They were incredibly slow in sending out my reference forms, in fact we only received them through email after much nagging, a couple of days before my tenancy began. Before I continue, I should note that when I first moved in to the property I was informed that the landlord was the current manager of the property, but South Lettings were taking over management of the building.

When looking around the flat I noted that there was electric heating, and I was informed that they were on a timer, upon moving in I discovered that the `timer’ was the Eco7 circuit, which turned the storage heaters on all night (off during the day), but the direct heat elements, when enabled, were on all the time (my electricity bill was £770 for 6 months, and I suspect a the heating contributed a large part towards that).  To their credit when people complained about the heating, they did arrange for an electrician to come over and demo how to use it efficiently.

When I moved in to my flat (which I was told would have been professionally cleaned before I moved in) the flat was filthy. The work surfaces in the kitchen were covered with plaster dust, as were the sofas, carpets and parts of the wall. I noticed there was an uncovered socket on the wall and reported it to the agents, then 6 months later (at the end of my tenancy) it was still uncovered.

The flat I was in was quite new, and I was informed that some workmen would come in to install a closing pump on the front door (which I agreed to). Upon returning from University later that day, I came home to find my front door unlocked and the flat unoccupied (with the new pump installed). Also, while I was living at the flat, there were some damp problems in the kitchen/living room, I informed the estate agent’s and a couple of days later I came home to find an electric fan heater plugged in to my wall set on full power, blasting air at my wall. The estate agents did not ask permission to use my electricity supply, and did not even inform me that that would happen, as I don’t know exactly how long the heater was running for before I came back, I have no idea how much it cost me.

Upon moving out, I spent the day cleaning the flat to make it look presentable, ready for the next day, when I would do the checkout with the agent. During the checkout, the agent noted a couple of spots on the kitchen work surface that I was told I needed to clean, otherwise they would have charged me for hiring professional cleaners (some spots behind the oven, and just to give the fridge shelves a wipe down). I told the agent that I didn’t have any cleaning products on me, but as she told me she had another checkout to do, I’d go down to the local shops, buy some cloths etc. then come and fetch her when I was done cleaning the flat.

When leaving the flat, we agreed that I wouldn’t be charged for any cleaning or damages, but the agent noted that there would be a £35 checkout fee that I was told was in my contract. I couldn’t recall any mention of a £35 checkout fee, but I didn’t mention it at the time, assuming that I had just forgotten about it.

After getting home and re-reading my contract I saw no mention of any fees. About a week later, I signed in to the deposit protection scheme website to find that they had charged me £58. When phoning the agents, I was informed that was £35 checkout fee, plus a £15 fee for the estate agent going back to check the flat, and then VAT on top of that.

After informing them that there was no mention of a £35 fee in my contract I was told that I was in fact told about it in a letter they sent to me (presumably after I had signed the contract). I had no recollection of this letter and asked them to send me a photocopy of it showing my signed agreement. About one month later, and having still not received this letter as I was promised, I phoned them up again.

It is also interesting to note that there’s no mention of the checkout fees on their website either (see the screenshot below).

No mention of the check out fees on the South Lettings Website.

While on the phone to them, I informed them that I would not be paying the fees as they “cannot charge me random fees without informing me of them first”, to which they replied “yes we can”. After having spoken to some solicitors, I’ve confirmed that no, they can’t.  I have just received a copy of the supposed letter via email, and I can confirm that I have never seen it before.

So if you want to avoid all of this hassle, I advise you against South Lettings, and South Residential, who seem to be the same company (at least they have the same director according to companies house).

The saga continues.

Posted in Reviews.

Tagged with , , , , , , .