简体   繁体   English

MATLAB Simple-线性预测编码和能量预测

[英]MATLAB Simple - Linear Predictive Coding and Energy Forecasting

I have a dataset with 274 samples (9 months) of the daily energy (Watts.hour) used on a residential household. 我有一个数据集,其中包含一个居民家庭每天使用的274个样本(9个月)的每日能量(Watts.hour)。 I'm not sure if i'm applying the lpc function correctly. 我不确定我是否正确应用了lpc函数。

My code is the following: 我的代码如下:

  filename='9-months.csv';
  energy = csvread(filename);


  C=zeros(5,1);
  counter=0;


  N=3;



  for n=274:-1:31

  w2=energy(1:n-1,1);
  a=lpc(w2,N);

  energy_estimated=0; 

      for X = 1:N
      energy_estimated = energy_estimated + (-a(X+1)*energy(n-X));
      end

  w_real=energy(n);
  error2=abs(w_real-energy_estimated);


  counter=counter+1;

  C(counter,1)=error2;
  end

  mean_error=round(mean(C));

Being "n" the sample on analysis, I will use the energy array's values, from 1 to n-1, to calculate the lpc coefficientes (with N=3). 作为分析中的样本“ n”,我将使用从1到n-1的能量数组的值来计算lpc系数(N = 3)。

After that, it will apply the calculated coefficients on the "for" cycle presented, in order to calculate the estimated energy. 之后,它将计算出的系数应用于给出的“ for”周期,以便计算出估计的能量。

Finally, error2 outputs the error between the real energy and estimated value. 最后,error2输出实际能量和估计值之间的误差。

On the example presented ( http://www.mathworks.com/help/signal/ref/lpc.html ) some filters are used. 在提供的示例( http://www.mathworks.com/help/signal/ref/lpc.html )上,使用了一些过滤器。 Do I need to apply any filter to it? 我需要对其应用任何过滤器吗? Is my methodology correct? 我的方法正确吗?

Thank you very much in advance! 提前非常感谢您!

The lpc seems to be used correctly, but there are a few other things about your code. LPC似乎已正确使用,但是关于代码还有其他一些事情。 I am adressign the part at he "for n" : 我对他“为n”感到满意:

for n=31:274 %for me it would seem more logically to go forward in time

  w2=energy(1:n-1,1);
  a=lpc(w2,N);


  energy_estimate=filter([0 -a(2:end)],1,w2);
  energy_estimate=energy_estimate(end);

  estimates(n)=energy_estimate;


end

error=energy(31:274)-estimates(31:274)';
meanerror=mean(error); %you dont really round mean errors

filter is exactly what you are trying to do with the X=1:N loop. 过滤器正是您要使用X = 1:N循环执行的操作。 but this will perform the calculation for the entire w2 vector. 但这将对整个w2向量执行计算。 If you just want the last value take the (end) command as well. 如果只希望最后一个值,也可以使用(end)命令。

Now there is no reason to calculate the error for every single value and then add them to a vector you can do that faster after the calculation. 现在,没有理由为每个单个值计算误差,然后将它们添加到向量中,这样您就可以在计算后更快地做到这一点。

Now if your trying to estimate future values with a lpc it could work like that, but you are implying that every value is only dependend on the last 3 values. 现在,如果您尝试使用lpc估算未来值,则可以像这样工作,但是您暗示每个值仅取决于最后三个值。 Have you tried something like a polynominal approach? 您是否尝试过多项式方法? i would think that this would be closer to reality. 我认为这将更接近现实。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM