% This m-file psdchk1.m was created by Professor Ron Adrezin

% of The Cooper Union, School of Engineering

% on 5/04/97. It was last modified on 5/04/97.

%

% The purpose of this m-file is to demonstrate how to

% determine the frequency of an incoming signal.

% The user will specify up to three functions.

% These functions are summed and their

% resulting function is then plotted and its Power Spectral

% Density (PSD) is calculated and plotted.

%

% Can you tell the frequencies of the three functions

% by only reviewing the PSD plot? What about the Amplitude

% of each function? Can this be estimated from the PSD plot?

%

%

% FunctA: the first function

% A1: amplitude of the first function in meters

% f1: frequency of the first function in Hz

% FunctB: the second function

% A2: amplitude of the second function in meters

% f2: frequency of the second function in Hz

% FunctC: the third function

% A3: amplitude of the third function in meters

% f3: frequency of the third function in Hz

% FunctTotal: the sum of the three functions

% fs: the sampling frequency in Hz

% t: time in seconds

% t0: start time in seconds

% tf: final time in seconds

 

clear all;

t0=0;

tf=30;

fs=20;

 

A1=2;

A2=300;

A3=60;

f1=.1;

f2=8;

f3=3;

 

t=t0:1/fs:tf;

 

FunctA=A1*sin(2*pi*f1*t);

FunctB=A2*sin(2*pi*f2*t);

FunctC=A3*sin(2*pi*f3*t);

 

FunctTotal =FunctA+FunctB+FunctC;

 

 

 

 

figure(1)

subplot(3,1,1);

plot(t,FunctTotal);

xlabel('time [s]');

ylabel('displacement [m]');

title('Plot of FunctTotal');

subplot(3,1,3);

 

p=spectrum(FunctTotal,512); %This requires at least 1024 points

% It also must be 2 to a power.

specplot(p,fs);