Fourier transform and Bode Plot from .CSV file

6 ビュー (過去 30 日間)
Thijs Verstegen
Thijs Verstegen 2019 年 4 月 4 日
回答済み: Star Strider 2019 年 4 月 4 日
I'm currently working on a porject that involves the improvement of a industrial scale that is used for dynamic weighing of products/crates (the goal is that products never stop, and that a fast and accurate weighing is made).
The scale currently calculates the weight with the help of analog loadcells ( Load Cells in case you're interested).
These load cells are (for analysis purposes) connected to my laptop through a convertor and special software that allows me to read the data (weight in this case). A set of data can be stored to a .CSV file or to a picture.
As there is a lot of noise in the signal from vibrations etc., I'm planning to analyse where these vibrations come from to make some good improvements to the next version of the scale.
The .CSV file currently has 3 columns: time, measurement, state
The column state can be ignored as this is always equal to '8', there is some text in the top rows that can be ignored as well.
So, in short, the goal is to analyse which frequencies are in the noise using a Fourier Transform and a Bode Plot.
I've looked all over the internet, but I'm unable to find an answer that solves my problem and I'm hoping one of you can maybe help me.
I've added one of the .CSV files and a picture of what the data/graph looks like.
Kind regards,
Thijs
Note:
The program outputs a .CSV file that uses ',' as a decimal point, this is changed to a normal point in Notepad++

回答 (1 件)

Star Strider
Star Strider 2019 年 4 月 4 日
It would have been easier if you had saved your data to a text file rather than to an Excel .csv file.
Try this:
[~,S] = xlsread('ScopeData2.csv');
C = cellfun(@(x)strsplit(x, ';'), S(12:end), 'Uni',0);
D = cellfun(@(x)str2double(x), C, 'Uni',0);
N = reshape([D{:}], 3, [])';
t = N(:,1); % Time Vector
m = N(:,2); % Measurement Vector
L = numel(t); % Length
Fs = 1/mean(diff(t)); % Sampling Frequency
Fn = Fs/2; % Nyquist Frequency
FTm = fft(m)/L; % Normalised Fourier Transform
Fv = linspace(0, 1, fix(L/2)+1)*Fn; % Frequency Vector
Iv = 1:numel(Fv); % Index Vector
figure
plot(Fv, abs(FTm(Iv))*2)
grid
xlim([0 150])
xlabel('Frequency')
ylabel('Amplitude')
title('Fourier Transform of ‘Measurement’')
Wp = [20 28]/Fn; % Bandpass Filter Passband
Ws = [18 30]/Fn; % Bandpass Filter Stopband
Rp = 1; % Passband Ripple
Rs = 50; % Stopband Ripple / Attenuation
[n,Ws] = ellipord(Wp, Ws, Rp, Rs); % Elliptical Filter Order
[z,p,k] = ellip(n,Rp,Rs,Wp); % Elliptical Filter Design
[sos,g] = zp2sos(z,p,k); % Elliptical Filter Implementation
figure
freqz(sos,2^14,1000) % Check Filter Perfoormance
m_filt = filtfilt(sos, g, m); % Filter Signal
figure
plot(t, m_filt) % Plot Filtered Signal
grid
I leave the final filter design to you, since you know what result you want. This is prototype code for it. See the documentation for the various functions to understand how they work. (I now prefer elliptical filters because they are much more computationally efficient than other designs. Also, a bandpass design seems to be best here. Use whatever filter design works best for you.)

カテゴリ

Help Center および File ExchangeVibration Analysis についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by