简体   繁体   中英

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. I'm not sure if i'm applying the lpc function correctly.

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).

After that, it will apply the calculated coefficients on the "for" cycle presented, in order to calculate the estimated energy.

Finally, error2 outputs the error between the real energy and estimated value.

On the example presented ( http://www.mathworks.com/help/signal/ref/lpc.html ) some filters are used. 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. I am adressign the part at he "for 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. but this will perform the calculation for the entire w2 vector. If you just want the last value take the (end) command as well.

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. Have you tried something like a polynominal approach? i would think that this would be closer to reality.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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