Skip to content

Contains both Signal Processing and DSP function (includes test cases) #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
  •  
  •  
  •  
58 changes: 58 additions & 0 deletions DSP functions/allpassbpc2bpc/allpassbpc2bpc.sci
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
function [AllpassNum,AllpassDen]= allpassbpc2bpc (Wo,Wt)
// All pass filter for complex bandpass transformation
//
//Calling Sequence:
//[AllpassNum,AllpassDen]= allpassbpc2bpc (Wo,Wt): returns the numerator, AllpassNum, and the denominator, AllpassDen, of the first-order allpass mapping filter for performing a complex bandpass to complex bandpass frequency transformation. This transformation effectively places two features of an original filter, located at frequencies Wo1 and Wo2, at the required target frequency locations Wt1 and Wt2.In general it is possible to select any feature; e.g., the stopband edge, the DC,etc.
//
//Input Parameters:
// Wo: Frequency values of the prototype filter
// Wt: Desired Frequencies for the target filter
//
//Output Parameters:
// AllpassNum: Numerator of mapping filer
// AllpassDen: Denominator of mapping filter
//Example: Design an allpass mapping filter, changing the complex bandpass filter with the band edges at Wo1=0.3 and Wo2=0.6 to the new band edges of Wt1=0.4 and Wt2=0.8. Find the frequency response of the allpass mapping filter:
//
// Wo = [0.3 0.6]; Wt = [0.4 0.8];
// [AllpassNum, AllpassDen] = allpassbpc2bpc(Wo, Wt);
// [h, f] = freqz(AllpassNum, AllpassDen);
// plot(f/%pi,-angle(h)/%pi);
//
//Author: Shrenik Nambiar
//
//References: 1. Constantinides, A.G., "Spectral transformations for digital filters," IEEE® Proceedings, vol. 117, no. 8, pp. 1585-1590, August 1970.
// 2. Constantinides, A.G., "Design of bandpass digital filters," IEEE Proceedings, vol. 1, pp. 1129-1231, June 1969.
//
// Input Validation Statement
if argn(2) ~=2 then
error("Number of input arguments should be 2");
end

if argn(1)<1 | argn(1)>2 then
error("Number of output arguments should either be 1 or 2");
end

if length(Wo)~=2 | ~isreal(Wo) then
error("Wo must be real, numeric and must contain only 2 elements");
end
if Wo(1)<=-1 | Wo(1)>=1 | Wo(2)<=-1 | Wo(2)>=1 then
error("Wo must lie between -1 and 1");
end

if length(Wt)~=2 | ~isreal(Wt) then
error("Wt must be real,numeric and must contain only 2 elements");
end
if Wt(1)<=-1 | Wt(1)>=1 | Wt(2)<=-1 | Wt(2)>=1 then
error("Wt must lie between -1 and 1");
end

// Calculating the numerator and denominator for the mapping filter

bw1 = max(Wo) - min(Wo);
bw2 = max(Wt) - min(Wt);
be = sin(%pi*(bw1-bw2)/4)/sin(%pi*(bw1+bw2)/4);
al= exp(-%i*%pi*sum(Wt)/2);
AllpassNum = flipdim((conj([al -be] * exp(%i*%pi*sum(Wo)/2))),2);
AllpassDen = flipdim((conj([-be*al 1])),2);

endfunction
7 changes: 7 additions & 0 deletions DSP functions/allpassbpc2bpc/test_1.sce
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Test # 1 : No Input Arguments
exec('./allpassbpc2bpc.sci',-1);
[n,d]=allpassbpc2bpc();
//!--error 10000
//Number of input arguments should be 2
//at line 28 of function allpassbpc2bpc called by :
//[n,d]=allpassbpc2bpc();
13 changes: 13 additions & 0 deletions DSP functions/allpassbpc2bpc/test_10.sce
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Test # 10 : Valid input test case #2
exec('./allpassbpc2bpc.sci',-1);
[n,d]=allpassbpc2bpc([-0.3,-0.112],[-0.42,0.68]);
disp(d);
disp(n);
//
//Scilab Output
//d=1. 0.7108650 + 0.3076188i
//n= 0.6179475 + 0.4670110i 0.4927273 + 0.8701838i
//
//Matlab Output
//n= 0.6179 + 0.4670i 0.4927 + 0.8702i
//d= 1.0000 + 0.0000i 0.7109 + 0.3076i
5 changes: 5 additions & 0 deletions DSP functions/allpassbpc2bpc/test_2.sce
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Test # 2 : Excess Input Arguments
exec('./allpassbpc2bpc.sci',-1);
[n,d]=allpassbpc2bpc([0.3,0.2],[0.1,0.5]);
//!--error 58
//Wrong number of input arguments
5 changes: 5 additions & 0 deletions DSP functions/allpassbpc2bpc/test_3.sce
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Test # 3 : Incorrect number of output Arguments
exec('./allpassbpc2bpc.sci',-1);
[n,d,e]=allpassbpc2bpc([0.4,0.5],[0.1,0.9]);
//!--error 59
//Wrong number of output arguments
7 changes: 7 additions & 0 deletions DSP functions/allpassbpc2bpc/test_4.sce
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Test # 4 : When either Input Argument #1 or #2 is of complex type
exec('./allpassbpc2bpc.sci',-1);
[n,d]=allpassbpc2bpc([0.4*%i,0.7],[0.2,0.5]);
//!--error 10000
//Wo must be real, numeric and must contain only 2 elements
//at line 36 of function allpassbpc2bpc called by :
//[n,d]=allpassbpc2bpc([0.4*%i,0.7],[0.2,0.5]);
7 changes: 7 additions & 0 deletions DSP functions/allpassbpc2bpc/test_5.sce
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Test #5 : Input Argument #1 range test
exec('./allpassbpc2bpc.sci',-1);
[n,d]=allpassbpc2bpc([1.1,0.9],[0.5,0.9]);
//!--error 10000
//Wo must lie between -1 and 1
//at line 39 of function allpassbpc2bpc called by :
//[n,d]=allpassbpc2bpc([1.1,0.9],[0.5,0.9]);
7 changes: 7 additions & 0 deletions DSP functions/allpassbpc2bpc/test_6.sce
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Test #6 : Input Argument #2 range test
exec('./allpassbpc2bpc.sci',-1);
[n,d]=allpassbpc2bpc([0.3,0.1],[-1.4,0.9]);
//!--error 10000
//Wt must lie between -1 and 1
//at line 46 of function allpassbpc2bpc called by :
//[n,d]=allpassbpc2bpc([0.3,0.1],[-1.4,0.9]);
10 changes: 10 additions & 0 deletions DSP functions/allpassbpc2bpc/test_7.sce
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Test #7 : For 1 output argument
exec('./allpassbpc2bpc.sci',-1);
[n]=allpassbpc2bpc([0.1,0.2],[-0.5,0.8]);
disp(n);
//
//Scilab Output
//n=0.8090170-0.4122147i 1.
//
//Matlab Output
//n = 0.8090 - 0.4122i 1.0000 + 0.0000i
7 changes: 7 additions & 0 deletions DSP functions/allpassbpc2bpc/test_8.sce
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Test # 8 : Input Argument #1 or #2 length test
exec('./allpassbpc2bpc.sci',-1);
[n,d]=allpassbpc2bpc([0.3,0.2],0.6);
//!--error 10000
//Wt must be real,numeric and must contain only 2 elements
//at line 43 of function allpassbpc2bpc called by :
//[n,d]=allpassbpc2bpc([0.3,0.2],0.6);
13 changes: 13 additions & 0 deletions DSP functions/allpassbpc2bpc/test_9.sce
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Test # 9 : Valid input test case #1
exec('./allpassbpc2bpc.sci',-1);
[n,d]=allpassbpc2bpc([0.3,0.7],[0.2,0.8]);
disp(d);
disp(n);
//
//Scilab Output
//d=1. 1.355D-17 + 0.2212317i
//n=1.355D-17-0.2212317i 1.

//Matlab Output
//n=0.0000 - 0.2212i 1.0000 + 0.0000i
//d=1.0000 + 0.0000i 0.0000 + 0.2212i
56 changes: 56 additions & 0 deletions DSP functions/allpasslp2bp/allpasslp2bp.sci
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
function [AllpassNum,AllpassDen]= allpasslp2bp (Wo,Wt)
// All pass filter for lowpass to bandpass transformation
//
//Calling Sequence:
//[[AllpassNum,AllpassDen] = allpasslp2bp(Wo,Wt): returns the numerator, AllpassNum, and the denominator, AllpassDen, of the second order allpass mapping filter for performing a real lowpass to real bandpass frequency transformation. This transformation effectively places one feature of an original filter, located at frequency -Wo, at the required target frequency location, Wt1, and the second feature, originally at +Wo, at the new location, Wt2. This transformation implements the "DC mobility," which means that the Nyquist feature stays at Nyquist, but the DC feature moves to a location dependent on the selection of Wt.
//
//Input Parameters:
// Wo: Frequency value of the prototype filter
// Wt: Desired Frequencies for the target filter
//
//Output Parameters:
// AllpassNum: Numerator of mapping filer
// AllpassDen: Denominator of mapping filter
//Example: Design the allpass mapping filter changing the lowpass filter with cutoff frequency at Wo=0.4 to the real–valued bandpass filter with cutoff frequencies at Wt1=0.2 and Wt2=0.3.
//
// Wo = 0.4; Wt = [0.2 0.3];
// [AllpassNum, AllpassDen] = allpasslp2bp(Wo, Wt);
// [h, f] = freqz(AllpassNum, AllpassDen);
// plot(f/%pi,-angle(h)/%pi);
//
//Author: Shrenik Nambiar
//
//References: 1. Constantinides, A.G., "Spectral transformations for digital filters," IEEE® Proceedings, vol. 117, no. 8, pp. 1585-1590, August 1970.
// 2. Constantinides, A.G., "Design of bandpass digital filters," IEEE Proceedings, vol. 1, pp. 1129-1231, June 1969.
//
// Input Validation Statements
if argn(2) ~=2 then
error("Number of input arguments should be 2");
end

if argn(1)<1 | argn(1)>2 then
error("Number of output arguments should either be 1 or 2");
end

if ~isscalar(Wo) | ~isreal(Wo) then
error("Wo must be real ,numeric and scalar");
end
if Wo<=0 | Wo>=1 then
error("Wo must lie between 0 and 1");
end

if length(Wt)~=2 | ~isreal(Wt) then
error("Wt must be real and numeric and must contain only 2 elements");
end
if Wt(1)<=0 | Wt(1)>=1 | Wt(2)<=0 | Wt(2)>=1 then
error("Wt must lie between 0 and 1");
end

//Calculating the numerator and denominator for the mapping filter
bw = abs(Wt(2) - Wt(1));
al = sin(%pi*(Wo-bw)/2) / sin(%pi*(Wo+bw)/2);
be= cos(%pi*sum(Wt)/2) / cos(%pi*bw/2);
AllpassNum = -[al -be*(1+al) 1];
AllpassDen = -flipdim(AllpassNum,2);

endfunction
7 changes: 7 additions & 0 deletions DSP functions/allpasslp2bp/test_1.sce
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Test # 1 : No Input Arguments
exec('./allpasslp2bp.sci',-1);
[n,d]=allpasslp2bp();
//!--error 10000
//Number of input arguments should be 2
//at line 28 of function allpasslp2bp called by :
//[n,d]=allpasslp2bp();
13 changes: 13 additions & 0 deletions DSP functions/allpasslp2bp/test_10.sce
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Test # 10 : Valid input test case #2
exec('./allpasslp2bp.sci',-1);
[n,d]=allpasslp2bp(0.23,[0.22,0.48]);
disp(d);
disp(n);
//
//Scilab Output
//d=1. -0.4611906 -0.0676902
//n=0.0676902 0.4611906 -1.

//Matlab Output
//n=0.0677 0.4612 -1.0000
//d=1.0000 -0.4612 -0.0677
5 changes: 5 additions & 0 deletions DSP functions/allpasslp2bp/test_2.sce
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Test # 2 : Excess Input Arguments
exec('./allpasslp2bp.sci',-1);
[n,d]=allpasslp2bp(0.3,[0.1,0.5],0.4);
//!--error 58
//Wrong number of input arguments
5 changes: 5 additions & 0 deletions DSP functions/allpasslp2bp/test_3.sce
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Test # 3 : Incorrect number of output Arguments
exec('./allpasslp2bp.sci',-1);
[n,d,e]=allpasslp2bp(0.1,[0.5,0.9]);
//!--error 59
//Wrong number of output arguments
7 changes: 7 additions & 0 deletions DSP functions/allpasslp2bp/test_4.sce
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Test # 4 : When either Input Argument #1 or #2 is of complex type
exec('./allpasslp2bp.sci',-1);
[n,d]=allpasslp2bp(0.4,[0.1,0.2*%i]);
//!--error 10000
//Wt must be real and numeric and must contain only 2 elements
//at line 43 of function allpasslp2bp called by :
//[n,d]=allpasslp2bp(0.4,[0.1,0.2*%i]);
7 changes: 7 additions & 0 deletions DSP functions/allpasslp2bp/test_5.sce
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Test #5 : Input Argument #1 range test
exec('./allpasslp2bp.sci',-1);
[n,d]=allpasslp2bp(1.1,[0.5,0.9]);
//!--error 10000
//Wo must lie between 0 and 1
//at line 39 of function allpasslp2bp called by :
//[n,d]=allpasslp2bp(1.1,[0.5,0.9]);
7 changes: 7 additions & 0 deletions DSP functions/allpasslp2bp/test_6.sce
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Test #6 : Input Argument #2 range test
exec('./allpasslp2bp.sci',-1);
[n,d]=allpasslp2bp(0.3,[-1.4,0.9]);
//!--error 10000
//Wt must lie between 0 and 1
//at line 46 of function allpasslp2bp called by :
//[n,d]=allpasslp2bp(0.3,[-1.4,0.9]);
10 changes: 10 additions & 0 deletions DSP functions/allpasslp2bp/test_7.sce
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Test #7 : For 1 output argument
exec('./allpasslp2bp.sci',-1);
[n]=allpasslp2bp(0.1,[0.5,0.8]);
disp(n);
//
//Scilab Output
//n=0.5257311 -0.2416521 -1.
//
//Matlab Output
//n=0.5257 -0.2417 -1.0000i
7 changes: 7 additions & 0 deletions DSP functions/allpasslp2bp/test_8.sce
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Test # 8 : Input Argument #1 or #2 length test
exec('./allpasslp2bp.sci',-1);
[n,d]=allpasslp2bp([0.3,0.2],[0.6,0.8]);
//!--error 10000
//Wo must be real ,numeric and scalar
//at line 36 of function allpasslp2bp called by :
//[n,d]=allpasslp2bp([0.3,0.2],[0.6,0.8]);
13 changes: 13 additions & 0 deletions DSP functions/allpasslp2bp/test_9.sce
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Test # 9 : Valid input test case #1
exec('./allpasslp2bp.sci',-1);
[n,d]=allpasslp2bp(0.7,[0.49,0.78]);
disp(d);
disp(n);
//
//Scilab Output
//d=1. 0.7334144 0.6004943
//n=- 0.6004943 - 0.7334144 -1.

//Matlab Output
//n= -0.6005 -0.7334 -1.0000
//d= 1.0000 0.7334 0.6005
57 changes: 57 additions & 0 deletions DSP functions/allpasslp2bpc/allpasslp2bpc.sci
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
function [AllpassNum,AllpassDen]= allpasslp2bpc (Wo,Wt)
// All pass filter for lowpass to bandpass transformation
//
//Calling Sequence:
//[AllpassNum,AllpassDen] = allpasslp2bpc(Wo,Wt): returns the numerator, AllpassNum, and the denominator, AllpassDen, of the first-order allpass mapping filter for performing a real lowpass to complex bandpass frequency transformation. This transformation effectively places one feature of an original filter, located at frequency -Wo, at the required target frequency location, Wt1, and the second feature, originally at +Wo, at the new location, Wt2. It is assumed that Wt2 is greater than Wt1.
//
//Input Parameters:
// Wo: Frequency value of the prototype filter
// Wt: Desired Frequencies for the target filter
//
//Output Parameters:
// AllpassNum: Numerator of mapping filer
// AllpassDen: Denominator of mapping filter
//Example: Design the allpass mapping filter changing the lowpass filter with cutoff frequency at Wo=0.6 to the complex–valued bandpass filter with cutoff frequencies at Wt1=0.4 and Wt2=0.5.
//
// Wo = 0.6; Wt = [0.4 0.5];
// [AllpassNum, AllpassDen] = allpasslp2bpc(Wo, Wt);
// [h, f] = freqz(AllpassNum, AllpassDen);
// plot(f/%pi,-angle(h)/%pi);
//
//Author: Shrenik Nambiar
//
//References: 1. Constantinides, A.G., "Spectral transformations for digital filters," IEEE® Proceedings, vol. 117, no. 8, pp. 1585-1590, August 1970.
// 2. Constantinides, A.G., "Design of bandpass digital filters," IEEE Proceedings, vol. 1, pp. 1129-1231, June 1969.
//
// Input Validation Statements
if argn(2) ~=2 then
error("Number of input arguments should be 2");
end

if argn(1)<1 | argn(1)>2 then
error("Number of output arguments should either be 1 or 2");
end

if ~isscalar(Wo) | ~isreal(Wo) then
error("Wo must be real ,numeric and scalar");
end
if Wo<=0 | Wo>=1 then
error("Wo must lie between 0 and 1");
end

if length(Wt)~=2 | ~isreal(Wt) then
error("Wt must be real,numeric and must contain only 2 elements");
end
if Wt(1)<=0 | Wt(1)>=1 | Wt(2)<=0 | Wt(2)>=1 then
error("Wt must lie between 0 and 1");
end

//Calculating the numerator and denominator for the mapping filter
Wc = sum(Wt)/2;
bw = max(Wt) - min(Wt);
al = sin(%pi*(Wo-bw/2)/2) / sin(%pi*(Wo+bw/2)/2);
be= exp(-%pi*%i*Wc);
AllpassNum = flipdim(conj([be -al]),2);
AllpassDen = flipdim(conj([-al*be 1]),2);

endfunction
7 changes: 7 additions & 0 deletions DSP functions/allpasslp2bpc/test_1.sce
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Test # 1 : No Input Arguments
exec('./allpasslp2bpc.sci',-1);
[n,d]=allpasslp2bpc();
//!--error 10000
//Number of input arguments should be 2
//at line 28 of function allpasslp2bpc called by :
//[n,d]=allpasslp2bpc();
13 changes: 13 additions & 0 deletions DSP functions/allpasslp2bpc/test_10.sce
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Test # 10 : Valid input test case #2
exec('./allpasslp2bpc.sci',-1);
[n,d]=allpasslp2bpc(0.17,[0.9,0.95]);
disp(d);
disp(n);
//
//Scilab Output
//d=1. 0.7281417 - 0.1748114i
//n=-0.7488320 -0.9723699 + 0.2334454i

//Matlab Output
//n= -0.7488 + 0.0000i -0.9724 + 0.2334i
//d= 1.0000 + 0.0000i 0.7281 - 0.1748i
5 changes: 5 additions & 0 deletions DSP functions/allpasslp2bpc/test_2.sce
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Test # 2 : Excess Input Arguments
exec('./allpasslp2bpc.sci',-1);
[n,d]=allpasslp2bpc(0.2,[0.1,0.9],0.4);
//!--error 58
//Wrong number of input arguments
5 changes: 5 additions & 0 deletions DSP functions/allpasslp2bpc/test_3.sce
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Test # 3 : Incorrect number of output Arguments
exec('./allpasslp2bpc.sci',-1);
[n,d,e]=allpasslp2bpc(0.3,[0.4,0.9]);
//!--error 59
//Wrong number of output arguments
7 changes: 7 additions & 0 deletions DSP functions/allpasslp2bpc/test_4.sce
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Test # 4 : When either Input Argument #1 or #2 is of complex type
exec('./allpasslp2bpc.sci',-1);
[n,d]=allpasslp2bpc(0.1,[0.3,0.4*%i]);
//!--error 10000
//Wt must be real,numeric and must contain only 2 elements
//at line 43 of function allpasslp2bpc called by :
//[n,d]=allpasslp2bpc(0.1,[0.3,0.4*%i]);
Loading