Hello All,
I am trying to implement an alpha tunable low pass filter on in PCAN Explorer. My script currently reads the command signal and sends it over the CAN bus. I would like to filter this command signal before its sent. How should I go about implementing this?
Filter Implementation
Smoothing Filter Implementation
Hello All,
I am trying to implement an alpha tunable low pass filter on in PCAN Explorer. My script currently reads the command signal and sends it over the CAN bus. I would like to filter this command signal before its sent. How should I go about implementing this?
Following is the matlab script I would like to implement on the realtime CAN data
Following is the PCAN explorer script where I would like to implement the above filter on the Cmd. My question is how do I access the i-1th Cmd in the script. Thanks.
I am trying to implement an alpha tunable low pass filter on in PCAN Explorer. My script currently reads the command signal and sends it over the CAN bus. I would like to filter this command signal before its sent. How should I go about implementing this?
Following is the matlab script I would like to implement on the realtime CAN data
Code: Select all
Cmd=sin(2*pi*(linspace(1,5,80)));% random data
Cmd=Cmd';
t=0.2; %tau
y=zeros(1,length(Cmd));
y(1,1)=Cmd(1,1);
for i=2:length(Cmd);
y(i)=y(i-1)+(t*(Cmd(i)-y(i-1)));
end
axis([0 80 -5 5])
plot(Cmd,'-r')
hold on;
plot(y,'-g')
set(gca,'Xlim',[0 70],'Ylim',[-1.5 1.5]);
hold off;
Code: Select all
Sub Feedback()
Dim Network1, Network2
Dim Port1, Port2
Dim obj
Dim RecvMsgNetwork1, SendMsgNetwork2
Dim Cmd
Set Network1 = CreateObject("Pcan3.PCANClient")
Set Network2 = CreateObject("Pcan3.PCANClient")
Network1.Name = "CAN1"
Network2.Name = "CAN2"
' Connect to the pre defined Networks
Set Port1 = Network1.Connections.Add("Connection1")
Set Port2 = Network2.Connections.Add("Connection2")
' Receive CAN1 messages
Set RecvMsgNetwork1 = Network1.Messages.Add
Set SendMsgNetwork1 = Network1.Messages.Add
' Send CAN2 messages
Set SendMsgNetwork2 = Network2.Messages.Add
'Message Filter for CAN1
Port1.RegisterMsg &h11BD3659, &h11BD1254, 1, 1
Do 'Forever loop till error or CAN ID found
Do While not RecvMsgNetwork1.Read ' Here we read the driver queue until we received a MSG
Wait(100) ' Cmd frequency
Loop
If RecvMsgNetwork1.LastError = pcanErrorOk Then
With SendMsgNetwork2 ' receive the filtered command
.ID = RecvMsgNetwork1.ID '
.DLC = RecvMsgNetwork1.DLC '
.MsgType = RecvMsgNetwork1.MsgType
.Data(0) = RecvMsgNetwork1.Data(0)
.Data(1) = RecvMsgNetwork1.Data(1)
.Data(2) = RecvMsgNetwork1.Data(2)
.Data(3) = RecvMsgNetwork1.Data(3)
.Data(4) = RecvMsgNetwork1.Data(4)
.Data(5) = RecvMsgNetwork1.Data(5)
.Data(6) = RecvMsgNetwork1.Data(6)
.Data(7) = RecvMsgNetwork1.Data(7)
End With
Cmd = (RecvMsgNetwork1.Data(1) + RecvMsgNetwork1.data(0))
'Combine the two bytes to get command for applying the filter
End Sub
- PEAK-Support
- Sales & Support
- Posts: 1646
- Joined: Fri 10. Sep 2010, 19:34
Re: Filter Implementation
First of all: double posting will not speed up the time until someone send a feedback (we need max. 24h)
I have now merged both posts to one thread. Also, please understand, we do know not if you use a PE4 or PE5 (think it´s a PE5 because of using 2 CAN BUS in a Project). Please always post the Version you use. Also be sure you have update to the latest version. See Start Screen of your PCAN-Explorer.
You have simply copy a sample from us and post it here
Why? You write you like to port a script from MatLab, but i found nothing in the Macro that you post. Its an 1:1 sample for using 2 physical CAN Bus in a project ? Do you need 2 CAN ? Did you understand what the macro does ?
Please read and study the samples and if you have understand how the PE5 macros work, try to repost in a way we could support you. We also offer consulting - so if we should wrote the PE5 script for you, send us a technical specification and we send you an offer. By the way the MatLab support also PEAK-CAN Hardware.
I have now merged both posts to one thread. Also, please understand, we do know not if you use a PE4 or PE5 (think it´s a PE5 because of using 2 CAN BUS in a Project). Please always post the Version you use. Also be sure you have update to the latest version. See Start Screen of your PCAN-Explorer.
You have simply copy a sample from us and post it here

Please read and study the samples and if you have understand how the PE5 macros work, try to repost in a way we could support you. We also offer consulting - so if we should wrote the PE5 script for you, send us a technical specification and we send you an offer. By the way the MatLab support also PEAK-CAN Hardware.
--------------------------------
PEAK-System Technik
Technical Support Team
support[at]peak-system.com
-------------------------------
PEAK-System Technik
Technical Support Team
support[at]peak-system.com
-------------------------------