% Parseval theorem 定理数值验证
%clean the command window
clc;
% clean the worksapce
clear;
% close all figures
close all;
format compact;
% sample rate, dots/second
fs = 256;
% time, from 0 to 4 seconds
t = 0:1/fs:4-1/fs;
% amplitue of sine function
A = 100;
% a simulated signal
x = A/2*sin(2*pi*3*t) + A/2*sin(2*pi*7*t) + A/2*sin(2*pi*11*t) + A/2*sin(2*pi*15*t) ;
% change it to vector
x = x(:);
% length of signal
n = length(x);
% FFT length
nfft = 2^nextpow2(n);
% select a window-function, for example hamming window, boxcar window, blackman
% window
win = @hamming;
% window multiplication
xw = x .* win(n);
% sum of the squared signal
result1 = sum(xw .* xw)
% fft, transform the signal to the frequency domain
H = fft(xw,nfft);
%
result2 = sum(abs(H).^2) / nfft
% is it equal ?
result1 - result2
if result1 - result2 < 1e-6
display('equal^_^');
else
display('not equal, :(');
end
% if you want to do some further observe
figure;
subplot(211);
plot(t, x, 'b'); grid;
legend('raw signal');
subplot(212);
plot(t,xw, 'r'); grid
legend('windowed signal');
% Parseval theorem 定理数值验证(一个例子, 入门MATLAB)
最新推荐文章于 2024-07-22 23:00:00 发布