Azzera filtri
Azzera filtri

How to implement custom function in Flight Log Analyzer

31 visualizzazioni (ultimi 30 giorni)
Mckenzie Turpin
Mckenzie Turpin il 14 Ago 2024 alle 12:49
Commentato: Walter Roberson il 15 Ago 2024 alle 17:55
I am trying to create a custom function within the Flight Log Analyzer app in the UAV Toolbox, and I am getting errors no matter what I try. I am simply trying to plot a Fast-Fourier Transform of Accel and Gyro data. Below is an example of a function I wrote that works on its own, but I can not get it to work within the app. I am wondering what the function sturcture is that the app is looking for. I see what is on the pop up window when you go to create the function, but even when I try creating more arguments for the function I get index mismatch errors. An example of a function that can be passed into the app would be very helpful.
(in this example, "signalData" would be ACC_0 from the workspace file)
function afft = ArdupilotFFT(singalData)
Fs = 2000;
L = length(singalData);
L2 = floor(L/2);
f0 = Fs/L*(0:L2-1);
X0 = fft(singalData(:,5));
X0 = 10*log10(abs(X0(1:L2)));
Y0 = fft(singalData(:,6));
Y0 = 10*log10(abs(Y0(1:L2)));
Z0 = fft(singalData(:,7));
Z0 = 10*log10(abs(Z0(1:L2)));
figure('Name','FFT');
%subplot(1,3,1);
semilogx(f0,X0,f0,Y0,f0,Z0)
grid on; xlabel('Frequency (Hz)'); xlim([1,1000]);
end

Risposte (1)

Walter Roberson
Walter Roberson il 15 Ago 2024 alle 0:05
Assuming that the plotting is to be directed to UIAxes3
function afft = ArdupilotFFT(app, singalData)
Fs = 2000;
L = length(singalData);
L2 = floor(L/2);
f0 = Fs/L*(0:L2-1);
X0 = fft(singalData(:,5));
X0 = 10*log10(abs(X0(1:L2)));
Y0 = fft(singalData(:,6));
Y0 = 10*log10(abs(Y0(1:L2)));
Z0 = fft(singalData(:,7));
Z0 = 10*log10(abs(Z0(1:L2)));
ax = app.UIAxes3; %for example
semilogx(ax, f0, X0, f0, Y0, f0, Z0)
grid(ax, 'on');
xlabel(ax, 'Frequency (Hz)');
xlim(ax, [1,1000]);
end
  2 Commenti
Mckenzie Turpin
Mckenzie Turpin il 15 Ago 2024 alle 13:09
I am not sending this to a custom made app, it would be sent to an app that is imbedded in the UAV Toolbox with MATLAB. So simply assigning it to an axis to be plotted onto would not work as i do not know the axis name.

Accedi per commentare.

Community Treasure Hunt

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

Start Hunting!

Translated by