% ex_rv_1.m Example to illustrate frequency analysis of signals % % written by Babu Joseph, Washington University, July 2000 % % First generate a signal containing two sinewaves and white noise % t=0:4990;% time vector t_samp=1;% sample time N=length(t); % no of sample points x=sin(t*pi/100)+sin(t*3*pi/100)+rand(1,N);% pi/100 and 3pi/100 are dominant plot(t,x); pause % % now analyze the spectrum % X=fft(x); % matlab computes frequency range from 2pi/(t_samp) to 2Pi/t_samp % The transform is symmetric about the nyquist frequency pi/t_samp % % only the first half is necessary. freq=0:2*pi/(t_samp*N):pi/t_samp; amp=abs(X(1:N/2+1))*2/N; % Takes the first half and normalizes it so % unit amplitude in time corresponds to unit amplitude in frequency loglog(freq,amp);% use loglog since power varies a great deal