Numerical Integration on Discrete Data Sets
Ältere Kommentare anzeigen
Hi All,
Im currently trying to run the following code:
close all; % close all programs
clc; % clears command window
clear all; % Clears memory
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Parameters
%Function and Interval
A= csvread('finaldata.csv');
x= A(:,2)
value= @sin
a= 0; % Lower limit of function
b= pi; % Upper limit of function
% Number of Points
N= 1250; % Number of points can be adjusted later
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Discrete Integration
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Positions of the points
dx = (b-a)/N;
x = [0.0010:N - 0.0010]*dx; % Centre positions of segments under the curve to be integrated
% Calculate Function
y = value(x) % Calculates function at midpoints
% Numerical Integration
I_Discrete = sum(y)*dx; % Numerical integration by summing and multiplying by dx
subplot(1,3,1)
plot(x,y)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Trapezoidal Integration
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Positions of the points
x = linspace(a,b,N); % To place N points on a and b exactly
dx = x(2) -x(1); % Extracts spacing between x values
% Calculate Function
y = value(x); % Caluclates function at midpoints
% Numerical Integration
W = [0.5 ones(1,N-2) 0.5];
I_Trap = sum(W.*y)*dx;
subplot(1,3,2)
plot(x,y)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Simpsons 1/3rd Integration
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Positions of the points
x = linspace(a,b,N); % To place N points on a and b exactly
dx = x(2) -x(1); % Extracts spacing between x values
% Calculate Function
y = value(x); % Caluclates function at midpoints
% Numerical Integration
I = 0;
for n = 1 : 2 : N-2
a = y(n) + 4*y(n+1) + y(n+2);
I = I + a;
end
I_simp = I*(dx/3);
subplot(1,3,3)
plot(x,y);
Im trying to feed a data set (it forms a sinewave) to integrate to remove the phase shift on the signal. The program works fine with the sin function, but cannot seem to get it working well with my data set. the data set has two collumns which when plotted together shows the sinewave over a number of periods.
Is it a case that i cannot apply the data in this way? Any help is appreicated.
Andy
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Smoothing finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


