HP Forums
Signals: Convolution - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html)
+--- Forum: HP Prime (/forum-5.html)
+--- Thread: Signals: Convolution (/thread-5950.html)



Signals: Convolution - toshk - 03-29-2016 01:04 AM

Extended convolution code found on this forum. StatisticVar1
BAR plots for digital convolution (ask HP to give us stem plot).
Can not plot zeros with Bar plot. Change from BAR plot to LINE plot if you want to see the zeros in the plot.
this code will do piece-wise functions convolution; (LINE plot)
[attachment=5329]


RE: Signals: Convolution - toshk - 03-29-2016 01:23 AM

lets do some convolution now (digital).
square brackets [] digital signal representation NOT accepted.

[attachment=3299]
conv({1,2,3,4,5},{10,9,,8,7,6,5,4,3,2,1})

[attachment=3298]
conv({1,2,3,4,0,0,0,0},{1,0,1,0,1,0,0,0})

[attachment=3300]
syntax for Piecewise function {} only!!!! CAS x only
{func1, range1, func2, range2,......}
{-x+2,x<1,2,1<=x<5,.5x+1,5>=x}
conv({-x+2,x<1,2,1<=x<5,.5x+1,5>=x},{1,0,1,0,1,0,0,0})

[attachment=3301]
{0,x<-1,6*x+6,-1<=x<2,18,2<=x<7,0,7<=x}
conv({-x+2,x<1,2,1<=x<5,.5x+1,5>=x},{0,x<-1,6*x+6,-1<=x<2,18,2<=x<7,0,7<=x})


RE: Signals: Convolution - cperrinekc - 04-10-2017 10:57 PM

(03-29-2016 01:04 AM)toshk Wrote:  Extended convolution code found on this forum. StatisticVar1
BAR plots for digital convolution (ask HP to give us stem plot).
Can not plot zeros with Bar plot. Change from BAR plot to LINE plot if you want to see the zeros in the plot.
this code will do piece-wise functions convolution; (LINE plot)

Code:

#pragma mode( separator(.,;) integer(h32) )
SAMP();
Set1();
c1;
export conv(v1,v2)
begin 
local p1,p2,var:="x_";
L0:=MAKELIST(X,X,-10,10,1);
A:=5;
purge(var);
IF (TYPE(v1)==6 OR TYPE(v2)==6) THEN SAMP(v1,v2); ELSE
p1:=poly2symb(v1,var); 
p2:=poly2symb(v2,var);
c1:=symb2poly(simplify(p1*p2),var); 
END;
Set1(); 
end;

#cas
SAMP(v1,v2)
BEGIN
local f1,f2;
local n,k,fa1,fa2;
L3:={};L2:={};L4:={};L7:={};
IF even(length(v1)) AND instring(string(v1),"x") THEN 
L3:={};L2:={};L4:={};L7:={};L7:=v1;
FOR n FROM 1 TO size(L7)/2 DO L2:= select((x)->L7(2*n),L0);fa1:=unapply(L7(2*n-1),x); 
FOR k FROM 1 TO length(L2) DO L3(k):=fa1(L2(k));END;
L4:=CONCAT(L4,L3);
END;
f1:=simplify(poly2symb(L4)); A:=4; ELSE f1:=poly2symb(v1,x);
END;
L3:={};L2:={};L4:={};L7:={};
IF even(length(v2)) AND instring(string(v2),"x") THEN L7:=v2;
FOR n FROM 1 TO size(L7)/2 DO L2:= select((x)->L7(2*n),L0);fa2:=unapply(L7(2*n-1),x); 
FOR k FROM 1 TO length(L2) DO L3(k):=fa2(L2(k));END;
L4:=CONCAT(L4,L3);
END;
f2:=simplify(poly2symb(L4)); A:=4; ELSE f2:=poly2symb(v2,x);
END;
c1:=symb2poly(simplify(f1*f2),x); 
L3:={};L2:={};L4:={};L7:={};       
END;
#end

Set1()
BEGIN
startapp("Statistics 1Var");
D1:=mat2list(c1);D2:=MAKELIST(X,X,1,length(c1),1);
Statistics_1Var.H1:={'D1','D2',A};
CHECK(1);
startview(1,1);
END;



RE: Signals: Convolution - cperrinekc - 04-10-2017 10:59 PM

I have been trying to add this code to my HP prime calculator, but i keep getting an error at the line where you have SAMP (v1,v2). Any ideas on how to fix this or what may be going wrong?


RE: Signals: Convolution - toshk - 04-11-2017 07:19 AM

(04-10-2017 10:59 PM)cperrinekc Wrote:  I have been trying to add this code to my HP prime calculator, but i keep getting an error at the line where you have SAMP (v1,v2). Any ideas on how to fix this or what may be going wrong?
Line 2: just after #pragma mode( separator(.,Wink integer(h32) )
instead of SAMP() try SAMP(v1,v2)