Errors in Changing Matlab scripting file for tutorial 2 FFT

Concerning processing components: filters, file load/save, visualizations, communication ...
Post Reply
NagarjunV
Posts: 9
Joined: Wed Feb 06, 2019 11:53 am

Errors in Changing Matlab scripting file for tutorial 2 FFT

Post by NagarjunV »

Hello,

I am using openvibe tutorial 2 FFT for data acquisition and signal processing. I have done small modifications to the code "tuto2_FFT_filter_Uninitialize.m", such that I want to print amplitude of the peak at 8hz frequency from the mean plot (which occurs after stopping the acquisition scenario) into a text file. I am highlighting the colour as shown below which represents the changes I have made. When I play the scenario. I get an error that fprintf is an undefined variable. Can anyone please suggest me and help me if any odig=fication is required for this code to work?

function box_out = tuto2_FFT_filter_Uninitialize(box_in)
disp('Uninitializing the box...')
syms j k
Fs = box_in.inputs{1}.header.sampling_rate; % Sampling frequency
L = box_in.inputs{1}.header.nb_samples_per_buffer; % Length of signal

NFFT = 2^nextpow2(L);
f = Fs/2*linspace(0,1,NFFT/2+1);

box_in.user_data.mean_fft_matrix = box_in.user_data.mean_fft_matrix / box_in.user_data.nb_matrix_processed;

%% we close the previous figure window and plot the mean FFT between 5 and 50Hz.
close(gcf);
plot_range_fmin = box_in.settings(3).value;
plot_range_fmax = box_in.settings(4).value;
plot(f(plot_range_fmin*2:plot_range_fmax*2),2*abs(box_in.user_data.mean_fft_matrix(plot_range_fmin*2:plot_range_fmax*2)))
j = f(plot_range_fmin*2:plot_range_fmax*2);
k = 2*abs(box_in.user_data.mean_fft_matrix(plot_range_fmin*2:plot_range_fmax*2));
k = [j;k];
fileID = fopen('exptable.txt','w');
fprintf(fileID,'%f %f\n',k);
fclose(fileID);

title('MEAN Single-Sided Amplitude Spectrum of the corrupted signal (channel 1)')
xlabel('Frequency (Hz)')
ylabel('Amplitude')

% We pause the execution for 10 seconds (to be able to see the figure before the scenario is stopped)
pause(10);

box_out = box_in;
end

Thibaut
Posts: 264
Joined: Wed Oct 31, 2018 9:14 am

Re: Errors in Changing Matlab scripting file for tutorial 2

Post by Thibaut »

Hi,

Code: Select all

fprintf(fileID,'%f %f\n',k);
you have 2 %f and only one argument.
Thibaut

NagarjunV
Posts: 9
Joined: Wed Feb 06, 2019 11:53 am

Re: Errors in Changing Matlab scripting file for tutorial 2

Post by NagarjunV »

thank you for your reply, but that will not be a problem.
According to MATLAB, the 2 f% are for printing both J and K. For y=[g,h] if we give command f% f%, it prints both g and h side by side.

Thibaut
Posts: 264
Joined: Wed Oct 31, 2018 9:14 am

Re: Errors in Changing Matlab scripting file for tutorial 2

Post by Thibaut »

Maybe try the function disp()

Post Reply