% Integration approximation and Signal energy and power: % % @ Kefu Xue, Ph.D., June 2006 % % Energy calucation for an exponential signal: % T=10^-3; % pick a sampling frequency (the smaller T the better approximation) D=100; % pickup a duration of 100 seconds N=D/T; % total number of samples t=[0:N-1]*T; xe=3*exp(-2*t); Exe=sum(xe.*xe)*T; disp(['The approximated total energy is ' num2str(Exe)]); % % Power calculation: % f0=20; % fundamental frequency from Maximum Common Factor: 40pi T0=1/f0; % shortest period of the signal T=T0/40; % sampling 40 samples over a period of the signal N=120; % plot 3 periods t=[0:N-1]*T; % time sampling vector s1=2*cos(200*pi*t-1); Ps1=sum(s1(1:40).^2)/40; display(['The power of a sinusoidal s1 (A^2/2) is equal to ' num2str(Ps1)]); s2=sin(120*pi*t+pi/3); Ps2=sum(s2(1:40).^2)/40; display(['The power of a sinusoidal s2 is equal to ' num2str(Ps2)]); s3=-0.5*cos(80*pi*t+2); Ps3=sum(s3(1:40).^2)/40; display(['The power of a sinusoidal s3 is equal to ' num2str(Ps3)]); x=s1+s2+s3; Px=sum(x(1:40).^2)/40; display(['The power of multiple sinusoids is equal to ' num2str(Px)]); % % end of file