Omega method to integrate sin function
Show older comments
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))
Accepted Answer
More Answers (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 Comments
Tommaso Ballantini
on 13 Apr 2023
Askic V
on 13 Apr 2023
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.
Categories
Find more on Filter Analysis in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!









