AMAT 415 — Midterm 2 practice solutions

Here they are: pdf

Posted in Uncategorized | Leave a comment

AMAT 415 — Assignment 3 solutions

Here they are: a3solns

As usual, please report any errors, typos, etc.

Posted in Uncategorized | Leave a comment

AMAT 415 — Week 9 problems

50) Find the z-transform of the sequence x=(\ldots,0,0,\overset{\downarrow}1,0,1,0,1,0,\ldots). (Give a closed-form expression.)

51) Let x be as in the previous problem.

  •  Find two signals u and v such that u*v=x.  (You might consider letting u be a \delta-spike.)
  • If u=\delta_m, can you find a v such that u*v=x?
  • Can you a solution with causal signals find u and v such that both u and v have infinitely many nonzero components and u*v=x?  (You might consider z-transforms for this last part.)

52) Find a simple expression for \mathcal{Z}(x), where

\displaystyle{x=(\ldots,\frac{1}{4!},\frac{1}{3!},\frac{1}{2!},\overset{\downarrow}1,1,1,1,\ldots)}.

53) Show that the z-transform of the sequence

\displaystyle{x=(\ldots,\frac{1}{8},\frac{1}{4},\frac{1}{2},\overset{\downarrow}1,1,1,1,\ldots)}

is \displaystyle{\frac{-z}{(1-2z)(1-z)}}.

(Problems 52 and 53 are from Chapter 5.1 of Transform methods in applied mathematics, by Lancaster and Salkauskas.)

Posted in Uncategorized | Leave a comment

Matlab activity 7: Sliding FFTs

Our previous MATLAB activities have dealt primarily with the study of periodic signals. The theory of Fourier series tells us that periodic signals can be represented as sums of the simplest kinds of periodic signals — sines and cosines.

This makes less sense for aperiodic signals, the signals we’ve began studying last week. To see this, let’s look at an example:

t=1/4096:1/4096:1;
f1 = 300;
x=cos(2*pi*f1*t.^2);
plot(t,x)

(Note the t.^2 inside the cosine.) A cosine wave of (constant) frequency f is given described by the equation x=\cos(2\pi\cdot f\cdot t). The function x=\cos(2\pi\cdot t\cdot t) is a cosine function of “variable” frequency. Near t, it’s frequency is roughly t. (Such a sound is called a “chirp”. There is actually a MATLAB command chirp that makes these kinds of signals.) Take a look at some “zoomed in” plots:

x1=x(2000:2199);
plot(x1);
hold on;
x2=x(3000:3199);
plot(x2,’red’);
x3=x(3897:4096);
plot(x3,’green’);

(Maybe try looking at them on separate plots too.) These look more like standard sinusoids. Approximately what are their frequencies?

If these zoomed in pieces of the signal x do indeed behave like sinusoids, then their FFTs should gives sharp spikes close to their frequencies. Do they?

X1=fft(x1);
X2=fft(x2);
X3=fft(x3);
hold off;
hold on;
plot(abs(X1))
plot(abs(X2),’red’);
plot(abs(X3),’green’);

Compare these plots with that of the FFT of the entire signal x:

hold off
X4=fft(x);
plot(abs(X4));

What is this plot trying to tell us? A lot of frequencies seem to be present. The spectrum is spread out between frequencies of 0 and like 900 cycle/second, where there is a steep dropoff. (This is sort of strange because our “variable frequency cosine wave” has frequency varying between 0 and 300 cycles/second.) From the plot in the time domain (the plot of x vs t), we saw that x oscillates very slowly near t=0 and that the rate of oscillation increases as t increases. This information cannot be read off this last plot. (At least I don’t see how to do it…)

The FFT is a great tool for reading off information about the frequency domain composition of signals so long as this composition isn’t varying too quickly. This means we should only perform FFTs on relatively short time intervals. Since our “variable frequency cosine wave” has its frequency varying between 0 and 30, and we know we should always sample at more than two times as great as the highest frequency component, let’s do FFTs of length 256=2^8. The simplest thing to do is to break our signal up into 16=length(x)/256 blocks of 256 samples, take the FFT of each, and “assemble the results”.

A = zeros(256,16);

for k = 1:16
xx = x((k-1)*256+1:k*256);
A(:,k)=fft(xx);
end

image(abs(A’))

The vertical axis along the bottom tells us which block’s FFT we’re looking at. The horizontal axis is frequency (scaled in a strange way, let’s not bother with that for the moment.) The color intensity indicates the strength (or amplitude or volume) of a given frequency within a given block. You should see a bright line sloping downwards from the top left and another one sloping downwards from the top right. The brightness indicates that our signal contains a dominant frequency component that is increasing as we move from block to block, i.e., as time progresses. This is the behavior we expect from our variable (increasing) frequency cosine wave. (The bright line sloping downwards from the top left comes from the symmetry of the Fourier transform. It gives no new information.)

This picture is still very rough, and it’s tough to read quantitative information off of it. First, the resolution is a little grainy because we only have 16 blocks along the horizontal axis. We can remedy this to an extent by allowing out blocks to overlap: Instead of our first FFT being samples 1 to 256, our second being 257 to 512, etc., we instead slide along our FFT window of length 256 by a smaller increment each time: Our first FFT would still be calculated from samples 1 to 256, but our second may be say from 128 to 384, and the third from 256 to 512, … I won’t make you code this process by hand. MATLAB has a built in function for exactly this: spectrogram. (The picture it gives you is also called a spectrogram.) Here’s the syntax:

spectrogram(x,256,128,256,4096)

(Note that the spectrogram has the axes interchanged: It has frequency on the horizontal axis and time on the vertical.) The first 256 is the “window” which for us at the moment is the same as the other 256, just the length of the FFT (the number of samples used to compute it). 128 is the overlap between each successive FFT. Thus, as stated there is 50% overlap between each FFT. 4096 is the sampling rate — just the length of x since our t ran from 0 to 1. Play around with the parameters and see what happens.

Try a different x:

x=cos(2*pi*f1*t.^3);
spectrogram(x,256,128,256,4096);

In the next weeks, we’ll touch on a few ways to optimize these spectrograms — make them smoother, have better resolution, less noise, etc. But for now I just wanted to introduce the notion. The spectrogram is one of the most useful and pervasive methods for visualizing frequency composition of aperiodic signals. The key is that it shows three parameters simultaneously — time, frequency (frequencies present in the signal at a given time) and intensity/amplitude/power of the signal.

The takeaway sentence from this exercise is: Since frequency composition of aperiodic signals is roughly constant over short enough time intervals, we can use our tools (FFT) for analyzing periodic signals — those whose frequency composition is constant over long intervals — in blocks for analyzing aperiodic signals.

Posted in Uncategorized | 1 Comment

AMAT 415: Assignment 3

Please submit the following problems: 28, 33, 38, 42, 47.

And: In MATLAB activity 6, you investigated the function \log(1+e^z) graphically. Along which line segments is \log(1+e^z) discontinuous? Explain why.

Each problem is graded out of 2 points.

Posted in Uncategorized | Leave a comment

AMAT 415 — Matlab activity 6: Complex logarithms

If x is a real number, then \log(x) is an unambiguously defined real number if x>0. One reason for this is that \log(x) is the inverse function of e^x, an increasing and therefore one-to-one function.

In the complex realm, \log(z) is not well defined, echoing the fact the function e^z is not one-to-one. (It’s periodic with period 2\pi i and thus \infty-to-one.)

To unambigiously define a complex logarithm, we must choose an interval (\theta_0-\pi,\theta_0+\pi] in which to measure the angles of complex numbers: If z\in\mathbb{C}, then there is a unique \theta\in (\theta_0-\pi,\theta_0+\pi] such that z=|z|e^{i\theta}. We can define a branch of logarithm subordinate to this choice by the rule \log(z)=\log|z|+i\theta. Although defined for all nonzero z, this branch of the logarithm is discontinuous along the ray z=re^{i(\theta_0\pm\pi)}, r>0.

A standard choice is \theta_0=0, putting \theta in (-\pi,\pi], and this is what MATLAB uses when computing logarithms using the command log. To “see” the discontinuity of this branch of the logarithm along z=re^{i\pi}=-r, r>0 — the negative real axis — try this:

>> h = 0.01;
>> x = -3:h:3;
>> A = ones(1,length(x))’*x;
>> B = A+i*A’;
>> C = log(B);
>> m = -min(min(imag(C)));
>> image(x,x,10*(imag(C)+m)); % We can’t plot a complex function of a complex variable!

How is does the discontinuity manifest itself on the picture? Is the discontinuity evident from the following plots? Why or why not?

>> image(x,x,10*(real(C)+m));
>> image(x,x,10*(abs(C)+m));

Since the logarithm function is discontinuous, functions defined in terms of it will also tend to be discontinuous. Let’s look at f(z)=\log(e^z+1), for example.

>> x = -10:h:10;
>> A = ones(1,length(x))’*x;
>> B = A+i*A’;
>> C = log(exp(B)+1);
>> m = -min(min(imag(C)));
>> image(x,x,10*(imag(C)+m));

What do you conclude from this picture about the location of the discontinuities of f(z)? Try to confirm your claim theoretically. What if you replace imag by angle in the above snippet? What do you observe? Can you “explain” your observations?

Since the logarithm comes in many branches, so do functions that are defined using the logarithm, e.g., power functions: g(z)=z^s, z\neq 0, s\in\mathbb{C}. Here, z^s is defined to be e^{s\log(z)} where, implicitly, we have chosen a branch of \log(z). (This choice of branch doesn’t matter when $s$ is an integer. Why?) Let’s consider the case s=1/2.

>> x = -3:h:3;
>> A = ones(1,length(x))’*x;
>> B = A+i*A’;
>> C = exp(1/2*log(B));
>> m = -min(min(imag(C)));
>> image(x,x,10*(imag(C)+m));

So g(z)=z^{1/2}=\sqrt{z} is discontinuous along a ray. Thought question: Without mentioning logarithms, can you explain why a square root function cannot be continuous on the entire complex plane? You might want to consider how square roots behave on the unit circle.

Here another fun one:

>> C = log(1/2*(B.^2-1));
>> m = -min(min(angle(C)));
>> image(x,x,10*(imag(C)+m));

Can you explain the discontinuities?

FOR 2 BONUS POINTS ON ASSIGNMENT 3: There is a branch of the logarithm making h(z)=\sqrt{z^2-1} continuous (and analytic) on \mathbb{C}-\{x\in\mathbb{R}: |x|\geq 1\}. Which one is it? Justify your answer.

Posted in Uncategorized | 1 Comment

AMAT 415 — Week 8 problems

40) Find the first 5 terms of the Taylor series of f(z)=e^z\sin(z) around z=0.

41) Find the Taylor series of f(z)=\sin(z+\pi/4) around z=0. (Suggestion: Use the identity \sin(x+y) = \sin(x)\cos(y) + \cos(x)\sin(y).)

42) Find the first four nonzero terms in the Taylor series of

\displaystyle{f(x)=\frac{(\cos(x)-1)^2}{x^4}}

around z=0.

43) Find the Taylor expansion of

\displaystyle{f(x)=\frac{1}{(z-1)^2(z-2)}}

around z=0. (Suggestion: First do a partial fraction decomposition.)

44) Find the Taylor expansion of

\displaystyle{f(x)=\frac{1}{(z+i)^2}}

around z=i.

45) Find the first 5 nonzero terms in the Laurent expansion of 1/\sin(z) around z=0.

46) Find the terms of nonpositive index in the Laurent expansion of

\displaystyle{f(x)=\frac{e^z+1}{(z^2-1)^2}}

around z=1.

47) Find the points where

\displaystyle{f(x)=\frac{1}{z^3(z+4)}}

is singular (i.e. not analytic). Find its residues at those points.

48) Same as the previous question, but with

\displaystyle{f(x)=\frac{1}{z^3-3}}.

49) Same as the previous question, but with

\displaystyle{f(x)=\frac{e^z}{z(1-z)^3}}.

Posted in Uncategorized | Leave a comment

AMAT 415 — Tutorial 6 activity

Here is the activity: pdf

Rejoice! I couldn’t think come up with a worthwhile MATLAB-centric activity relevant to what we’ve been doing lately in class. But MAPLE or MATHEMATICA might come in handy…

Posted in Uncategorized | Leave a comment

AMAT 415 — Weeks 6 & 7 problems

Please report typos and errors by email.

28) Find all the solutions of \cosh(z) = i.  (Hint: Rewrite the equations in terms of exponentials and manipulate it into a quadratic equation in the variable e^z.)

29) Suppose f(z) is analytic on \mathbb{C}.  Let g(z)=f(\bar{z}).  For which z is g(z) analytic? (Hint: Use the Cauchy-Riemann equations.)

30) Suppose f(z) is analytic on \mathbb{C}.  Let h(z)=\overline{f(\bar{z})}.  For which z is h(z) analytic?

31) Find a function v(x,y) such that v(0,0)=2 and f(z)=x^3-3xy^2+iv(x,y) is analytic.

32) Sketch and describe in a few words the paths \gamma(t)=1+\cos(t) + i\sin(t), t\in [\pi/2,\pi], and \gamma(t)=2\cos(t) + i\sin(t), t\in [0,\pi].

33) Evaluate \int_\gamma xdz, where \gamma is the union of the line segments joining 0 to i and then i to i+2.

34) Evaluate \int_\gamma e^z dz, where \gamma is the part of the unit circle joining 1 to i in a counterclockwise direction.

35) Evaluate \int_\gamma \frac{1}{|z|}dz, where \gamma is the unit circle traversed counterclockwise.

36) In class, we showed that \int_\gamma \frac{1}{z}dz=2\pi i, where \gamma(t)=e^{2\pi i t}, t\in [0,1].  Identify the flaw in the following argument:  Since \log(z) is an antiderivative of 1/z, the fundamental theorem of calculus implies that \int_\gamma \frac{1}{z}dz=\log(\gamma(1))-\log(\gamma(0))=1-1=0.

37) Evaluate \int_\gamma \frac{1}{z-i}dz where \gamma is the circle centered at z=0 with radius 3. (Hint: Deform the path \gamma into a more convenient one.)

38) Evaluate \int_\gamma\frac{1}{(z-1)^3}dz, where \gamma is the (a) circle or radius 1/2 centered at z=0; (b) the circle of radius 1/2 centered at z=1; (c) the circle of radius z=1/2 centered at z=-1.

39) Let

\displaystyle{f(x)=\begin{cases} x^2\sin(\frac{1}{x})&x\neq 0,\\ 0&x=0\end{cases}}.

Show that

\displaystyle{f'(x)=\begin{cases} 2x\sin(\frac{1}{x})-\cos(\frac{1}{x})&x\neq 0,\\ 0&x=0\end{cases}}.

Conclude that f' is not continuous at x=0. (Hint: Use the definition of the derivative to compute f'(0).) Challenge: Adapt this exercise to construct a function such that f'(x), f''(x), \ldots, f^{(n)}(x) exist but such that f^{(n)}(x) is discontinuous at x=0.

Posted in Uncategorized | Leave a comment

AMAT 415 — Matlab activity 5: Downsampling, upsampling and interpolation

(As usual, please report errors or typos by email.)

Let’s plot the cosine wave of frequency 60 Hz, sampled 1000 times per second for 1 second:

t = 0:0.001:1-0.001;
x = cos(2*pi*60*t);
plot(t,x);

(Maximize your figure window if the graph is to squooshed.) Now let’s plot the same wave, sampled at 200 times per second for one second. There are two ways to do this. One way is to proceed as above:

tt = 0:0.005:1-0.005;
xx = cos(2*pi*60*tt);
plot(tt,xx);

Alternatively, MATLAB builds in functionality to downsample by a factor of n, i.e., to keep 1 out of every n samples
starting with the first one. We want 200=1000/n, so n=5.

tt = downsample(t,5);
xx = downsample(x,5);
plot(tt,xx);

To compare the graphs, it helps to plot them one below the other. To do this, type:

subplot(2,1,1);
plot(t,x);
subplot(2,1,2);
plot(tt,xx);

(Look up subplot in the online help for an explanation of the syntax.)
The graphs look pretty similar, at least in the sense that both graphs seem to be displaying waves of the same frequency. So it seems that we didn’t lose that much information by downsampling by a factor of 5.

Now let’s see what happens when we downsample by a factor of 10:

xx = downsample(x,10);
tt = downsample(t,10);
subplot(2,1,2);
plot(tt,xx);

Now the graphs look significantly different. If you count the peaks (local maxima) on the downsampled graph — both the sharp ones and the squared off ones — you should count 40 of them. This doesn’t sound right for a cosine wave that’s supposed to have frequency 60 Hz. The problem here is aliasing. Since 60 (frequency of wave) > 100/2 (half the sampling rate), our wave is aliased with one of frequency 100 – 60 = 40 Hz. The aliasing can also be seen in the frequency domain.

y = fft(x);
yy = fft(xx);
subplot(1,2,1);
stem(0:99,abs(y(1:100))/1000); % just plotting frequencies up to 100 to make the picture clearer
subplot(1,2,2);
stem(0:49,abs(yy(1:50))/100);

Note the locations of the spikes. In summary: For applications like data compression, it is often desirable to downsample a signal. When doing this, you need to be aware of the aliasing phenomena that can creep in.

The process opposite to downsampling is upsampling — increasing the number of samples/second of a prerecorded signal.
Upsampling is closely related to (and sometimes used synonymously with) interpolation.

Close the figure window to start fresh.

Suppose we sample a signal 20 times per second and obtain the following:

x = [-4.0000,
5.2802,
-6.5403,
3.3084,
2.2331,
-3.0000,
4.0872,
-0.2183,
-1.6862,
-0.4261,
2.0000,
-6.8983,
5.9223,
-2.6904,
-0.6151,
5.0000,
-2.4692,
0.8363,
1.0682,
-1.1919];

Make x a row vector:

x = x’;

How might we fit a curve to this data set? How can we “connect the dots” in the stem plot in a reasonable way? The output of

plot(0:0.05:0.95,x);

isn’t very satisfying — too jagged. Upsampling gives a way. Try:

xx = upsample(x,5);
stem(xx);

What we’ve just done is just upsampled x by a factor of 5, i.e., stuck 4 zeros between each component of x. The plot doesn’t look any better than the last one, though. But now let’s pass to the frequency domain. First, we examine the spectrum of our original signal x:

y = fft(x);
subplot(1,2,1); % we’ll add another plot below
stem(0:19,abs(y));

The plot suggests that our signal is a superposition of sinusoidal components of frequencies 2, 7, and 9 Hz. (Recall that we can only resolve frequencies less than half the sampling rate, in this case 10=20/2.)

Now let’s examine the spectrum of the upsampled signal xx:

yy = fft(xx);
subplot(1,2,2);
stem(0:99,abs(yy));

What do you observe? (Maximize the figure window if the plot is to squooshed.)

The spectrum is a bunch of (5, actually) copies of the spectrum of the original signal lined up. If we kill the extra copies, we’re left with the spectrum of our original signal, but at a higher resolution.

w =1;

The inverse Fourier transform of w.*yy interpolates x nicely:

z = ifft(w.*yy); % this is the same as the convolution of xx with ifft(w)
plot(0:0.01:0.99,5*real(z),’red’);
hold on;
stem(0:0.05:0.95,x);

So we have found a “nice” smooth curve interpolating the data set x using Fourier analysis.

This is an illustration of a standard method for recovering a continuous signal from a sampled version. This method is the content of the famous Shannon Sampling Theorem. Time permitting, we’ll talk a bit about that towards the end of the course.

FOR 2 BONUS POINTS ON HOMEWORK 3: In the last snippit of code, I’m plotting 5*real(z) as opposed to just z. Can you explain the presence of this correction factor conceptually? (“Because it makes the picture look right” is not sufficient.)

  1. 1:100) < 21);
    stem(0:99,w.*abs(yy []
Posted in Uncategorized | 1 Comment