Why my function is not running online although it works offline?

1 回表示 (過去 30 日間)
K G
K G 2019 年 7 月 22 日
コメント済み: Kavya Vuriti 2019 年 8 月 6 日
I have a matlab within a simulation model function with no errors but its does not do what is asked for, i want to change the value of weight_d. My input are a vektor u_out and a changing constant statusFlag. I want to run fft function of u_out only one time when statusflag is 5 and do change in weight_du and at the end initialize my temp so i can run the same thing in the next simulation cycle.
function weight_du = rTuning(u_out,weight_du,statusFlag)
persistent temp
if isempty(temp)
temp = 0;
end
if statusFlag ==6 && temp ==0
L=length(u_out); %length of the signal
Fs=125; %sampling frequency
t=(0:L-1);%time domain array
f=linspace(0,Fs/2,length(t));%frequency domain array
win=hamming(L); %hamming window
[Frequenz_Achse, Amplitudengang]=fft_analyse(win.*u_out,Fs,10^6); %fft with hamming
Ausschnitt1= Amplitudengang(500001:580001); % pos Amplitude until 10Hz
I1= trapz(Ausschnitt1).*1.0000e-03; % integration with trapz
Ausschnitt2= Amplitudengang(580001:end); % pos Amplitude until end
I2= trapz (Ausschnitt2).*1.0000e-03; % integration with trapz
I=I2/I1;% quotient of both integrations
if I>=0.1715
weight_du=weight_du.*10;
end
if I<= 0.0429
weight_du=weight_du/10;
end
temp= temp+1;
if statusFlag ==6 && temp==1
temp=0;
end
end
end
function [ Frequenz_Achse, Amplitudengang] = fft_analyse(Signal,SamplingRate,ZeroPadding)
FFT_sig = fftshift(fft(Signal,ZeroPadding));
Frequenz_Achse = (0:(ZeroPadding-1))/ZeroPadding/(1/SamplingRate)-1/(2/SamplingRate);
Amplitudengang = abs(FFT_sig)/(ZeroPadding/2);
%figure;
%plot(Frequenz_Achse,Amplitudengang);
end
  1 件のコメント
Kavya Vuriti
Kavya Vuriti 2019 年 8 月 6 日
Hi,
There is a mismatch in the status flag set by your code and the status flag required. From the code, the fft function on u_out executes only when status flag is 6 whereas in the question it is mentioned that the fft function should run only when status flag is 5.
Also what do you mean by the function running offline but not online.

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeNumerical Integration and Differentiation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by