filter ode45 sinewave becomes smoother
1 view (last 30 days)
Show older comments
i used this line of code, for ode45, and these is the figure i got..
now, i need to filter the result becomes like this(example):
so, to filter my ode45, i used this line of codes that i refered from this webpage ( http://uk.mathworks.com/help/signal/ug/filtering-data-with-signal-processing-toolbox.html ) below are the the codes:
Function:
function dxdt = forced(t,x)
dxdt_1 = x(2);
dxdt_2 = -100*x(2)-250000*x(1)+ ((25000)*((0.00002)*sin(2.6735*t)).^3);
dxdt = [dxdt_1; dxdt_2];
Command Windows:
tspan=[0:0.1:20];
initial_x=0; initial_dxdt=0;
[t,x]=ode45(@forced,tspan,[initial_x initial_dxdt]);
figure
plot(t,x(:,1));
grid on % ode45
fHandle=forced(t,x);
Fs=20;
fc=3;
t=0:0.1:Fs;
Wn=(2/Fs)*fc;
b=fir1(20,Wn,'low',kaiser(21,3));
fvtool(b,1,'Fs',Fs)
z=filter(b,1,fHandle);
plot(t(1:100),fHandle(1:100),'--')
hold on
plot(t(1:100),z(1:100),':')
xlabel('Time(s)')
ylabel('Amplitude')
legend('Original Signal','Filtered Data')
but maybe the code i used is wrong somewhere. result is not as desired. here is what i got:
so, anybody can help me to correct these codes to filter my data...
any suggestion or helps, much thanks
2 Comments
Star Strider
on 5 Apr 2015
I am at a bit of a loss as to understanding what you are doing and what you want to do. If you want a smoother result from your ODE integration, my first approach would be to use a finer increment for ‘tspan’, so instead of:
tspan=[0:0.1:20];
use:
tspan=linspace(0, 20, 500);
I don’t quite follow the filter design, though. What do you want to get from filtering your signal? Did you use the freqz function with it so you have some idea of its frequency and phase chatacteristics? There may be more appropriate filter designs for what you want to do.
Answers (0)
See Also
Categories
Find more on Filter Analysis in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!