0
votes

I am trying to acquire the frequency information about a displacement signal(e.g., Vx) while the simulation is running.

My idea was to make use of the fft command supported by Embedded Matlab Function block.

The first thing which i performed was to store the values of displacement signal 'Vx' in a buffer of length 'L'.

The second thing is to compute the fft of those values stored in the buffer and calculate the index value corresponding to the maximum amplitude.

The third thing is to acquire the frequency from index value, sampling frequency and length of the buffer.

Embedded Matlab code is the following:-

  Function[freq_Vx,buffero_Vx] = fcn(Vx,bufferi_Vx)
  % This block supports the Embedded MATLAB subset.
  % See the help menu for details. 


  buffo_Vx = [Vx;buffi_Vx(1:end-1)];                 % buffer which stores the values of signal 'Vx'
  Fs = 2000;
  nfft = 2^nextpow2(length(buffo_Vx)); 
  [max_Vx,index_Vx] = max(abs(fft(buffo_Vx,nfft)));
  freq_Vx = index_Vx*Fs/length(buffo_Vx);

  end

Is this the right way of acquiring the frequency content of a signal while the simulation is running?

1

1 Answers

0
votes

I believe your approach to processing the data "real time" in the model is reasonable, however I believe the index_Vx*Fs/length(buffo_Vx) is not going to give the desired results and buffo_Vx = [Vx;buffi_Vx(1:end-1)]; will likely need to be buffo_Vx = [Vx;bufferi_Vx(1:end-1)];` Checkout this link for your frequency conversion.

For diagnostic purposes, check out the Simulink Extras -> Additional Sinks blocks on the Simulink library browser.

Browser

The Spectral densities should be helpful.