Computer
Homework 1
In this homework you will do simple spectral analysis. You will first look at the spectrum of known signals, then try to find the amplitudes and frequencies of cosines in an unknown signal.
1. Two cosines with very similar
frequencies.
Make a signal composed of two cosines close in frequency with the following commands (you do not have to copy the comments):
>>N = 51; %Define N to be 51.
>>n = 0:1:N-1; %make a vector from 0 to N-1 with steps of 1.
>>x = cos(.4*pi*n)+0.7*cos(.43*pi*n); %make the
signal with two cosines.
This signal has only 51 points. Zero padd the signal to make it at least 1024 points long. Once the signal has been zero padded, determine the Fourier Transform using the FFT (Fast Fourier Transform) command:
>>X = fft(x);
MATLAB is case sensitive, so X is not equal to x. Next look at a plot of its magnitude spectrum:
>>plot(w,abs(X))
where w is the frequency vector from 0 to 2pi,
>>w = 0 : (2*pi)/M : 2*pi-(2*pi)/M;
The procedure above is the same as multiplying the signal by 1, so it uses a rectangular window. Repeat the same procedure, except multiply the signal by a window with a large main lobe like the hanning window. (The windowing is done before the zero padding.)
>>hanning_window = hanning(N);
>>x = x.*hanning_window;
2. Two cosines with very different
amplitudes.
Make a signal composed of two cosines with very different amplitudes:
>>N=51;
>>n=0:1:N-1;
>>x=cos(.4*pi*n)+0.01*cos(.7*pi*n);
Use the same procedure as above to look at the spectrum of the signal.
3. Unknown Signal
Determine the frequency and amplitude of three cosines with added noise. I have included the data in two formats, the MATLAB native format called mat, and a simple ASCII file. The files are named hw1.mat and hw1.dat respectively. They can be read into matlab with the load command:
>>load hw1.mat
>>load hw1.dat
I have tried to make the signal so that the frequencies and amplitudes are not obvious, so you will need to use the techniques discussed in class and done above in parts 1 and 2. The added noise may look like many cosines, so what you are looking for are the three largest cosines in the signal.
Include the amplitude and frequencies of the cosines in your program description.