太阳黑子是人们最早发现也是人们最熟悉的一种太阳表面活动。因为太阳内部磁场发生变化,太阳黑子的数量并不是固定的,它会随着时间的变化而上下波动,每隔一定时间会达到一个最高点,这段时间就被称之为一个太阳黑子周期。太阳黑子的活动呈现周期性变化是由施瓦贝首次发现的。沃尔夫 (R.Wolfer)继而推算出11年的周期规律。实际上,太阳黑子的活动不仅呈11年的周期变化,还有海耳在研究太阳黑子磁场分布时发现的22年周期;格莱斯堡等人发现的80年周期以及蒙德极小期等。由于太阳黑子的活动规律极其复杂,时至今日科学家们仍在努力研究其内在的规律和特性。事实上,对太阳黑子活动规律的研究不仅具有理论意义,而且具有直接的应用需求。太阳黑子的活动呈现周期性变化的,沃尔夫(R.Wolfer)根据在过去的288 年(1700年~1987 年)间每年太阳黑子出现的数量和大小的观测数据推算出11 年的周期规律。我们利用Matlab强大的数据处理与仿真功能,对Wolfer数进行功率谱密度分析从而可以得到对太阳黑子活动周期的结论。
clear;
close all;
warning off;
%YEAR MON SSN DEV
%画出导入的活动数据
YEAR = Sunspot(:,1);
MON = Sunspot(:,2);
SSN = Sunspot(:,3); %sun spot number
DEV = Sunspot(:,4); %标准偏差表
figure;
subplot(211);plot(SSN,'b.');
title('SSN');
subplot(212);plot(DEV,'b.');
title('DEV');
addpath 'funcs\'
%步骤1,Identify a reasonable frequency, f.
%步骤1,Identify a reasonable frequency, f.
%步骤1,Identify a reasonable frequency, f.
%由于早期的数据不精确,可以选择后期的数据作为计算频率的数据
K = 20;%前22年数据去除
Start = 12*K+1;
mainPeriod = func_cycle_cal(SSN(Start:end));
disp('太阳黑子的活动周期为(单位年):');
mainPeriod
%步骤2,Compute X1 = cos(2πft) and X2 = sin(2πft).
%步骤2,Compute X1 = cos(2πft) and X2 = sin(2πft).
%步骤2,Compute X1 = cos(2πft) and X2 = sin(2πft).
t = 1/(12):1/(12):length(SSN)/(12);
yc = cos(2*pi*t/mainPeriod);
ys = sin(2*pi*t/mainPeriod);
figure;
subplot(211);
plot(yc,'r');hold on
plot(ys,'b');hold off
legend('X1','X2');
subplot(212);
plot(yc,'r--');hold on
plot(ys,'k--');hold on
plot(SSN/max(SSN),'b.');hold off
legend('X1','X2','SSN');
%步骤3,Fit the linearized cyclic model with least squares using Matlab.
%步骤3,Fit the linearized cyclic model with least squares using Matlab.
%步骤3,Fit the linearized cyclic model with least squares using Matlab.
%Nt = β0 + β1X1 + β2X2 + error.
%最小二乘辨识
c0 = [1 1 1]';%直接给出被辨识参数的初始值,即一个充分小的实向量
p0 = 10^6*eye(3,3); %直接给出初始状态P0,即一个充分大的实数单位矩阵
for k=1:length(SSN); %开始求K
h1 =[1,yc(k),ys(k)]';
x = h1'*p0*h1 + 99;
x1 = inv(x); %开始求K(k)
k1 = p0*h1*x1; %求出K的值
d1 = SSN(k)-h1'*c0;
c1 = c0+k1*d1; %求被辨识参数c
e1 = c1-c0; %求参数当前值与上一次的值的差值
e2 = e1./c0; %求参数的相对变化
e(:,k) = e2; %把当前相对变化的列向量加入误差矩阵的最后一列
c0 = c1; %新获得的参数作为下一次递推的旧参数
c(:,k) = c1; %把辨识参数c 列向量加入辨识参数矩阵的最后一列
p1 = p0-k1*k1'*[h1'*p0*h1+1]; %求出 p(k)的值
p0 = p1; %给下次用
end
%估计得到的太阳黑子活动曲线
for k=1:length(SSN); %开始求K
Y_predict(k) = c(1,k) + c(2,k)*yc(k) + c(3,k)*ys(k);
end
figure;
plot(Y_predict,'b','LineWidth',2);hold on;
plot(SSN,'r');hold off;
legend('预测SSN','实际SSN');
%步骤4: Interpret the ?tted model parameters in terms of amplitude,frequency, and phase shift of the cyclic model.
%步骤4: Interpret the ?tted model parameters in terms of amplitude,frequency, and phase shift of the cyclic model.
%步骤4: Interpret the ?tted model parameters in terms of amplitude,frequency, and phase shift of the cyclic model.
%根据预测结果计算
%ut = Bcos(2*pi*f*t+o);
t = 1/(12):1/(12):length(SSN)/(12);
for k = 1:length(SSN);
beta0(k) = c(1,k);
beta1(k) = c(2,k);
beta2(k) = c(3,k);
BETA(k) = sqrt(beta1(k)^2 + beta2(k)^2);
fai(k) = atan(-beta2(k));
%ut = Bcos(2*pi*f*t+o);
%t = 1/(12):1/(12):length(SSN)/(12);
%yc = cos(2*pi*t/mainPeriod);
ut(k) = BETA(k)*cos(2*pi*t(k)/mainPeriod+fai(k)) + beta0(k);
end
figure;
plot(ut(40:end),'b','LineWidth',2);
hold on;
plot(SSN(40:end),'r');
hold off;
legend('Bcos(2*pi*f*t+o)','实际SSN');
%步骤5: Use residual plots to validate/evaluate the model.
%步骤5: Use residual plots to validate/evaluate the model.
%步骤5: Use residual plots to validate/evaluate the model.
%计算误差
Err = Y_predict' - SSN;
figure;
plot(Err,'.');
xlabel('Year');
ylabel('Nt - Ut');
%步骤6: Consider how the model might be improved.
%步骤6: Consider how the model might be improved.
%步骤6: Consider how the model might be improved.
%模型的改进
%注意,从上面的分析结果可知,预测模型的误差较大,做如下的改进,使其误差较小
%最小二乘辨识
clear h1 x x1 k1 d1 c1 e1 e2 e c0 c p1 p0
c0 = [1 1 1 1 1 1 1 1]';%直接给出被辨识参数的初始值,即一个充分小的实向量
p0 = 10^6*eye(8,8); %直接给出初始状态P0,即一个充分大的实数单位矩阵
t = 1/(12):1/(12):length(SSN)/(12);
yc2 = cos(2*pi*t/(2*mainPeriod));
ys2 = sin(2*pi*t/(2*mainPeriod));
yc3 = cos(2*pi*t/(3*mainPeriod));
ys3 = sin(2*pi*t/(3*mainPeriod));
for k=1:length(SSN); %开始求K
h1 =[1,k,yc(k),ys(k),yc2(k),ys2(k),yc3(k),ys3(k)]';
x = h1'*p0*h1 + 99;
x1 = inv(x); %开始求K(k)
k1 = p0*h1*x1; %求出K的值
d1 = SSN(k)-h1'*c0;
c1 = c0+k1*d1; %求被辨识参数c
e1 = c1-c0; %求参数当前值与上一次的值的差值
e2 = e1./c0; %求参数的相对变化
e(:,k) = e2; %把当前相对变化的列向量加入误差矩阵的最后一列
c0 = c1; %新获得的参数作为下一次递推的旧参数
c(:,k) = c1; %把辨识参数c 列向量加入辨识参数矩阵的最后一列
p1 = p0-k1*k1'*[h1'*p0*h1+1]; %求出 p(k)的值
p0 = p1; %给下次用
end
%估计得到的太阳黑子活动曲线
for k=1:length(SSN); %开始求K
Y_predict2(k) = c(1,k) + c(2,k)*k + c(3,k)*yc(k) + c(4,k)*ys(k) + c(5,k)*yc2(k) + c(6,k)*ys2(k) + c(7,k)*yc3(k) + c(8,k)*ys3(k);
end
figure;
plot(Y_predict2,'b','LineWidth',2);hold on;
plot(SSN,'r');hold off;
legend('预测SSN','实际SSN');
联系:highspeedlogic
QQ :1224848052
微信:HuangL1121
邮箱:1224848052@qq.com
微信扫一扫: