12.07.2015 Views

Basics of MATLAB and Beyond

Basics of MATLAB and Beyond

Basics of MATLAB and Beyond

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

-0.5000-0.3750-0.2500-0.125000.12500.25000.3750We combine fftshift <strong>and</strong> fftfreq to plot the two-sided FFT:plot(fftfreq(.5,8),fftshift(abs(Y)))axis([-.5 .5 0 7])zeroaxesLet us do a slightly more realistic example. We simulate some datarecorded at a sampling frequency <strong>of</strong> 1 kHz, corresponding to a time stepdt = 1/1000 <strong>of</strong> a second. The Nyquist frequency is, therefore, 500 Hz.Suppose there is a 100 Hz sinusoid contaminated by noise. We simulatethe data, calculate the FFT, <strong>and</strong> plot the results as follows:dt = 1/1000;t = dt:dt:200*dt;sine = sin(2*pi*100*t);y = sine + r<strong>and</strong>n(size(t));Y = fft(y);f = fftfreq(500,length(Y));clfsubplot(211)stairs(t,y)hold onstairs(t,sine-4)boxxlabel(’Time (seconds)’)subplot(212)stairs(f,fftshift(abs(Y)))boxxlabel(’Frequency (Hz)’)c○ 2000 by CRC Press LLC

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!