i need to filter this ode45 sine wave becomes a smooth one...

조회 수: 8 (최근 30일)
Amirul Akil
Amirul Akil 2015년 4월 4일
댓글: Amirul Akil 2015년 4월 5일
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.

채택된 답변

Mahdiyar
Mahdiyar 2015년 4월 4일
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,

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Digital Filter Analysis에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by