**Lab 1.**** Exploring nonlinear signal processing with MATLAB on
a PC.**

Lab 1. Due 9/ 7/04.

Exercises to be done using MATLAB. A PC
will be available in 87MSC. We can have a discussion if it is necessary. You
can do these exercises on any PC that has MATLAB. Any supplied m-files can be
obtained from the class WEB site. There is an editor for writing m-files in
MATLAB.

Do…
FILE…NEW… m-file , then enter your code.

You
have to save it in your folder.

To
execute the m-file… you have to tell MATLAB where the file is. cd c:\phy735\your_name does the job.

**Problem 1.** In order to familiarize
everyone with the use of the discrete Fourier transform:

generate y(t) = 10*sin(2*pi*f*t) where f = 100Hz. Make the signal 1 second
long. Use a power of 2 for the number of
samples. Note: the Nyquist theorem states you have to
sample a signal at least twice as fast as the highest frequency present. It is often better to sample at least 5Xs faster than the
highest frequency, especially, if you want a nice looking waveform to plot.

Plot
the waveform, and its Fourier magnitude and phase. Note: one variation of plotting in MATLAB
uses subplot(n,m,i) where
n=# of rows of plots, m=# of columns and I is the index of the current plot. E.g.,
if you are placing three plots on a single page and doing the second plot of
the series, the MATLAB code would be:

Subplot(3,1,2)

Plot(x,y)

There
will be an MATLAB m-file, __L1P1__, available as a starter for those who
have difficulty with this exercise. It
can be used as a template for several of the following exercises. You can
display any m-file in MATLAB by typing __dbtype____
FileName or you can do File then Open filename__. The
code can be printed by selecting the lines on the screen you want with the
mouse and then use the File command: followed by print selection.

**Problem
2.** Clip the waveform from Problem 1 at the following levels: 100%,
90%, 75%, 50%, 25% and 10 % of the maximum & minimum signal level, i.e.,
this is a symmetric clipping function. What amount of the total signal energy
is present in the each of the first three harmonics for each three conditions. Make a
table and/or graph of the results. Note
that as the clipping level gets lower that the signal is essentially a square
wave. When graphing this us the subplot function to place the results on a
single page.

**Problem 3.** Distortion of signals
results in the generation of components that are at frequencies that are not
present in the input signal. One can
represent the distortion process with a polynomial function. If x(t) is the input
and y(t) the output, then we can write y = aFx + bFx^{2} +cFx^{3} +…

set
a = 0, b= 1, and c=0. Let the input
consist of two sinusoids with frequencies of 1000 and 1100Hz.

What
frequency components are present in the output signal?

Note
that you can do this analytically. It is
just trigonometry. However, if you are a
bit rusty…. You can use MATLAB to compute the waveforms and then Fourier
analyze them. See below.

Remember:
Phythagorus: the Square of the hypotenuse = the sum of the squares of the sides
of a right triangle.

sin^{2}(x)
+ cos^{2}(x) = 1.

sin(A ± B) = sin(A)cos(B) ± sin(B)cos(A)

cos(A ± B) = cos(A)cos(B) -+ sin(B) sin(A)

and
if you set A = B = x you can derive:

cos^{2}(x)
= (1 + cos(2x))/2.

**Problem.**** 4.**
With the same frequency components as in Problem 3, set a = 0, b = 0 and c = 1.

What
frequency components are present in the output. Analytically or with MATLAB
FFT.

**Problem 5.** Same as Problem 4 but set a
= 1 and c = .05.

What
is the spectrum? Plot it.

**Problem 6.** A special case occurs when the ratio of the
two frequency components is set to 1.5 (f2/f1 = 1.5, f1 = 1000Hz). Set a = 1, b = c = 0.05. Vary the phase angle between the two primary
frequencies and plot the magnitude of the difference frequency, f2-f1 and the most
prominent distortion product heard by animals and humans, 2f1-f2, often labeled
the cubic difference tone (CDT). We will
discuss these distortion products and their generation in the auditory system in
greater detail later. Use MATLAB to obtain the results.

Double click on the Matlab 6.5 icon.

At
the Matlab prompt >> Type __demo__

Click
on matrices (this
is all Matlab really understands, i.e., matrices).

Then Run Basic matrix. Continue
through the slides.

When
done click on **close**.

Then
select numerics.

Select
Fast fourier transform. Run fast fourier transform

Sequence the slides.

At end close.

Your now ready to enter a set of instructions for Matlab
to execute.

Click
on **File** on the toolbar.

Select New and then m-file.

You are now in an editor/debugger.

Type in a series of
instructions. A % sign indicates a comment

e.g.

x=1:

y=x .^2; % says
make y= each element of x squared.

Plot(x,y)

Pause; % to advance
beyond this point hit any key

Plot(x,y,’*r’); % this says plot the curve using red asterisks.

%save this file with a name such as temp in your directory

%then
close the editor; this returns you to Matlab

type cd c:\phy735\your_name

temp %this will run the series of instruction that you just saved as an
m-file.

How
to obtain the FFT of a
signal….

%fft_example.m

t=0:.025:10;

y=sin(2*pi*t*2)+.5*sin(2*pi*t)+.4;

fy=fft(y); mfy=abs(fy);

[a,n]=size(y); dc=mfy(1)/n;

fresol=1/max(t); freq=0:fresol:fresol*(n/2);

amfy(1)=dc; maxn=round(n/2);

amfy(2:maxn)=2*mfy(2:maxn)/n;

plot(freq,amfy)