Omega method to integrate sin function
显示 更早的评论
Hi, I'm a student who is practicing with signal processing and matlab. I'm trying to integrate a sine function dividing it by (i*2*pi*f). And I'm trying to do that two times as if my signal was an acceleration and I would like to calculate displacement. I can't understand why it works to obtain velocity but it doesn't work with second integration. This is the code. Thank very much to everyone.
clear all; close all; clc;
fs = 20; % sampling frequency
t = 0:1/fs:600; t=t.'; % time vector
f1 = 0.01; % frequency of oscillation
acc = sin(2*pi*f1*t); % signal acceleration
N = length(acc);
plot(t,acc);
acc_fft = fft(acc); % fft of acceleration
f = linspace(0,fs/2,length(acc_fft)); f=f.'; % freequency vector
omega = 2*pi*f; % omega vector
omega(1) = eps; % first term different from zero
vel_fft = acc_fft./(1i*omega); % fft velocity dividing bt i omega
vel = ifft(vel_fft); % velocity in time domain
vel_analytic = -1/(2*pi*f1)*cos(2*pi*f1*t);
plot(t,real(vel));
hold on
plot(t,vel_analytic,'*')
legend('Velocità otenuta da FFT','Velocità analitica')
disp_analytic = -1/(2*pi*f1)^2*sin(2*pi*f1*t); % analytical displacement
figure
plot(t,disp_analytic)
disp_fft = vel_fft./(1i*omega); % fft of displacement dividing vel_fft by (i omega)
disp = ifft(disp_fft); % displacement in time domain
hold on
plot(t,real(disp))
采纳的回答
更多回答(1 个)
You're getting the weird values for disp because of division with eps (very small number).
This code will produce what you expect:
clear all; close all; clc;
fs = 20; % sampling frequency
t = 0:1/fs:600; t=t.'; % time vector
f1 = 0.01; % frequency of oscillation
acc = sin(2*pi*f1*t); % signal acceleration
N = length(acc);
plot(t,acc);
acc_fft = fft(acc); % fft of acceleration
f = linspace(0,fs/2,length(acc_fft)); f=f.'; % freequency vector
omega = 2*pi*f; % omega vector
omega(1) = 1; % first term different from zero
vel_fft = acc_fft./(1i*omega); % fft velocity dividing bt i omega
vel = ifft(vel_fft); % velocity in time domain
vel_analytic = -1/(2*pi*f1)*cos(2*pi*f1*t);
plot(t,real(vel));
hold on
plot(t,vel_analytic,'*')
legend('Velocità otenuta da FFT','Velocità analitica')
disp_analytic = -1/(2*pi*f1)^2*sin(2*pi*f1*t); % analytical displacement
figure
plot(t,disp_analytic)
disp_fft = vel_fft./(2i*omega); % fft of displacement dividing vel_fft by (i omega)
disp = ifft(disp_fft); % displacement in time domain
hold on
plot(t,real(disp),'o')
Please note there is a division with 2*i*omega for finding disp_fft.
I'm not sure why is that, but it may have something to do with even/odd functions. There are many people here who are very familiar with FFT and IFFT and would probably know why this scaling is important.
2 个评论
Tommaso Ballantini
2023-4-13
Askic V
2023-4-13
No, it is not your fault, I added disp_fft = vel_fft./(2i*omega) in order to scale it properly. Your original code had 1i*omega. Execute and see for yourself.
类别
在 帮助中心 和 File Exchange 中查找有关 Filter Analysis 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!










