Sunday, 21 July 2019

How an ECG is done ,How ECG signal is converted to Fourier series

I recently had a medical checkup that included an ECG (electro-cardiograph).
This is what my ECG looked like:
ECG
[Click the image for a larger view.]


ecg assembly ECG setup

The electrodes are connected to various parts of your anatomy (chest, legs, arms, feet) and voltage differences over time are measured to give the ECG readout.
The horizontal axis of the ECG printout represents time and the vertical axis is the amplitude of the voltage.
ecg - reference pulse
Amplitude units are millivolts (mV) and on the graph, 1 mV = 10 mm high.
The time scale is 25 mm = 1 second (or 1 mm per 0.04 seconds on the graph).
So here's my readout for Lead II, representing the voltage between the positive electrode on my left leg and the electrode on my right arm. Each thicker red vertical line represents a time of 1 second.
ECG II
Apparently (according to the doctor), this indicates my heart is quite healthy.
In more detail, the features of the repeated pulse we are looking at are as follows.
PQRST waves ECG
[Image source: T. Burke]
The P wave is caused by contraction of the right atrium followed by the left atrium (the chambers at the top of the heart).
The QRS complex represent the point in time when most of the heart muscles are in action, so has highest amplitude.
The T wave represents the polarization of the ventricles (the chambers at the bottom of the heart).
heart
Human heart showing atria and ventricles.
[Image by UCSD, source page no longer available]

Modeling the Heartbeat Using Fourier Series

A heartbeat is roughly regular (if it isn't, it indicates something is wrong). Mathematically, we say something that repeats regularly is periodic.
Such waves can be represented using a  Fourier Series.

Assumptions

In my case, my heart rate was about 70 beats per minute. For the sake of simplicity, I'll assume 60 beats per minute or 1 per second. So the period = 1 second = 1000 milliseconds.
Also for simplicity, I will only model the R wave for this article. To get a more accurate model for the heartbeat, I would just need to do a similar process for the P, Q, S and T waves and add them to my model.
I observed that my R wave was about 2.5 mV high and lasted for a total of 40 ms. The shape of the R wave is almost triangular and so I could have used straight lines for my model, but these don't give us a smooth curve (especially at the top - it must be continuously differentiable).
A better approach is to use a polynomial (where the ascending and descending lines are close enough to being straight), so my model is as follows (the time units are milliseconds):
f(t) = -0.0000156(t − 20)⁴ + 2.5
f(t) = f(t + 1000)

Explanation of the Model

The model is based on a quartic (power 4) since this will give me close to the shape I need (a parabola would be too broad). I'm using similar thinking to what I was doing in this article,  where I move a curve around to where I want it.
The (t − 20) term comes from deciding the curve should start at (0,0), (which makes our lives easier), it will pass through (40,0) since the pulse is 40 ms long, and be centered on t = 20.
The "+2.5" comes from the fact the amplitude of the pulse is 2.5 mV.
The -0.0000156 comes from solving the following for a when t = 0.
a(t − 20)⁴ + 2.5 = 0.
The "f(t) = f(t + 1000)" part means the function (pulse in this case) is repeated every 1000 ms.

Graph of the Model

This is the graph of part of one period (the part above the t-axis from t = 0 to t = 40):
ECG model
Of course. this is just one pulse. How do we produce a graph that repeats this pulse at regular intervals?
This is where we use Fourier Series.
I'll spare you all the details, but essentially the Fourier Series is an infinite series involving trigonometric terms. When all the terms are added, you get a mathematical model of the original periodic function.
To obtain the Fourier Series, wee need to find the mean valuea0, and 2 coefficient expressions involving nan and bn which are multiplied by trigonometric terms and summed for n = 1 to infinity.

Mean Value Term

a0 is obtained by integration as follows (L is half of the period):
{a}_{0}={\frac{{1}}{{L}}}{\int_{-{L}}^{L}}{f{{\left({t}\right)}}}{\left.{d}{t}\right.}
={\frac{{1}}{{500}}}{\int_{-{500}}^{500}}{f{{\left({t}\right)}}}{\left.{d}{t}\right.}
={\frac{{1}}{{500}}}{\int_{0}^{40}}{\left(-{0.0000156}{{\left({t}-{20}\right)}}^{4}+{2.5}\right)}{\left.{d}{t}\right.}
={0.16}
(The section of the curve we need for this part of the problem is from t = 0to t = 40, so that's why we chose those values for the limits of integration in the second last line.)

First Coefficient Term, an

Next, we compute an:
{a}_{n}={\frac{{1}}{{L}}}{\int_{-{L}}^{L}}{f{{\left({t}\right)}}}{\cos{{\frac{{{n}\pi{t}}}{{L}}}}}{\left.{d}{t}\right.}
={\frac{{1}}{{500}}}{\int_{-{500}}^{500}}{f{{\left({t}\right)}}}{\cos{{\frac{{{n}\pi{t}}}{{500}}}}}{\left.{d}{t}\right.}
={\frac{{1}}{{500}}}{\int_{0}^{40}}{\left(-{0.0000156}{{\left({t}-{20}\right)}}^{4}+{2.5}\right)}{\cos{{\frac{{{n}\pi{t}}}{{500}}}}}{\left.{d}{t}\right.}
The answer for this integral is pretty ugly. I've included it in the PDF solution. 

Second Coefficient Term, bn

Now for bn:
{b}_{n}={\frac{{1}}{{L}}}{\int_{-{L}}^{L}}{f{{\left({t}\right)}}}{\sin{{\frac{{{n}\pi{t}}}{{L}}}}}{\left.{d}{t}\right.}
={\frac{{1}}{{500}}}{\int_{-{500}}^{500}}{f{{\left({t}\right)}}}{\sin{{\frac{{{n}\pi{t}}}{{500}}}}}{\left.{d}{t}\right.}
={\frac{{1}}{{500}}}{\int_{0}^{40}}{\left(-{0.0000156}{{\left({t}-{20}\right)}}^{4}+{2.5}\right)}{\sin{{\frac{{{n}\pi{t}}}{{500}}}}}{\left.{d}{t}\right.}
Once again, I have spared you from the full details.
Finally, we put it all together and obtain the Fourier Series for our simple model of a heart beat:
{f{{\left({t}\right)}}}={\frac{{{a}_{0}}}{{2}}}+{\sum_{{n}={1}}^{\infty}}{a}_{n}{\cos{{\frac{{{n}\pi{t}}}{{L}}}}}+{\sum_{{n}={1}}^{\infty}}{b}_{n}{\sin{{\frac{{{n}\pi{t}}}{{L}}}}}
{f{{\left({t}\right)}}}={\frac{{0.16}}{{2}}}
+{\sum_{{n}={1}}^{\infty}}{\left(\frac{1}{500}{\int_{0}^{40}}{\left(-{0.0000156}{{\left({t}-{20}\right)}}^{4}+{2.5}\right)}{\cos{{\frac{{{n}\pi{t}}}{{500}}}}}{\left.{d}{t}\right.}\right)}{\cos{{\frac{{{n}\pi{t}}}{{500}}}}}
+{\sum_{{n}={1}}^{\infty}}{\left({\frac{{1}}{{500}}}{\int_{0}^{40}}{\left(-{0.0000156}{{\left({t}-{20}\right)}}^{4}+{2.5}\right)}{\sin{{\frac{{{n}\pi{t}}}{{500}}}}}{\left.{d}{t}\right.}\right)}{\sin{{\frac{{{n}\pi{t}}}{{500}}}}}
When we graph this for just the first 5 terms (n = 1 to 5), we can see the beginnings of a regular 1-second heart beat.
ECG model n=5
The above graph shows the "noise" you get in a Fourier Series expansion, especially if you haven't taken enough terms.
Taking more terms (this time, adding the first 100 terms) gives us the following, and we see we get a reasonable approximation for a regular R wave with period 1 second.
ECG model
I added the T wave for this next model (in blue).
ECG model
I used a parabola for the T wave because the shape of the T wave is broader than the shape of the R wave.
We could keep going, adding the P, Q and S waves to get an even better model.

What have we done?

We have taken a single spike representing one R wave of my heartbeat. We then found a formula that repeats our spike at regular time intervals. The Fourier Series (an infinite sum of trigonometric terms) gave us that formula.
Finally, we added the T wave, using the same theory as before.
Fourier Series is very useful in electronics and acoustics, where waveforms are periodic.

Deduction for Rent paid 80GG




It is generally understood that only salaried employees receiving House Rent Allowance from their employers get a tax benefit in respect of rent paid. However, Section 80GG of the Income-Tax Act, 1961 provides deduction for rent paid for accommodation by other tax payer as well wherein the least of the following is allowed as a deduction:

# Rent Paid minus 10% of the total income

# Rs 5,000 per month

# 25% of the total income

However, it is pertinent to note that one cannot claim this benefit in case either one’s spouse / minor child / HUF owns a house at the place of employment/ business/ profession or himself owned a house at any other place which is occupied by him.

Further, you are required to submit a declaration in Form 10BA along with your income tax return to claim this benefit.

2. Deduction for qualifying donations u/s. 80G of the Act

Many employers do not provide tax deduction for donations given by their employees at the time of deducting tax at source on salary. However, there is no restriction in the Act for claiming deduction at 50%/ 100% of donation amount depending upon the approval granted to the institution to whom the donation is made.

Deductions in respect of donation amount exceeding Rs 2,000 will be available if the amount is paid through banking channel. One will also be required to furnish the Name, Address and PAN of the institution to whom the contribution is made in the ITR.

3. Deductions under Chapter VIA missed out in Form 16

In an event you being a salaried employee were not able to submit all the documentary evidences related to deductions u/s 80C, 80CCD, 80D etc. to your employer which has resulted into excess tax being deducted by your employer, you still have the chance to claim benefits of such investments. The only thing you are required to do is disclose the correct investment amounts in your income tax returns which will enable you to claim the refund of the excess tax deducted even though it has not been considered by your employer in the Form 16.

Similarly, Section 80TTA of the Act provides a deduction of up to Rs 10,000 for interest earned on savings bank / post office savings account by individual taxpayers and only the excess amount is chargeable to tax.

4. Carry forward and Set off of losses:

Although the stock market had been on a roll during FY 2017-18, some tax payers may also have suffered losses in their share trading / investment activities. In order to carry forward any losses other than loss under the head “income from house property” to subsequent years, it is necessary to file the income tax return on or before the due date so that set off can be claimed in the subsequent years. The loss under the head “income from house property” can be carried forward even in case of belated return.

Similarly, tax payers can also set off brought forward losses of earlier years against the income of the current year as per the applicable provisions of the Act. For example, brought forward short-term capital loss can be set off against the current year’s long-term and short-term capital gain, brought forward long-term capital loss can be set off only against current year’s long term capital gain and similarly brought forward house property loss can be set off against current year’s house property