lab2

a) find the FT [F(w)] of f(t) = exp(-(t^2)/Z) where Z = 4
hint multiply f(t) by exp(-w^2)*exp(w^2) = 1
plot this function.[w:rad/s][t:s]

ans = F(w) = 2*exp(-w^2)

b) f[n] = f(Ts*n) where n is an integer and Ts is a constant.
write an equation for the DTFT of f[n] in terms of F(w);

c) g(t) = f(t-50) for 0<=t<=100
write a progam to sample g(t) in the range of 0<=t<=100
with the sampling rate Fs = 3 Hz to get gs[n]
calculate the DFT of this vector. Gs[k] = DFT(gs[n])
To do this use the octave command Gs = fft(gs)
plot Gs (the magnitude of Gs).
Explain (in words) how F(w) and Gs[k] and the DTFT of f[n} are related. be sure to address the complex nature
Gs and include concepts of aliasing in time and frequency in your discussion.

try varying the function f(t) by varying Z (try values ranging from 0.1 to 100). what do you observe?

d)Zero Padding in time: write a script to generate:

gszt[n] = gs[n] 0<=n<=300; 0 for 300 < n <= 900

compare the magnitude of Gszt[k] = fft(gsz) to that of Gs[k].
what is the effect of zero paddingin time?

f) Zero Padding in Frequency: write a script to generate:

Gszf[n] = Gs[n} for 0<=n<=150; 0 for 150 < n <=750; Gs[n-600] for 750<n<=900;

compute gszf = ifft(Gszf) to get the corresponding time domain signal.
compare the magnitude of gszf[n] to gs[n].
what is the effect of zero padding in frequency?

g) Insert two zeros after each sample in gs[n] and take the fft of this sequence.
How does this type of interpolation affect the signal properties in the frequency domain.
Discuss how this would change if one zero was inserted instead of two.

h) Windowing: using the following signal

for j = 1:1000
        x(j) = sin((j-1)*2*pi/200);
endfor

window the signal using a square window:
xsw[n] = x[n].*sw[n] where sw = 1 for 251<=n<=750; 0 otherwise;
(note: ".*" is point-wise multiplication)

window the signal using a hanning window
xhan[n] = x[n].*hw[n]

where hw is generated by
xhan=[zeros(1,250) hanning(500)' zeros(1,250)]';

Compare the spectra of x, xsw and xhan. Describe how the time domain characteristics of the
window functions affect their spectral characteristics (recall that multiplication in the time-domain
is equivalent to convolution in the frequency domain).

Audio Processing:

Here's the fun part of the lab. The task is to develop an autofocus algorithim for the camera pictured
below:
In order to allow people to do this at home, a sequence of test images can be found here. The camera has 200
focus positions, and there is one image per focus position. the lower the number of the image, the closer an
object has to be to the camera, to be in focus.


included in the lab directory there is a sound file called mystery.raw.
you can load it into octave using the commnad line:
x = loadaudio('mystery','raw');

You can play the sound using: playaudio(x);

octave only plays sounds at 8KHz and unfortunatly this file was recorded at a faster rate.
Your task is to use what you learned inthe first section to change the sampling rate of the
audio such that mystery audio file sounds correct.(please hand in your code as well as plots so that the TA's
can verify that your solution works);

BONUS:
write an octave script to change the sampling rate of the mystery audio file by and rational factor.


Image Processing:





Try loading one of the images into Octave using the command
a=imread("s001.jpg","jpeg");
