Contents
DEMO1
This demonstration illustrates some basic functions found in the VibraTools toolbox.
% Copyright (c) 2003-2006, Axiom EduTech AB, Ljusterö, Sweden. All rights reserved. % URL: http://www.vibratools.com Email: info@vibratools.com
Create Sine Wave
Now let's create a time vector N samples long, and with a sampling frequency of fs
N=8192; fs=1000; t=maketime(1:N,fs); % This is a toolbox command that simplifies making time vectors % Then create a sine wave with with a frequency of fs/20 f0=fs/20; y=sin(2*pi*f0*t); figure plot(t,y) xlabel('Time, s') axis([0 10/f0 -1 1])
Linear Spectrum
For a periodic signal like this, let's make a linear (rms) spectrum using a flattop window. Note that the length of the spectrum produced is N/2+1 samples long, which means that the fs/2 frequency bin is kept. This in turn means that we can reproduce the double-sided spectrum exactly, if needed.
[L,f] = fanflat(y,fs,N,1,0); figure plot(f,L) xlabel('Frequency, Hz') ylabel('Linear spectrum, (m/s^2) RMS')
RMS summation in Frequency Domain
Let us now compute the RMS value of the sine in the frequency domain, and place it into the plot. To do this we need to divide the square frequency sum with the equivalent noise bandwidth factor. To insert the text, we use a toolbox command, FIGTEXT
R=sqrt(sum(L.*L)/equivbw(flattop(N))); R=round(1000*R)/1000; % Round to 3 decimals figtext(70,70,['RMS = ' num2str(R)]);
Import Universal File Data and Compute PSD
Next, we will import time data from a universal file and compute a PSD of it. The file contains simulated time data in acceleration format from the output of an SDOF system (produced by the ModalTools function timeresv).
fprintf('Next, a universal file with noise from an SDOF system is imported...\n') univread(1,'sdof.unv'); load uf1 % Since we put sequence number 1 in univread, the file is called uf1.mat % We now have data in two variables: Data, and Header fs=1/headdx(Header); N=length(Data)/100; [P,f]=psdnorm(Data,fs,N); figure; semilogy(f,P) xlabel('Frequency, Hz') Yu=headyu(Header); ylabel(strcat('(',Yu,')^2/Hz')) title(headti(Header,2,80),'FontSize',8) axis([0 fs/2.56 1e-6 100])
Next, a universal file with noise from an SDOF system is imported... Reading 58 Saved data as uf1.mat
Automatic Plotting of Labels etc.
When a file is stored in the VibraTools data format (which is automatically used when using any import routine in VibraTools), it contains a header. This header can be used for adding information to a plot. Here is an example of how to plot the first 1000 samples of data and the header values
figure plothead(Xaxis(1:1000),Data(1:1000),Header);