How to avoid symbolic function when working with results files

The data_temp structure stores all the results for multiple probes for multiple point.
Say we have N probes and M point the structure would be data_temp(N).results(2:1:M)
My goal is to evaluate the integral over one periode of the PF_interface function which is built using multiple results values for all given point.
I could'nt find a way to do it without the symbolic expression but it takes ages to computes which does'nt work when M>1000, thus I'm quite sure it is not the optimal solution. Is there another way around ?
If not I already tried the following:
  • going from exact fraction numbers to decimal value (hence de vpa) didn't do anything
  • without the m for loop using matrix computation and replacing m by : in my calls, it did not change anything.
The code runs "fast" for x iteration and then slows down by a factor of 100 to 1000x without explanation
Any other way to optimise it ?
I'm using 2013b version for compatibility issues, so no vpaintegral function available for example.
Thanks for your help
syms func_t(t,amp,phase)
func_t(t,amp,phase)=amp*cos(t+phase);
PF_RMS=zeros(1,length(data_temp(1).resultat));
for m=1:length(data_temp(1).resultat)
tic
PF_interface = 0;
for ii=1:3
PF_interface = PF_interface + vpa(func_t(t,data_temp(ii).resultat(1,m),data_temp(ii).resultat(2,m)).*func_t(t,data_temp(ii+3).resultat(1,m),data_temp(ii+3).resultat(2,m)),8);
end
PF_interface=vpa(PF_interface.^2,8);
PF_RMS(m) = sqrt(1/(2*pi)*double(int(PF_interface,t,0,2*pi)));
toc
end

9 Comments

Are you using vpa() on symbolic expressions? Why?
To validate my code I wanted to check that the coefficients in the function where consistent with the entry data, but I runed it with and without the vpa parts nothing changes regarding computation time
I tried with arrays, would this be the same as the upper code and would there be a possibility to get rid of M for loop ?
I've tried it on small sample it seems to yield the same results as the original code
tt=linspace(0,2*pi,10000);
PF_RMS_2=zeros(1,length(data_temp(1).resultat));
for m=1:length(data_temp(1).resultat)
tic
PF_interface = 0;
for ii=1:3
PF_interface = PF_interface + data_temp(ii).resultat(1,m).*cos(tt+data_temp(ii).resultat(2,m)).*data_temp(ii+3).resultat(1,m).*cos(tt+data_temp(ii+3).resultat(2,m));
end
PF_interface=PF_interface.^2;
PF_RMS_2(m) = sqrt(1/(2*pi)*trapz(tt,PF_interface));
toc
end
Could you attach the data you are working with? Use the paperclip button to attach.
If yfou are doing a Fourier transform, there are easier ways. Specifically, see fft and fourier depending on what approach you want to take.
The ‘resultat’ field has one non-zero entry, so it a sort of impulse function —
LD = load('data_temp.mat')
LD = struct with fields:
data: {1×174 cell} metadata: [1×1 struct] evrn_interface: {9×2 cell} tt: [0 6.2838e-04 0.0013 0.0019 0.0025 0.0031 0.0038 0.0044 0.0050 0.0057 0.0063 0.0069 0.0075 0.0082 0.0088 0.0094 0.0101 0.0107 0.0113 0.0119 0.0126 0.0132 … ] (1×10000 double) interfaceIdx: 9 data_temp: [1×6 struct] dataIdx: 174 PF_RMS_2: [1.6433e-18 2.5817e-10 1.2083e-08 9.5448e-07 3.9415e-07 3.7248e-07 2.6259e-06 2.2613e-05 1.1703e-05 1.5983e-05 4.9306e-05 6.8085e-05 3.4939e-05 3.3271e-05 … ] (1×301 double) PF_interface: [5.3306 5.3311 5.3316 5.3321 5.3327 5.3332 5.3337 5.3342 5.3347 5.3352 5.3357 5.3362 5.3367 5.3372 5.3377 5.3382 5.3387 5.3392 5.3396 5.3401 5.3406 5.3411 … ] (1×10000 double) m: 301 ii: 3
data_temp = LD.data_temp
data_temp = 1×6 struct array with fields:
valeur_label base resultat
valeur_label = data_temp.valeur_label
valeur_label = 2×5 char array
'Ampl ' 'Phase'
base = data_temp.base;
resultat = data_temp.resultat;
resultat = squeeze(resultat)
resultat = 2×301
0.0000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1.6952 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
figure
plot(base, resultat)
grid
xlim([0 100])
.
I'm sorry, I did save the full workspace by mistake so multiple file not related to the question, I updated the file
In that case yes the first sensor has 0 amplitude because of the setup used, all the other are non zero.
I figured that.
The Fourier transforms of those data are not going to be very informative, regardless.

Sign in to comment.

Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Tags

Asked:

on 13 Oct 2023

Commented:

on 13 Oct 2023

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!