Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Convert Matlab to Scilab

1,235 views
Skip to first unread message

Tranquility

unread,
Jul 7, 2014, 9:05:23 AM7/7/14
to
Hello every one ,

Unfortunately I'm totally new in Scilab but not in Matlab ,so I would like to convert a Matlab script to Scilab script , I tried the converter tool but it didn't work .
this is the Matlab code :

"function spectrum =spectrum-calc(data,freq,n-lags,M)
data=load ('DATA.txt');
N=size(data,1);
c-k=autocorr(data,n-lags)*var(data);%calculates the autocorrelation
c_0=var(data)%Variance
l-k=0.5*(1+cos((pi*(0:M))./M));%Tukey window calculation
for i=1:size(freq,2)
sum=0;
for e=1:M
sum=sum+l-k(1,e)*c-k(e,1)*cos(freq(1,i)*e);%Sweeps the data and generates the variance for each frequency
end
spectrum(i,1)=(c_0+2*sum)/pi ;
end
end"

Any help would be appreciated.

Tranquility

akhorshidi

unread,
Jul 7, 2014, 2:42:25 PM7/7/14
to
Hi;

First off your Matlab code appears wrong because a variable name cannot contain an dash (-).

I think your function can be run in Scilab by a little modifications. So use xcorr() and xcov() instead autocorr() and cov(), respectively. See: https://help.scilab.org/docs/current/en_US/xcorr.html and https://help.scilab.org/docs/current/en_US/xcov.html

Also we can define a function in Scilab as follows:

function spectrum = spectrum-calc(data,freq,n-lags,M)

// body of the function

endfuncrion

You may need to import some data into Scilab environment, so read() function can be handy. For instance suppose we wanna load a DAT file downloaded from a website (e.g. ftp://ftp.esat.kuleuven.be/pub/SISTA/data/process_industry/powerplant.dat.gz).

So just try this:

pathname = "PATH_TO_THE_FILE";
data=read(pathname + "powerplant.dat",-1,11);
//Also You can classify your data:
u=data(:,1:5); y=data(:,6:8); yr=data(:,9:11);


HTH
Mehran
_

Tranquility

unread,
Sep 9, 2014, 8:58:07 AM9/9/14
to
Hi again,
i would like to thank you for you help.
Now firstly, i wonder if you can show me how to define the n_lags of my autocorr knowing that the only information I have is that it should be < N-1 (N=size of data).Secondly, i have problem with selecting the right value of the point M which is called in signal processing the truncation point.I note that is the non parametric spectrum estimation method .
Any help would be greatly appreciated.

Tranquility

RRogers

unread,
Oct 7, 2014, 10:00:51 AM10/7/14
to
N estimate: Well the old books, Nelson "applied time series analysis", give a complicated formula; but it boils down to taking the autocorrelation graph and chopping off everything beyond the point where the remainder is below .3 . This means that you graph the full n-1 lags and then use the graph to determine the significant number of lags. If you want to automate it I could give you the formula (or you could just look for .3) . If you end up with a graph that wobbles above and below the threshold you need to look at the Partial Autocorrelation graph. And so on..
0 new messages