Filter löschen
Filter löschen

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

1 Ansicht (letzte 30 Tage)
K G
K G am 22 Jul. 2019
Kommentiert: Kavya Vuriti am 6 Aug. 2019
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 Kommentar
Kavya Vuriti
Kavya Vuriti am 6 Aug. 2019
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.

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by