How to find the frequency from data measured with a strain gage?
조회 수: 8 (최근 30일)
이전 댓글 표시
Hi,
I have collected data from a strain gage using a DAQ. I would like to find the frequency from that data.
I set the DAQ sample rate to 1000 samples per second, and I have 43800 samples. I am not sure if the sample rate is adequate and if the code below is correct to find the frequency.
If anyone has worked with this kind of test before and could help me to find the best approach to solve this problem.
Thank you,
signal = load('DataSG.txt');
N=length(signal);
Fs=1000; %Sampling frequency
Ts=1/Fs; %sampling period or time step
dt=0:Ts:43.8-Ts; %signal duration
X_mags = abs(fftshift(fft(signal)));
X_mags = X_mags/max(X_mags);
bin_vals = [0 : N-1];
N_2 = ceil(N/2);
fax_Hz = (bin_vals-N_2)*Fs/N;
subplot(2,1,1);
plot(dt,signal);
xlabel('Time[s]');
ylabel('Amplitude');
title('Time Domain Signal');
subplot(2,1,2);
plot(fax_Hz,X_mags);
xlabel ('Frequency [Hz]');
ylabel ('Normalized Amplitude');
title('frequency Domain Signal');
[B,IX] = sort(2*X_mags); %order the amplitudes
A1=B(end); %amplitude of the first peak
A2=B(end-1); %amplitude of second peak
f1=fax_Hz(IX(end)); %frequency of first peak
f2=fax_Hz(IX(end-1)); %frequency of second peak
BFloor=0.1; %BFloor is the minimum amplitude value (ignore small values)
Amplitudes=B(B>=BFloor) %find all amplitudes above the BFloor
Frequencies=fax_Hz(IX(1+end-numel(Amplitudes):end)) %frequency of the peaks
채택된 답변
Star Strider
2020년 8월 16일
편집: Star Strider
2020년 8월 16일
Try this:
SG = load('DataSG.txt');
L = numel(SG);
Fs = 1E+3; % Sampling Frequency
Fn = Fs/2; % Nyquist Frequency
Ts = 1/Fs;
t = linspace(0, L, L)*Ts;
figure
plot(t, SG)
grid
SGm = SG - mean (SG); % Subtract Mean (D-C Offset) To Make Other Peaks More Visible
FTSG = fft(SGm)/L; % Fourier Transform
Fv = linspace(0, 1, fix(L/2)+1)*Fn; % Frequency Vector
Iv = 1:numel(Fv); % Index Vector
[pks,lcs,w,p] = findpeaks(abs(FTSG(Iv))*2, 'MinPeakProminence',3, 'MinPeakDist',10);
[maxamp,idx] = max(abs(FTSG(Iv))*2);
figure
plot(Fv, abs(FTSG(Iv))*2)
hold on
plot(Fv(lcs), abs(FTSG(Iv(lcs)))*2, '^r')
hold off
grid
xlim([0 50])
text(Fv(idx),maxamp, sprintf('\\leftarrowAmplitude = %.3f\n Frequency = %.3f Hz', maxamp, Fv(idx)), 'HorizontalAlignment','left', 'VerticalAlignment','top')
It plots the peak frequency and significant harmonics.
Experiment with it to get the result you want.
EDIT — (16 Aug 2020 at 16:38)
Added plot image —
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/346662/image.png)
.
댓글 수: 4
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Spectral Measurements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!