i need to filter this ode45 sine wave becomes a smooth one...
2 views (last 30 days)
Show older comments
i used this line of code, and i implement Lowpass FIR filter, but maybe the code i used is wrong somewhere. can anybody help me fixed this
error popped is 'Index exceeds Matrix dimension' and 'Error using forced (line 2),Not enough input arguments.'
these are the codes
EDITOR: 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 WINDOW: 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 %UNTIL HERE IT WORKS FINE
fHandle=@forced; Fs=20; fc=3; t=linspace(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') %the error appear here...
any suggestion or helps, much thanks.
0 Comments
Accepted Answer
Mahdiyar
on 4 Apr 2015
Hi Akil
I think you need this, of Course I am not sure about the technical point of view
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
clear
clc
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
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')
Regards,
More Answers (0)
See Also
Categories
Find more on Single-Rate Filters 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!