quiz8_solution - %SUNSPOT A script that loads sunspot.dat...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: %SUNSPOT - A script that loads sunspot.dat, an ascii file %with column 1 as years and column 2 as wolfer index, into a MATLAB array, plots wolfer index vs. year, takes the fft of the input data, %plots power vs. frequency, plots power vs. period, and prints the %sunspot period to the title of power vs. period plot. %File written by S.C. Tegler. Last modified 3/31/11. %--------------------------------------------------load sunspot.dat year = sunspot(:,1); wolfer = sunspot(:,2); figure(1); plot(year,wolfer); xlabel('Year'); ylabel('Wolfer Index'); title('Sunspot Data'); Y = fft(wolfer); N = length(Y); Y(1) = 0; Power = abs(Y).^2; tau = year(2) - year(1); dv = 1/N*tau; v = 0:dv:(N-1)*dv; %loads sunspot.dat into MATLAB array %creates year vector %creates wolfer index vector %plots wolfer index vs. year %computes fft %length of fft vector %sets first element of fft output to 0 %computes power of fft output %computes time sampling interval %computes frequency sampling interval %computes frequency vector figure(2); %plots power vs. frequency plot(v,Power); xlabel('Frequency (1/yr)'); ylabel('Power'); title('Sunspot Power Spectrum'); figure(3); %plots power vs. period period = v.^(-1); %period vector [ampmax,indexmax] = max(Power); %amp and index of max value in Power sunper = period(indexmax); %sunspot period plot(period,Power); %makes the plot title(['Sunspot Period is ' ,num2str(sunper,'%4.2f'), 'Yrs']); xlabel('Period (Years)'); ylabel('Power'); ...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online