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

## Errors in Changing Matlab scripting file for tutorial 2 FFT

### Re: Errors in Changing Matlab scripting file for tutorial 2

Hi,
you have 2 %f and only one argument.

Thibaut

Code: Select all

`fprintf(fileID,'%f %f\n',k);`

Thibaut

### Re: Errors in Changing Matlab scripting file for tutorial 2

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.

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.

### Re: Errors in Changing Matlab scripting file for tutorial 2

Maybe try the function disp()