How to plot Fft of a Wilberforce Pendulum Data

7 views (last 30 days)
if true
% code
endPlease, how can I import the data I generated in Excel into matlab to perform a Fourier transform of the data. I have attached the Excel file for your help. The data is from a "design of Wilberforce pendulum". Do I need to save the file in a certain format?
Your help is really appreciated. Thank you
So I have this code, but how do I bring in my data work with the code?
Fs = 1000; % Sampling frequency
Ts = 1/Fs; % Sample time
L = 5*Fs; % Length of signal
t = (0:L-1)*Ts; % Time vector
[m,n]=size(x_orig); x=x_orig-mean(x_orig)*ones(m,n);
% Plot of data
subplot(4,1,1); plot(t,x_orig);
subplot(4,1,2); plot(t,x);
subplot(4,1,3); plot(t(1:200),x(1:200));
y=x+1*randn(size(t)); % Random noize with a standard deviation of 1
subplot(4,1,4); plot(t(1:200),y(1:200));
% Compute FFT of y(t)
% Compute the FFT
NFFT = 2^nextpow2(L); % Next power of 2 from length of y
Y = fft(y,NFFT)/L;
f = Fs/2*linspace(0,1,NFFT/2+1);
% Plot single-sided amplitude spectrum.
title('Single-Sided Power Spectral Density')
xlabel('Frequency (Hz)')
%Butterworth low-pass filter
[b1,a1] = butter(1,Fc/(Fs/2)); % 1st order butter low-pass filter
freqz(b1,a1); hold on;
[b2,a2] = butter(2,Fc/(Fs/2)); % 2nd order butter low-pass filter
freqz(b2,a2); hold on;
[b6,a6] = butter(6,Fc/(Fs/2)); % 6th order butter low-pass filter
y1 = filter(b1,a1,y); Y1 = fft(y1,NFFT)/L;
y2 = filter(b2,a2,y); Y2 = fft(y2,NFFT)/L;
y6 = filter(b6,a6,y); Y6 = fft(y6,NFFT)/L;
plot(f,2*abs(Y(1:NFFT/2+1)),'k:'); hold on;
plot(f,2*abs(Y1(1:NFFT/2+1)),'r.-'); hold on;
plot(f,2*abs(Y2(1:NFFT/2+1)),'g.-'); hold on;
plot(f,2*abs(Y6(1:NFFT/2+1)),'b.-'); legend('Original','1st order butter', '2nd order butter', '6th order butter');
title('Single-Sided Power Spectral Density');
xlabel('Frequency (Hz)');
% Elliptic low-pass filter
[be6, ae6] = ellip(6,5,40,Fc/(Fs/2));
ye6 = filter(be6,ae6,y); Ye6 = fft(ye6,NFFT)/L;
plot(f,2*abs(Y(1:NFFT/2+1)),'r.-'); hold on;
plot(f,2*abs(Y6(1:NFFT/2+1)),'g.-'); hold on;
plot(f,2*abs(Ye6(1:NFFT/2+1)),'b.-'); legend('Orginal','6th order butter', '6th order elliptic');
title('Single-Sided Power Spectral Density');
xlabel('Frequency (Hz)');
% Butterworth stop filter
[bs3,as3] = butter(3,[0.4 0.6], 'stop'); % 6th order butter stop filter
ys3 = filter(bs3,as3,y); Ys3 = fft(ys3,NFFT)/L;
plot(f,2*abs(Y(1:NFFT/2+1)),'r.-'); hold on;
plot(f,2*abs(Ys3(1:NFFT/2+1)),'g.-'); legend('Original', '6th order butter stop');
title('Single-Sided Power Spectral Density')
xlabel('Frequency (Hz)')
% Butterworth band-pass filter
[bp3,ap3] = butter(3,[0.4 0.6]); % 6th order butter pass filter
yp3 = filter(bp3,ap3,y); Yp3 = fft(yp3,NFFT)/L;
plot(f,2*abs(Y(1:NFFT/2+1)),'r.-'); hold on;
plot(f,2*abs(Yp3(1:NFFT/2+1)),'g.-'); legend('Original', '6th order butter band-pass');
title('Single-Sided Power Spectral Density')
xlabel('Frequency (Hz)')

Answers (1)

Elizabeth Reese
Elizabeth Reese on 7 Dec 2017
I would recommend starting with the Import Tool. This will let you easily import the XLS data as a table, numeric matrix, or column vectors. Line 407 in your data looks empty, so you can decide how MATLAB handles importing that row. For example, you can select the Range to be A2:E1004 and then create a rule to Exclude rows with blank cells to eliminate row 407. Then you can select the Output Type to be of your preference. If you select "Column vectors" then the names of your columns (which is row 1) are taken as the new variable names for each column.
From there, it looks like you have all of the FFT code already working.
  1 Comment
biniam tsegai
biniam tsegai on 1 Dec 2020
Dear elizabeth, where is line 407, I am trying to excess or upload data from excel as well,
and kind of understand but not exactly, if can verifiy please
thank you

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!