]]>2015-11-17T17:34:37+03:00http://nazarovsky.ru/2015/11/17/python-script-to-download-gost-from-protect-dot-gost-dot-ru-as-a-pdf-fileUnfortunately the Russian database of the national standards (GOSTs) does not enable to get files as .pdf , but only as separate images (which are even not directly available).
So we can’t even download the texts, it’s a pity. I’ve made a simple Python script to address this problem, because it’s far better to read and explore a printed copy.
Script uses some libraries, you can install them by running pip install img2pdf pypdf2 requests
It was tested in Python 2.7.

]]>2015-08-11T14:13:34+03:00http://nazarovsky.ru/2015/08/11/fixing-windows-from-bsod-stop-7b-0x0000007b-after-a-motherboard-replacementAfter the motherboard replacement I’ve got a blue screen of death (BSOD). This can happen after hard disk replacement also.
I’ve used the recipe from here
to recover from this failure.

Boot to the Recovery Console (F8 > Repair Your Computer) or from a system repair/Windows 7 disc.

Launch the command prompt.

To determine the name of the USB Flash disk you can use wmic logicaldisk get name,description

Change directory to the root of USB disk, e.g cd E:\

Run the script cscript fix_7hdc.vbs /enable /search

]]>2015-02-26T13:12:04+03:00http://nazarovsky.ru/2015/02/26/how-to-effectively-convert-books-from-djvu-to-pdfDJVU is a very good, although not very portable format for books and documents.
PDF is less efficient in compression, but is far more popular and portable. You can easily find
a free PDF reader for any system, for example for iPhone or iPad, but opening and reading DJVU is harder.

But you can always quiclky export DJVU to PDF and then use your favourite PDF reader program. On the iPad I use GoodReader and FoxitReader.

5 - You can also convert books from the command line (good for batch procesing)

command line DJVU to PDF conversion (B & W mode good for most of the books)

1

ddjvu.exe -format=pdf -mode=black -quality=75 infile.djvu outfile.pdf

]]>2015-02-25T17:36:25+03:00http://nazarovsky.ru/2015/02/25/powers-according-to-ieee1459Definitions of electric power qualities under nonsinusoidal conditions are quite complex and hard to grasp.
Annex B of the IEEE Std 1459-2010 shows how to calculate apparent power components in non-sinusoidal conditions. I have written a MATLAB script to illustrate this example. Unfortunately, there were typo errors in the standard, that’s why some of the values are different in my example.

It is learned from this expression that every component of $ S $ contributes to the total power loss in the supplying system. This means that not only fundamental active and reactive powers cause losses but also the current and voltage distortion powers as well as the harmonic apparent power cause losses.

The following numerical example is meant to facilitate the understanding of the previous explanations:

The total harmonic active power $ P_H =P –27.47 W < 0 $ is supplied by the load and injected into the power system. This condition is typical for dominant nonlinear loads. The bulk of the active power is supplied to the load by the fundamental component $ P_1 = 8660.25 W$ .

Of interest is the fact that $ Q_5 < 0$ , whereas other reactive powers are positive. If one incorrectly defines a total reactive power as the sum of the four reactive powers (in accordance with C. Budeanu’s definition):

\[
Q_B = Q_1 +Q_3 +Q_5 +Q_7 = 4984.67 \, var
\]

and assumes that the supplying line has a resistance $ r= 1.0 \, \Omega $ and the load is supplied with an rms voltage $ V=240 V $, the power loss due to $ Q_B $ in line is

The reactive power $ Q_5 $ , despite its negative value, contributes to the line losses in the same way as the positive reactive powers. The fact that harmonic reactive powers of different orders oscillate with different frequencies reinforces the conclusion that the reactive powers should not be added arithmetically (as recommended by Budeanu).

The cross-products that produce the distortion powers $ D_I $ and $ D_V $ are given in Table 3.

The apparent power and its components are represented in the following tree:

Figure 2 — Apparent power and its components tree

The fundamental power factor (displacement power factor) is $ PF_1 = P_1 / S_1 =0.866 $, and the power factor is $ PF= P/S=0.821 $ . The dominant power components are $ P_1 $ and $ Q_1 $ . Due to relatively large distortion, $ S_N $ is found to be a significant portion of $ S $, and the current distortion power $ D_I $ is the dominant component of $ S_N $ .

]]>2014-10-13T11:35:13+03:00http://nazarovsky.ru/2014/10/13/how-to-evaluate-voltage-unbalance-using-symmetrical-components-methodTo evaluate voltage unbalance we can use Symmetrical components method proposed by Charles Fortescue.
Vector of three phase voltages can be expressed as a sum of three vectors (phasors): zero- positive- and negative-sequence.

Here is MATLAB script that produces the desired level of both negative- and -zero voltage unbalance ratio, then sets respective phasor magnitudes.
After that we estimate unbalance using Symmetrical components method and draw a phasor diagramm.

To generate signal with known level of unbalance $K_{2U}$ we can change magnitude of one of the voltages in the balanced three phase system.
So we set all angles between voltages = 120 deg. Magnitudes of Ua and Uc should be equal (Ua=Uc). Ub should be set as

]]>2014-09-01T12:12:40+03:00http://nazarovsky.ru/2014/09/01/drawing-horizontal-and-vertical-lines-in-matlab-plotOften we need to draw a vertical or horizontal line across the plot, to mark the boundaries or min/max value of the function. It’s not obvious at the first glance how to do it, becase the X and Y limits can be different, and also we need to handle zoom commands.
I’m now using the solution, based on graph2d.constantline which was found hereDrawing horizontal and vertical lines in MATLAB plot

MATLAB functions that export values into a .CSV file are very slow. It is said, that their inefficiency is rooted in bad implementation of the string concatenation.
It is refered as Schlemiel the Painter’s algorithm.

Nevertheless, sometimes I have to write huge amounts of text data into CSV files. For example I had to generate test signals for power quality measurements algoritms, such as Flicker estimation.
So I had written a MEX function to speed up this task. Write process can also be interrupted by pressing Ctrl-C using this wonderful trick (http://www.caam.rice.edu/~wy1/links/mex_ctrl_c_trick/).

As you can notice difference in speed is huge! On big files ~ 1GB in size, write speed values are about 17-18 Megabytes/s.

You can use it freely, I hope it will save you a lot of time.

]]>2014-08-18T08:47:28+03:00http://nazarovsky.ru/2014/08/18/using-coursera-dl-to-download-lecture-videos-and-materials-from-coursera.orgI use Coursera-dl to download lecture videos and materials from Coursera, so I can watch them later after the course is finished.
How to install coursera-dl on Windows machine? It’s easy.

1.First of all you need to download Python 2.7 (don’t download Python 3, it is a different and incompatible version)
from Python download page.

In the command line change directory to pip (C:\Python27\Scripts for my case)

execute pip install coursera-dl

4.Now you are ready to download materials! For this you need the class name identificator from the browser URL.

Provide your user name and password, directory to download and class name identificator as the parameters into coursera-dl script.
Don’t forget, that you have to accept the honor code of the class before using this script (happens the very first time you go to the class page).

Sample command line to download Coursera materials for current Machine Learning class

1

coursera-dl -u myusername -p mypassword -d C:\Coursera\ ml-006m

]]>2014-08-12T08:48:42+03:00http://nazarovsky.ru/2014/08/12/how-to-draw-pentagram-in-matlab-in-one-simple-stepToday I shall teach you how to draw pentagrams in MATLAB. Just in case, if suddenly a wild demon will appear before you. Remember, it is super effective!
Venerate the power of the complex exponent!

1

plot(fft(eye(5)*-1j),'r');axissquare

]]>2014-08-07T11:05:48+03:00http://nazarovsky.ru/2014/08/07/quick-typing-of-math-symbols-using-numeric-keyboard-and-autohotkeyI’m using Autohotkey for keyboard input automation tasks in Windows, like typing repeating sequences of words and so on.
I want to share piece of code to automate math symbol input.

There are many math symbols with codes I am too lazy to remember, but I have to use them often.
When I am writing tech reports, specifications and requirements, I frequently have to type in characters like δ or σ².
I commonly use Microsoft Word for writing, because workflow there is so much faster than in LaTeX.
Yeah, I know the benefits of the latter, but in my opinion LaTeX is more suitable for big documents and for publishing, than for daily usage.
By the way, Office 2010 supports LaTeX markup in the Formula Editor. But using formulas is an overkill to type for example a degree symbol ° or plus-minus sign ±.
So I’ve written a script, which uses numeric keys for fast typing of math symbols. Key NumPlus is used as a selector key. For example if I want to enter ± sign
I press on numeric keyboard (+) , then (-), then release both keys.

]]>2014-08-03T16:19:24+03:00http://nazarovsky.ru/2014/08/03/octopress-installation-tips-and-tricks
I decided to use Octopress as a static blog generator, because I’ve got tired of Wordpress database mumbo-jumbo. I was seeking for a simple and reliable way to blog, and also I wanted markdown, version control, and LaTeX support, and code highlighting, etc, etc.
In Octopress we have many of these nice features out of the box. And you can tweak it further, if you wish. “If you want a thing done well, do it yourself.” - I’ve thought and decided to try Octopress.
Version control is maintained by git and pages are static html, i.e. they are not using any database. You can also use any text editor, that you prefer. Octopress also supports markdown syntax, which is clean and simple.

After installation I wanted to remove additional blog part in the URL’s. How to do that is described here as well, as some good SEO hacks for Octopress.

File uploading is done via rsync. To use rsync I’ve had to install cygwin (Yep, I’m Windows guy) from here and add it to the PATH variable.

UPD 08.08.2014 There is faster way to install rsync in Windows. You should use cwRsync - I have simply unzipped an archive to %RUBY%/bin folder

Unfortunately, rsync uploaded the files, but did not change the file attributes.
I’ve found that rsync can set permissions on files. How to do this is described here
Modify Rakefile as described below, so that after rsync directories will have permission 755 and files will have permission 644

1

rsync_args = "--chmod=Du=rwx,Dg=rx,Do=rx,Fu=rw,Fg=r,Fo=r"

To add LaTeX support for math equations I used Mathjax. Read more here.

Now I can write cool equations like this
$ e^{i \varphi} = \cos{\varphi} + i \sin {\varphi} $

]]>2014-08-03T13:23:51+03:00http://nazarovsky.ru/2014/08/03/welcome-to-my-new-blogHello, everyone and also my dear friends. I’ve decided to start a new blog in English, because I need practice in writing and also I want the materials to be accessible for broader audience.

I think that I shall write here mostly on engineering topics, but as usual, things can change.