From 70bac5392d8a84c43ceaf2e1a49cb375734d20b6 Mon Sep 17 00:00:00 2001 From: Shrenik Nambiar Date: Tue, 25 Jul 2017 23:19:39 +0530 Subject: [PATCH 01/15] Add files via upload --- .../Signal Processing functions/bandpower.sci | 203 ++++++++++++++++ .../Signal Processing functions/demod.sci | 202 ++++++++++++++++ .../Signal Processing functions/sfdr.sci | 228 ++++++++++++++++++ .../Signal Processing functions/sinad.sci | 192 +++++++++++++++ .../Signal Processing functions/stepz.sci | 108 +++++++++ .../Signal Processing functions/tf2latc.sci | 133 ++++++++++ Functions/Signal Processing functions/toi.sci | 176 ++++++++++++++ 7 files changed, 1242 insertions(+) create mode 100644 Functions/Signal Processing functions/bandpower.sci create mode 100644 Functions/Signal Processing functions/demod.sci create mode 100644 Functions/Signal Processing functions/sfdr.sci create mode 100644 Functions/Signal Processing functions/sinad.sci create mode 100644 Functions/Signal Processing functions/stepz.sci create mode 100644 Functions/Signal Processing functions/tf2latc.sci create mode 100644 Functions/Signal Processing functions/toi.sci diff --git a/Functions/Signal Processing functions/bandpower.sci b/Functions/Signal Processing functions/bandpower.sci new file mode 100644 index 0000000..be61250 --- /dev/null +++ b/Functions/Signal Processing functions/bandpower.sci @@ -0,0 +1,203 @@ +function power= bandpower(varargin) +// To find the bandpower of an input signal +// Calling sequences +// +//power= bandpower(x) : It returns the average power of the input matrix,x +// +//power= bandpower(x,fs,freqrange) : Returns the average power in the frequency range whose length must be 2. This function uses periodogram to determine the average power. +// +//power= bandpower(pxx,f,'psd') : In this case the average power is computed by integrating the power spectral density estimate,pxx. The input f is a vector of frequencies corresponding to pxx. 'psd' indicates its not time series data. +// +//power= bandpower(pxx,f,freqrange,'psd') : Similar to the above type except the average power is computed within the frequency range specified. +// +//Input parameters: +// x: Time series input of type double or scalar +// fs: Sampling frequency and must be positive scalar +// freqrange: The frequency range within which the average power is to be computed +// pxx: Power spectral density estimates. Must be nonnegatuve of type double or inte//ger +// f: Frequency vector for psd estimates. Must be of type double or integer +// +//Output Parameters: +// +// power: Average band power of type double or integer. +// +//Example: Create a signal consisting of a 100 Hz sine wave in additive N(0,1) white Gaussian noise. +// t = 0:0.001:1-0.001; +// x = cos(2*pi*100*t)+randn(size(t)); +// p = bandpower(x) +//Author: Shrenik Nambiar +// +//Input validation statements +// +// + if(argn(1) ~= 1) then + error(" Only one output argument allowed"); + end + if(argn(2)<1 | argn(2)>4 | argn(2)== 2) then + error("The no. of input arguments should be 1,3 or 4"); + end + + flag= find(strcmpi(varargin(:),'psd')); + varargin(flag)= []; + + if (flag) then + power= bandpowerfrompsd(varargin(1),varargin(2),varargin(3)); + else + power= bandpowerfromsignal(varargin(1),varargin(2),varargin(3)); + end + +endfunction + +function power = bandpowerfromsignal(x,fs,freqrange) + +// To convert the vector into column vector + if isvector(x) then + x=x(:); + end + +// THe input vector should either be a 1D vector or a 2D matrix + if (ndims(x)~= 1 | ndims(x)~= 2) then + error(" x should either be a vector or 2 matrix"); + end + +//Checking for argument type + if(type(x)~= 1 | type(x)~= 8) then + error(" Argument should be of type int or double"); + end + +//Performing Typecasting + x=double(x); + +// When the function has only 1 input parameter + if(argn(2)== 1) then + x2=x.^2; + power= sum(x2,'r'); + end + +// fs must be positive scalar + if length(fs)~= 1 then + error("fs must not be a vector"); + end + + if(type(fs)~= 1 | type(fs)~= 8) then + error(" Argument should be of type int or double"); + end + fs= double(fs); + +// Checking the freqrange parameter + if ~isempty(freqrange) then + if length(freqrange)~=2 then + error("freqrange must be a vector of 2 elements"); + end + if(type(freqrange)~= 1 | type(freqrange)~= 8) then + error(" Argument should be of type int or double"); + end + if freqrange(1)>=freqrange(2) then + error("1st element should be smaller than the second element"); + end + +//Performing Typecasting + freqrange = double(freqrange(:)); + end + + n = size(x,1); + + if isreal(x) then + [pxx, f] = periodogram(x, hamming(n), n, fs); + else + [pxx, f] = periodogram(x, hamming(n), n, fs, 'centered'); + end + power = bandpowerfrompsd(pxx, f, freqrange); + +endfunction + +function power= bandpowerfrompsd(pxx,f,freqrange) + +//Making it column vector + if isvector(pxx) then + pxx=pxx(:); + end + + if ndims(pxx)<1 | ndims(pxx)>2 then + error("Wrong dimesnion for argument #1 (pxx); must be vector or a 2D matrix"); + end + + if(type(pxx)~= 1 | type(pxx)~= 8) then + error(" Argument should be of type int or double"); + end + +// All the elements of pxx must b non-negative + for i=1:length(pxx) + if(pxx(i)<0) then + error("pxx must be non negative") + end + end + +//Performing Typecasting + pxx = double(pxx); + +//Checking the f parameter + if ~isvector(f) | size(pxx,1)~=length(f) then + error(" f should be a vector of same size as pxx"); + end + if(type(f)~= 1 | type(f)~= 8) then + error("Argument should be of type int or double"); + end + + if (diff(f)<=0) then + error("f must be strictly increasing"); + end + f = double(f(:)); + +//Checking for freqrange parameter + if ~isempty(freqrange) then + + if length(freqrange)~=2 then + error("freqrange must be a vector of 2 elements"); + end + if(type(freqrange)~= 1 | type(freqrange)~= 8) then + error("Argument should be of type int or double"); + end + + if freqrange(1)>=freqrange(2) then + error("1st element should be smaller than the second element"); + end + + if freqrange(1)f($) then + error("freqrange should lie between f"); + end + freqrangeflag=true; + freqrange = double(freqrange(:)); + else + + freqrange= [f(1) f($)]; + freqrangeflag= false; + + end + + f = f(:); + index1= find(f<=freqrange(1),1); + index2= find(f>=freqrange(2),1); + +//As we are approximating the integral using the rectangle method, we must find the width of the rectangle + + binwidth= diff(f); + +//For n is even,the nyquist point is fs/2, hence the emissing range is at the beginning of the vector + if freqrangeflag then + lastbinwidth=0; + binwidth= [binwidth; lastbinwidth]; + else + +//if the no. of points is odd, then the missing frequencies is present at both ends,but as the signal spectrum is symmetric the missing frequency can be assumedto be at the bginning of the vector + missingbinwidth = (f($) - f(1)) / (length(f) - 1); + centre = (f(1)==0); + if ~centre then + binwidths = [missingbinwidth; binwidths]; + else + binwidths = [binwidths; missingbinwidth]; + end + end + power = binwidths(index1:index2)'*pxx(index1:index2,:); + +endfunction diff --git a/Functions/Signal Processing functions/demod.sci b/Functions/Signal Processing functions/demod.sci new file mode 100644 index 0000000..1ac7a75 --- /dev/null +++ b/Functions/Signal Processing functions/demod.sci @@ -0,0 +1,202 @@ +function [x1,varargout]= demod (y,fc,fs,method,varargin) +//Demodulation for communication systems +//Calling Sequences +// +//x = demod(y,fc,fs,'method') +//x = demod(y,fc,fs,'method',opt) +//x = demod(y,fc,fs,'pwm',centered) +// +//Input parameters: +// y: Real carrier signal +// fc: Carrier frequency +// fs: Sampling frequency +// method: There are 9 methods for demodulating a modulated signal and a few of them//also accepts an extra parameter , opt + +// amdsb-sc or am: +// Amplitude demodulation (am), double sideband (sdb), suppressed carrier(sc) : Multiplies y by a sinusoid of frequency fc and applies a fifth-order Butterworth lowpass filter using filtfilt. +// +// amdsb-tc: +// Amplitude demodulation, double sideband, transmitted carrier (tc). Multiplies y by a sinusoid of frequency fc and applies a fifth-order Butterworth lowpass filter using filtfilt. +// If opt is specified, demod subtracts scalar opt from x. The default value for opt is 0. + +// amssb: +// Amplitude demodulation, single sideband. Multiplies y by a sinusoid of frequency fc and applies a fifth-order Butterworth lowpass filter using filtfilt. +// +// fm: +// Frequency demodulation. Demodulates the FM waveform by modulating the Hilbert transform of y by a complex exponential of frequency -fc Hz and obtains the instantaneous frequency of the result. +// +// pm: +// Phase demodulation. Demodulates the PM waveform by modulating the Hilbert transform of y by a complex exponential of frequency -fc Hz and obtains the instantaneous phase of the result. +// +// ppm: +// Pulse-position demodulation. Finds the pulse positions of a pulse-position modulated signal y. For correct demodulation, the pulses cannot overlap. x is length length(t)*fc/fs. +// +// pwm: +// Pulse-width demodulation. Finds the pulse widths of a pulse-width modulated signal y. demod returns x a vector whose elements specify the width of each pulse in fractions of a period. The pulses in y should start at the beginning of each carrier period, that is, they should be left justified. +// +// qam: +// Quadrature amplitude demodulation. +// +// [x1,x2] = demod(y,fc,fs,'qam') multiplies y by a cosine and a sine of frequency fc and applies a fifth-order Butterworth lowpass filter using filtfilt. +// +// The default method is am. +// +//Output parameters: +// x1: Demodulated signal. In all cases except ppm and pwm,x is the same size as y +// +// +//Author: Shrenik Nambiar +// +//References: B.P. Lathi, Modern digital and analog communication systems, Oxford University Press, 1998. +// Rappaport, Theodore S. Wireless Communications: Principles and Practice. Upper Saddle River, NJ: Prentice Hall, 1996 +// +//Input validation statements + + [out,in] = argn(0); + + if(in ~=3 | in ~=4 | in~= 5) then + error(" Number of Input parameters should either be 4 or 5"); + end + + if(out ~= 1 | out~= 2) then + error("Number of output parameters should either be 1 or 2"); + end + +//Checking whether the user entered arguments are of numeric type + + if(isnumeric(fc) & isnumeric(fs) & isnumeric(y)) then + fc= float(fc); + fs= float(fs); + y= float(y); + else + error(" All three parameters should be of numeric type"); + end + +//To check if it satisfies Nyquist Theorem + if(~(fs > 2*fc)) then + error("Not obeying the Nyquist theorem"); + end + + + method= ''; + + if(in == 3) then + method= 'am'; + end + + [row,col] = size(y); + if row==0 | col==0 then + x1=[]; + end + +// Column vector conversion + if(row==1) then + y=y(:); + l=col; + else + l=row; + end + +//For each type of demoulation technique enterd by the user, one of the if elseif block will be executed + if(strcmpi(method,'am') | strcmpi(method,'amdsb-sc')) | strcmpi(method,'amdsb-tc') | strcmpi(method,'amssb') then + + t= (0:1/fs:(l-1)/fs)'; + t=t(:,ones(1,size(y,2))); + x1= y.*cos(2*%pi*fc*t); + [b,a]= butter(5,fc*2/fs); + + for i=1:size(y,2) + x1(:,i) = filtfilt(b,a,x1(:,i)); + end + + if strcmpi(method,'amdsb-tc') then + if(in<5) then + options=0; + end + options=float(options); + + x1=x1-options; + end + + elseif(strcmpi(method,'fm')) then + if(in<5) then + options=1; + end + + options=float(options); + t= (0:1/fs:(l-1)/fs)'; + t=t(:,ones(1,size(y,2))); + yh= hilbert(y).*exp(-%i*2*%pi*fc*t); + x1= (1/options)*[zeros(1,size(yh,2));diff(unwrap(angle(yh)))]; + elseif(strcmpi(method,'pm')) then + if(in<5) then + options=1; + end + + options=float(options); + t= (0:1/fs:(l-1)/fs)'; + t=t(:,ones(1,size(y,2))); + yh= hilbert(y).*exp(-%i*2*%pi*fc*t); + x1= (1/options)*angle(yh); + elseif(strcmpi(method,'pwm') & type(varargin(1))== 10) then + y=y>0.5; //for thresholding purposes + t= (0:1/fs:(l-1)/fs)'; + l= ceil(l*fc/fs); //length of the signal + x1= zeros(l,size(y,2)); //initializing the vector + if(in<5) then + options = 'left'; + end + if(strcmpi(options,'centred')) then + for i = 1:l, + temp= t-(i-1)/fc; + index= (temp >= -0.5/fc) & (temp<=0.5*fc); + for j1= 1:size(y,2) + x1(i,j1) = sum(y(index,j1))*fc/fs; + end + end + x1(1,:) = x1(1,:)*2; + elseif(strcmpi(options,'left')) then + for i=1:l, + temp = t-(i-1)/fc; + index= (temp>=0) & (temp <1/fc) ; + for j2= 1:size(y,2) + x1(i,j2) = sum(y(index,j2))*fc/fs; + end + end + else + error("Invalid option"); + end + elseif(strcmpi(method,'ppm')) then + y=y>0.5; + t= (0:1/fs:(l-1)/fs)'; + l= ceil(l*fc/fs); //length of the message signal + x1= zeros(l,size(y,2)); + for i=1:l, + temp = t-(i-1); + index= find(temp>=0) & (temp <1) ; + for j3= 1:size(y,2) //accessing each element columnwise + index2 = y(index,j3)==1; + x1(i,j3) = temp(min(index,index2)); + end + end + elseif(strcmpi(method,'qam')) then + t= (0:1/fs:(len-1)/fs)'; + t=t(:,ones(1,size(y,2))); + x1= 2*.y*cos(2*%pi*fc*t); + x2= 2*.y*sin(2*%pi*fc*t); + [b,a]= butter(5,fc*2/fs); + for i=1:size(y,2) + x1(:,i)= filtfilt(b,a,x1(:,i)); + x2(:,i)= filtfilt(b,a,x2(:,i)); + end + + if(row==1) then + x2=x2'; //converting to column vector + end + end + + if(row==1) then + x1=x1'; + end + +endfunction diff --git a/Functions/Signal Processing functions/sfdr.sci b/Functions/Signal Processing functions/sfdr.sci new file mode 100644 index 0000000..d7821a3 --- /dev/null +++ b/Functions/Signal Processing functions/sfdr.sci @@ -0,0 +1,228 @@ +function [varargout]= sfdr(varargin) + + if(argn(1)<0 | argn(1)>3) then + error("Output arguments should lie between 0 and 3"); + end + + if(argn(2)<1 | argn(2)>4) then + error("Input arguments should lie between 1 and 4"); + end + + if (~isvector(x) & (type(x) ~=8 | type(x) ~= 1)) then + error("x should be a vector of type doule or integer"); + end + + if (~isscalar(fs) & fs<0) then + error("fs must be positive scalar"); + end + + if (~isscalar(msd) & msd<0) then + error("msd must be positive scalar"); + end + + if(~isvector(sxx) & (type(sxx) ~=8 | type(sxx) ~= 1) & sxx<0) then + error("power estimate vector must be non-negative vector of type double or integer"); + end + + if(~isvector(f) & (type(f) ~=8 | type(f) ~= 1)) then + error(" f must be a vector of type double or integer"); + end + + if argn(1)==0 then + flag=1; + else + flag=0; + end + if(argn(2)<2) then + x=varargin(1); + fs=1; + msd=0; + [r, spurpow, spurfreq]= timesfdr(x,fs,msd); + elseif(argn(2)==2) then + x=varargin(1); + fs=varargin(2); + msd=0; + [r, spurpow, spurfreq]= timesfdr(x,fs,msd); + elseif(argn(2)==3 & type(varargin(3)~=10)) then + x=varargin(1); + fs=varargin(2); + msd=varargin(3); + [r, spurpow, spurfreq]= timesfdr(x,fs,msd); + elseif(argn(2) == 3 & strcmpi(varargin(3),'power')) then + sxx= varargin(1); + f= varargin(2); + msd=0; + [r, spurpow, spurfreq]= powersfdr(sxx,f,msd); + elseif(argn(2)== 4 & strcmpi(varargin(4),'power')) then + sxx= varargin(1) ; + f= varargin(2); + msd= varargin(3); + [r, totdistpow]= powersfdr(sxx,f,msd); + else + error("The valid flag is power"); + end + +endfunction + +function [r,totdistpow] = timesfdr(flag,x,fs,msd) + + if max(size(x))==length(x) then + x=x(:); + end + n= length(x); + x=x-mean(x); + w= window('kr',n,38); + rbw= enbw(w,fs); + [pxx, f] = periodogram(x,w,n,fs); + + signalCopy=pxx; + pxx(1)= 2*pxx(2); + [pfreq,rfreq,ifreq,left,right] = dcremove(pxx,f,rbw,0); + pxx(left:right)= 0; + dcindex = [left;right]; + + [pfreq,rfreq,ifreq,left,right] = dcremove(pxx,f,rbw); + pxx(left:right)= 0; + freqindex = [left;right]; + + pxx(abs(f-ffreq) sxx(freqbin:$-1),1,'first')-1; + if isempty(leftbin) + leftbin = 1; + end + + if isempty(rightbin) + rightbin = length(sxx); + end + + leftbinex = find(F <= fundfreq - msd, 1, 'last'); + rightbinex = find(fundfreq + msd < f, 1, 'first'); + if ~isempty(leftbinex) & leftbinex < leftbin + leftbin = leftbinex; + end + if ~isempty(rightbinex) & rightbinex > rightbin + rightbin = rightbinex; + end + +endfunction + +function[r,spurpow, spurfreq] = powersfdr (flag,sxx,f,msd) + + if(f(1) ~=0) then + error("sxx must be one-sided"); + end + + sigSCopy = sxx; + + sxx(1) = 2*sxx(1); + lastindex = find(sxx(1:$-1) 0 & pxx(indexleft) <= pxx(indexleft+1) + indexleft = indexleft - 1; + end + + + while indexright <= length(pxx) & pxx(indexright-1) >= pxx(indexright) + indexright = indexright + 1; + end + + indexleft = indexleft+1; + indexright = indexright-1; + ffreq = f(indexleft:indexright); + sfreq = pxx(indexleft:indexright); + fr = (ffreq.*sfreq) ./ sum(sfreq); + + if (indexleft2) then + error("Output arguments should lie between 0 and 2"); + end + + if(argn(2)<1 | argn(2)>4) then + error("Input arguments should lie between 1 and 4"); + end + + if (~isvector(x) & (type(x) ~=8 | type(x) ~= 1)) then + error("x should be a vector of type doule or integer"); + end + + if (~isscalar(fs) & fs<0) then + error("fs must be positive scalar"); + end + + if(~isvector(pxx) & (type(pxx) ~=8 | type(pxx) ~= 1) & pxx<0) then + error("psd estimate vector must be non-negative vector of type double or integer"); + end + + if(~isvector(sxx) & (type(sxx) ~=8 | type(sxx) ~= 1) & sxx<0) then + error("power estimate vector must be non-negative vector of type double or integer"); + end + + if(~isvector(f) & (type(f) ~=8 | type(f) ~= 1)) then + error(" f must be a vector of type double or integer"); + end + + + if(~isscalar(rbw) & (type(rbw) ~=8 | type(rbw) ~= 1) & rbw<0) then + error("rbw must be positive scalar"); + end + + if(argn(1)==0) then + flag=1; + else + flag=0; + end + + + if(argn(2)<2) then + x=varargin(1); + fs=1; + [r, totdistpow]= sampsinad(x,fs); + elseif(argn(2)==2) then + x=varargin(1); + fs=varargin(2); + [r, totdistpow]= sampsinad(x,fs); + elseif(argn(2) == 3 & strcmpi(varargin(3),'psd')) then + pxx= varargin(1); + f= varargin(2); + [r, totdistpow]= psdsinad(pxx,f); + elseif(argn(2)== 4 & strcmpi(varargin(4),'power')) then + sxx= varargin(1) ; + f= varargin(2); + rbw= varargin(3); + [r, totdistpow]= powersinad(sxx,f,rbw); + else + error("The valid flags are psd and power"); + end +endfunction + +function [r,totdistpow] = sampsinad(flag,x,fs) + + if max(size(x))==length(x) then + x=x(:); + end + + x=x-mean(x); + n=length(x); + //w= window('kr',n,38); + //rbw= enbw(w,fs); + //[pxx, f] = periodogram(x,w,n,fs,'psd'); + + [r, totdistpow]= sinadcalc(flag,pxx,f,rbw); + +endfunction + +function [r,totdistpow]= powersinad(flag,sxx,f,rbw) + if(f(1) ~=0) then + error("pxx must be one-sided"); + end + df= mean(diff(f)); + [r, totdistpow]= sinadcalc(flag,sxx/rbw,f,rbw) +endfunction + +function [r,totdistpow]= psdsinad(flag,pxx,f,rbw) + if(f(1) ~=0) then + error("pxx must be one-sided"); + end + df= mean(diff(f)); + [r, totdistpow]= sinadcalc(flag,pxx,f,df); +endfunction + +function [r, noisepower] = sinadcalc(flag,pxx,f,rbw) + signalCopy= pxx; + pxx(1)= 2*pxx(1); + [pfreq,rfreq,ifreq,left,right] = dcremove(pxx,f,rbw,0); + pxx(left:right)= 0; + dcindex = [left;right]; + + [pfreq,rfreq,ifreq,left,right] = dcremove(pxx,f,rbw); + pxx(left:right)= 0; + freqindex = [left;right]; + + noiseden= median(pxx(pxx>0)) + pxx(pxx == 0)= noiseden; + + pxx= min([pxx signalCopy], [],2); + totalnoise= bandpower(pxx,f,'psd'); + + r= 10*log10(pfreq/totalnoise); + noisepower= 10*log10(totalnoise); + + if flag then + plotfunction(signalCopy,f,rbw,ifreq,dcindex,freqindex); + end + +endfunction + +function plotfunction(pxx,f,rbw,ifreq,dcindex,freqindex) + pxx=pxx*rbw; + + xd= f(freqindex(1):freqindex(2)); + yd=10*log10(pxx(freqindex(1):freqindex(2))); + plot(xd,yd,'r'); + + + xd=f; + yd=10*log10(pxx); + plot(xd,yd,'g'); + + + xd=f(dcindex(1):dcindex(2)); + yd=10*log10(pxx(dcindex(1):dcindex(2))); + plot(xd,yd,'b'); + + +endfunction + +function [power, fr, indextone, indexleft, indexright]= dcremove(pxx, f, rbw, tonefreq) + + if(f(1)<=tonefreq & tonefreq<=f($)) then + [s, indextone] = min(abs(f-tonefreq)); + iLeft = max(1,indextone-1); + iRight = min(indextone+1,length(pxx)); + [s, indexmax] = max(pxx(iLeft:iRight)); + indextone = iLeft+indexmax-1; + else + power = NaN; + fr = NaN; + indextone = []; + indexleft = []; + indexright = []; + end + + indexleft = indextone - 1; + indexright = indextone + 1; + while indexleft > 0 & pxx(indexleft) <= pxx(indexleft+1) + indexleft = indexleft - 1; + end + + + while indexright <= length(pxx) & pxx(indexright-1) >= pxx(indexright) + indexright = indexright + 1; + end + + indexleft = indexleft+1; + indexright = indexright-1; + ffreq = f(indexleft:indexright); + sfreq = pxx(indexleft:indexright); + fr = (ffreq.*sfreq) ./ sum(sfreq); + + if (indexleft4) then + error("Input arguments should lie between 1 and 4"); + end + + if(argn(1) ~=2) then + error("Outpu argument should be 2"); + end + flag= true; + if(size(b)> [1 1]) then + + if(size(b,2) ~= 6) then + error(" SOS must be k by 6 matrix"); + end + flag = false; + if argn(2)>1 then + n= varargin(1); + else + n=[]; + end + + if argn(2)>2 then + fs = varargin(2); + else + fs=1; + end + + if( type(n) ~=8) then + error("n must be of type double"); + end + + if(type(fs) ~= 8) then + error("fs must be of type double"); + end + + if (type(b) ~=8) then + error(" "); + end + end + + + + if flag then + if(argn(2)>1) + a= varargin(1); + if (size(a)> [1 1]) then + error(" a has wrong input size"); + end + else + a=1; + end + + if(argn(2)>2) then + n= varargin(2); + else + n=[]; + end + + if(argn(2)>3) then + fs= varargin(3); + else + fs=1; + end + + if(type(n) ~=8) then + error(" n must be of type double"); + end + + if(type(fs) ~=8) then + error(" fs must be of type double"); + end + + if( type(b) ~=8 & type(a)~= 8) then + error("b and a should be of type double"); + end + + end + + t=0; + N=[]; + + if (argn(2)<2) then + if flag + n =impzlength(b,a); + else + n= impzlength(b); + end + elseif(length(n)>1) + N= round(n); + n =max(N)+1; + M= min(min(N),0); + end + + t1 = (t:(n-1))'/fs; + + x = ones(size(t1)); + if flag + s= filter(b,a,x); + else + s= sfilter(b,x); + end + + if ~isempty(N) then + s= s(N-m+1); + t1= t1(N-m+1); + end + +endfunction diff --git a/Functions/Signal Processing functions/tf2latc.sci b/Functions/Signal Processing functions/tf2latc.sci new file mode 100644 index 0000000..3a4689e --- /dev/null +++ b/Functions/Signal Processing functions/tf2latc.sci @@ -0,0 +1,133 @@ +function [k,v]= tf2latc(varargin) + +// To convert transfer function filter parameters to lattice filter form +// Calling sequences +// +// +//[k,v]= tf2latc(b,a) : GIves both the lattice and ladder parameters on providing the numerator and +// denominator transfer function coefficients +// +//k= tf2latc(1,a) : Outputs the lattice parameters for an all pole lattice filter +// +//[k,v]= tf2latc(1,a) : Outputs both the lattice and ladder parameters for an all pole lattice filter +// +//k= tf2latc(b) : Gives the lattice parameters for an FIR lattice filter +// +//k= tf2latc(b,'phase') : 'phase' denotes the type of FIR filter, which can be 'max'(maximum phase filter) and 'min' (minimum phase filter) + +//Input parameters: +// b: Numerator coefficients of the transfer function +// a: Denominator coefficients of the transfer function +// +//Output Parametrs: +// k: lattice parameters +// v: ladder parmeters +// +//Example: +// +// Convert an IIR filters to its corresponding lattice parameters +// a=[1 1/5 3/5]; +// k=tf2latc(1,a); +// +//Author: Shrenik Nambiar +// +//References: John G.Proakis, Dimitris G.Manolakis, Digital Signal Processing, Pearson Publishers,//Fourth Edition +// M.H Hayes, Statistical Digital Signal Processing and Modelling,John Wiley and Sons,1996 +// +//Input validation statements + + + if(argn(2)<1) then + error("Atleast one input argument required"); + end + + b= varargin(1); + a = []; + phase=''; + + if (max(abs(b)) == 0) then + error("Numerator coefficients should not be zero"); + end + +//b= b./b(1); //normalizing +//a= a/a(1); + + b=b(:); //converting into column vectors + a=a(:); + +//According to the input given by the user,the below piece of code will direct the flow exectution to the appropriate function. + + if(argn(1)==2 & length(varargin)==2) then + if(varargin(1)==1) then + a= varargin(2); + [k v]= allpole2latc(b,a); + else + b= varargin(1); + a= varargin(2); + [k v]= iir2latc(b,a); + end + elseif(argn(1)==1 & length(varargin)==2) then + if(type(varargin(2))==10) then + b= varargin(1); + phase= varargin(2); + select phase + case "max" then + [k v]= fir2latc(b,a); + case "min" then + [k v]= fir2latc(b,a); + else + error("Invalid option, input should either be max or min"); + end + else + a= varargin(2); + b= varargin(1); + [k v]= allpole2latc(b,a); + end + elseif(argn(1)==1 & length(varargin)==1) then + b= varargin(1); + [k v]= fir2latc(b,a); + else + error("Too many input arguments"); + end + + +endfunction + +function [k,v]= allpole2latc(b,a) + + k= poly2rc(a); + v= [b;zeros(length(k))]; + +endfunction + + +function [k,v]= iir2latc(b,a) + + [b,a] = eqtflength(b,a); //to make the size of numerator and denominator equal + len= length(a); + k= poly2rc(a); + + [p,temp] = rlevinson(a,1); + v= zeros(len,1); + + for i = len:-1:1, + term= temp*v; + v(i)= b(i)-term(i); + end + v=flipdim(v,1); +endfunction + +function [k,v]= fir2latc(b,a) + + v = []; + if(argn(2)==1) then + v=b; + k=zeros(length(v)-1,1); + elseif(argn(2)==2) then + if(strcmpi(phase,'max')) then + b= conj(b($:-1:1)); //conjugating the polynomial to make it minimum phase filter + end + k= poly2rc(a); + end + +endfunction diff --git a/Functions/Signal Processing functions/toi.sci b/Functions/Signal Processing functions/toi.sci new file mode 100644 index 0000000..97379ec --- /dev/null +++ b/Functions/Signal Processing functions/toi.sci @@ -0,0 +1,176 @@ +function[oip3, fundpow, fundfreq, imodpow, imodfreq]= toi(varargin) + + if(argn(1)<0 | argn(1)>5) then + error("Output arguments should lie between 0 and 5"); + end + + if(argn(2)<1 | argn(2)>4) then + error("Input arguments should lie between 1 and 4"); + end + + if (~isvector(x) & (type(x) ~=8 | type(x) ~= 1)) then + error("x should be a vector of type doule or integer"); + end + + if (~isscalar(fs) & fs<0) then + error("fs must be positive scalar"); + end + + if(~isvector(pxx) & (type(pxx) ~=8 | type(pxx) ~= 1) & pxx<0) then + error("psd estimate vector must be non-negative vector of type double or integer"); + end + + + if(~isvector(sxx) & (type(sxx) ~=8 | type(sxx) ~= 1) & sxx<0) then + error("power estimate vector must be non-negative vector of type double or integer"); + end + + if(~isvector(f) & (type(f) ~=8 | type(f) ~= 1)) then + error(" f must be a vector of type double or integer"); + end + + + if(~isscalar(rbw) & (type(rbw) ~=8 | type(rbw) ~= 1) & rbw<0) then + error("rbw must be positive scalar"); + end + + if(argn(1)==0) then + flag=1; + else + flag=0; + end + + if(argn(2)<2) then + x=varargin(1); + fs=1; + [oip3, fundpow, fundfreq, imodpow, imodfreq]= timetoi(flag,x,fs); + elseif(argn(2)==2) then + x=varargin(1); + fs=varargin(2); + [oip3, fundpow, fundfreq, imodpow, imodfreq]= timetoi(flag,x,fs); + elseif(argn(2) == 3 & strcmpi(varargin(3),'psd')) then + pxx= varargin(1); + f= varargin(2); + [oip3, fundpow, fundfreq, imodpow, imodfreq]= psdtoi(flag,pxx,f); + elseif(argn(2)== 4 & strcmpi(varargin(4),'power')) then + sxx= varargin(1) ; + f= varargin(2); + rbw= varargin(3); + [oip3, fundpow, fundfreq, imodpow, imodfreq]= powertoi(flag,sxx,f,rbw); + else + error("The valid flags are psd and power"); + end + +endfunction + +function [oip3, fundpow, fundfreq, imodpow, imodfreq] = timetoi(flag,x,fs) + + if max(size(x))==length(x) then + x=x(:); + end + + x=x-mean(x); + n=length(x); + w= window('kr',n,38); + rbw= enbw(w,fs); + [pxx, f] = periodogram(x,w,n,fs,'psd'); + + [oip3, fundpow, fundfreq, imodpow, imodfreq]= toicalc(flag,pxx,f,rbw); + +endfunction + +function [oip3, fundpow, fundfreq, imodpow, imodfreq]= powertoi(flag,sxx,f,rbw) + if(f(1) ~=0) then + error("pxx must be one-sided"); + end + df= mean(diff(f)); + + if(rbw 0 & pxx(indexleft) <= pxx(indexleft+1) + indexleft = indexleft - 1; + end + + + while indexright <= length(pxx) & pxx(indexright-1) >= pxx(indexright) + indexright = indexright + 1; + end + + indexleft = indexleft+1; + indexright = indexright-1; + ffreq = f(indexleft:indexright); + sfreq = pxx(indexleft:indexright); + fr = (ffreq.*sfreq) ./ sum(sfreq); + + if (indexleft Date: Tue, 25 Jul 2017 23:24:18 +0530 Subject: [PATCH 02/15] Delete bandpower.sci --- .../Signal Processing functions/bandpower.sci | 203 ------------------ 1 file changed, 203 deletions(-) delete mode 100644 Functions/Signal Processing functions/bandpower.sci diff --git a/Functions/Signal Processing functions/bandpower.sci b/Functions/Signal Processing functions/bandpower.sci deleted file mode 100644 index be61250..0000000 --- a/Functions/Signal Processing functions/bandpower.sci +++ /dev/null @@ -1,203 +0,0 @@ -function power= bandpower(varargin) -// To find the bandpower of an input signal -// Calling sequences -// -//power= bandpower(x) : It returns the average power of the input matrix,x -// -//power= bandpower(x,fs,freqrange) : Returns the average power in the frequency range whose length must be 2. This function uses periodogram to determine the average power. -// -//power= bandpower(pxx,f,'psd') : In this case the average power is computed by integrating the power spectral density estimate,pxx. The input f is a vector of frequencies corresponding to pxx. 'psd' indicates its not time series data. -// -//power= bandpower(pxx,f,freqrange,'psd') : Similar to the above type except the average power is computed within the frequency range specified. -// -//Input parameters: -// x: Time series input of type double or scalar -// fs: Sampling frequency and must be positive scalar -// freqrange: The frequency range within which the average power is to be computed -// pxx: Power spectral density estimates. Must be nonnegatuve of type double or inte//ger -// f: Frequency vector for psd estimates. Must be of type double or integer -// -//Output Parameters: -// -// power: Average band power of type double or integer. -// -//Example: Create a signal consisting of a 100 Hz sine wave in additive N(0,1) white Gaussian noise. -// t = 0:0.001:1-0.001; -// x = cos(2*pi*100*t)+randn(size(t)); -// p = bandpower(x) -//Author: Shrenik Nambiar -// -//Input validation statements -// -// - if(argn(1) ~= 1) then - error(" Only one output argument allowed"); - end - if(argn(2)<1 | argn(2)>4 | argn(2)== 2) then - error("The no. of input arguments should be 1,3 or 4"); - end - - flag= find(strcmpi(varargin(:),'psd')); - varargin(flag)= []; - - if (flag) then - power= bandpowerfrompsd(varargin(1),varargin(2),varargin(3)); - else - power= bandpowerfromsignal(varargin(1),varargin(2),varargin(3)); - end - -endfunction - -function power = bandpowerfromsignal(x,fs,freqrange) - -// To convert the vector into column vector - if isvector(x) then - x=x(:); - end - -// THe input vector should either be a 1D vector or a 2D matrix - if (ndims(x)~= 1 | ndims(x)~= 2) then - error(" x should either be a vector or 2 matrix"); - end - -//Checking for argument type - if(type(x)~= 1 | type(x)~= 8) then - error(" Argument should be of type int or double"); - end - -//Performing Typecasting - x=double(x); - -// When the function has only 1 input parameter - if(argn(2)== 1) then - x2=x.^2; - power= sum(x2,'r'); - end - -// fs must be positive scalar - if length(fs)~= 1 then - error("fs must not be a vector"); - end - - if(type(fs)~= 1 | type(fs)~= 8) then - error(" Argument should be of type int or double"); - end - fs= double(fs); - -// Checking the freqrange parameter - if ~isempty(freqrange) then - if length(freqrange)~=2 then - error("freqrange must be a vector of 2 elements"); - end - if(type(freqrange)~= 1 | type(freqrange)~= 8) then - error(" Argument should be of type int or double"); - end - if freqrange(1)>=freqrange(2) then - error("1st element should be smaller than the second element"); - end - -//Performing Typecasting - freqrange = double(freqrange(:)); - end - - n = size(x,1); - - if isreal(x) then - [pxx, f] = periodogram(x, hamming(n), n, fs); - else - [pxx, f] = periodogram(x, hamming(n), n, fs, 'centered'); - end - power = bandpowerfrompsd(pxx, f, freqrange); - -endfunction - -function power= bandpowerfrompsd(pxx,f,freqrange) - -//Making it column vector - if isvector(pxx) then - pxx=pxx(:); - end - - if ndims(pxx)<1 | ndims(pxx)>2 then - error("Wrong dimesnion for argument #1 (pxx); must be vector or a 2D matrix"); - end - - if(type(pxx)~= 1 | type(pxx)~= 8) then - error(" Argument should be of type int or double"); - end - -// All the elements of pxx must b non-negative - for i=1:length(pxx) - if(pxx(i)<0) then - error("pxx must be non negative") - end - end - -//Performing Typecasting - pxx = double(pxx); - -//Checking the f parameter - if ~isvector(f) | size(pxx,1)~=length(f) then - error(" f should be a vector of same size as pxx"); - end - if(type(f)~= 1 | type(f)~= 8) then - error("Argument should be of type int or double"); - end - - if (diff(f)<=0) then - error("f must be strictly increasing"); - end - f = double(f(:)); - -//Checking for freqrange parameter - if ~isempty(freqrange) then - - if length(freqrange)~=2 then - error("freqrange must be a vector of 2 elements"); - end - if(type(freqrange)~= 1 | type(freqrange)~= 8) then - error("Argument should be of type int or double"); - end - - if freqrange(1)>=freqrange(2) then - error("1st element should be smaller than the second element"); - end - - if freqrange(1)f($) then - error("freqrange should lie between f"); - end - freqrangeflag=true; - freqrange = double(freqrange(:)); - else - - freqrange= [f(1) f($)]; - freqrangeflag= false; - - end - - f = f(:); - index1= find(f<=freqrange(1),1); - index2= find(f>=freqrange(2),1); - -//As we are approximating the integral using the rectangle method, we must find the width of the rectangle - - binwidth= diff(f); - -//For n is even,the nyquist point is fs/2, hence the emissing range is at the beginning of the vector - if freqrangeflag then - lastbinwidth=0; - binwidth= [binwidth; lastbinwidth]; - else - -//if the no. of points is odd, then the missing frequencies is present at both ends,but as the signal spectrum is symmetric the missing frequency can be assumedto be at the bginning of the vector - missingbinwidth = (f($) - f(1)) / (length(f) - 1); - centre = (f(1)==0); - if ~centre then - binwidths = [missingbinwidth; binwidths]; - else - binwidths = [binwidths; missingbinwidth]; - end - end - power = binwidths(index1:index2)'*pxx(index1:index2,:); - -endfunction From cdfadf09b710211ecdfa7599256cc2eba2f8f5a3 Mon Sep 17 00:00:00 2001 From: Shrenik Nambiar Date: Tue, 25 Jul 2017 23:24:46 +0530 Subject: [PATCH 03/15] Delete demod.sci --- .../Signal Processing functions/demod.sci | 202 ------------------ 1 file changed, 202 deletions(-) delete mode 100644 Functions/Signal Processing functions/demod.sci diff --git a/Functions/Signal Processing functions/demod.sci b/Functions/Signal Processing functions/demod.sci deleted file mode 100644 index 1ac7a75..0000000 --- a/Functions/Signal Processing functions/demod.sci +++ /dev/null @@ -1,202 +0,0 @@ -function [x1,varargout]= demod (y,fc,fs,method,varargin) -//Demodulation for communication systems -//Calling Sequences -// -//x = demod(y,fc,fs,'method') -//x = demod(y,fc,fs,'method',opt) -//x = demod(y,fc,fs,'pwm',centered) -// -//Input parameters: -// y: Real carrier signal -// fc: Carrier frequency -// fs: Sampling frequency -// method: There are 9 methods for demodulating a modulated signal and a few of them//also accepts an extra parameter , opt - -// amdsb-sc or am: -// Amplitude demodulation (am), double sideband (sdb), suppressed carrier(sc) : Multiplies y by a sinusoid of frequency fc and applies a fifth-order Butterworth lowpass filter using filtfilt. -// -// amdsb-tc: -// Amplitude demodulation, double sideband, transmitted carrier (tc). Multiplies y by a sinusoid of frequency fc and applies a fifth-order Butterworth lowpass filter using filtfilt. -// If opt is specified, demod subtracts scalar opt from x. The default value for opt is 0. - -// amssb: -// Amplitude demodulation, single sideband. Multiplies y by a sinusoid of frequency fc and applies a fifth-order Butterworth lowpass filter using filtfilt. -// -// fm: -// Frequency demodulation. Demodulates the FM waveform by modulating the Hilbert transform of y by a complex exponential of frequency -fc Hz and obtains the instantaneous frequency of the result. -// -// pm: -// Phase demodulation. Demodulates the PM waveform by modulating the Hilbert transform of y by a complex exponential of frequency -fc Hz and obtains the instantaneous phase of the result. -// -// ppm: -// Pulse-position demodulation. Finds the pulse positions of a pulse-position modulated signal y. For correct demodulation, the pulses cannot overlap. x is length length(t)*fc/fs. -// -// pwm: -// Pulse-width demodulation. Finds the pulse widths of a pulse-width modulated signal y. demod returns x a vector whose elements specify the width of each pulse in fractions of a period. The pulses in y should start at the beginning of each carrier period, that is, they should be left justified. -// -// qam: -// Quadrature amplitude demodulation. -// -// [x1,x2] = demod(y,fc,fs,'qam') multiplies y by a cosine and a sine of frequency fc and applies a fifth-order Butterworth lowpass filter using filtfilt. -// -// The default method is am. -// -//Output parameters: -// x1: Demodulated signal. In all cases except ppm and pwm,x is the same size as y -// -// -//Author: Shrenik Nambiar -// -//References: B.P. Lathi, Modern digital and analog communication systems, Oxford University Press, 1998. -// Rappaport, Theodore S. Wireless Communications: Principles and Practice. Upper Saddle River, NJ: Prentice Hall, 1996 -// -//Input validation statements - - [out,in] = argn(0); - - if(in ~=3 | in ~=4 | in~= 5) then - error(" Number of Input parameters should either be 4 or 5"); - end - - if(out ~= 1 | out~= 2) then - error("Number of output parameters should either be 1 or 2"); - end - -//Checking whether the user entered arguments are of numeric type - - if(isnumeric(fc) & isnumeric(fs) & isnumeric(y)) then - fc= float(fc); - fs= float(fs); - y= float(y); - else - error(" All three parameters should be of numeric type"); - end - -//To check if it satisfies Nyquist Theorem - if(~(fs > 2*fc)) then - error("Not obeying the Nyquist theorem"); - end - - - method= ''; - - if(in == 3) then - method= 'am'; - end - - [row,col] = size(y); - if row==0 | col==0 then - x1=[]; - end - -// Column vector conversion - if(row==1) then - y=y(:); - l=col; - else - l=row; - end - -//For each type of demoulation technique enterd by the user, one of the if elseif block will be executed - if(strcmpi(method,'am') | strcmpi(method,'amdsb-sc')) | strcmpi(method,'amdsb-tc') | strcmpi(method,'amssb') then - - t= (0:1/fs:(l-1)/fs)'; - t=t(:,ones(1,size(y,2))); - x1= y.*cos(2*%pi*fc*t); - [b,a]= butter(5,fc*2/fs); - - for i=1:size(y,2) - x1(:,i) = filtfilt(b,a,x1(:,i)); - end - - if strcmpi(method,'amdsb-tc') then - if(in<5) then - options=0; - end - options=float(options); - - x1=x1-options; - end - - elseif(strcmpi(method,'fm')) then - if(in<5) then - options=1; - end - - options=float(options); - t= (0:1/fs:(l-1)/fs)'; - t=t(:,ones(1,size(y,2))); - yh= hilbert(y).*exp(-%i*2*%pi*fc*t); - x1= (1/options)*[zeros(1,size(yh,2));diff(unwrap(angle(yh)))]; - elseif(strcmpi(method,'pm')) then - if(in<5) then - options=1; - end - - options=float(options); - t= (0:1/fs:(l-1)/fs)'; - t=t(:,ones(1,size(y,2))); - yh= hilbert(y).*exp(-%i*2*%pi*fc*t); - x1= (1/options)*angle(yh); - elseif(strcmpi(method,'pwm') & type(varargin(1))== 10) then - y=y>0.5; //for thresholding purposes - t= (0:1/fs:(l-1)/fs)'; - l= ceil(l*fc/fs); //length of the signal - x1= zeros(l,size(y,2)); //initializing the vector - if(in<5) then - options = 'left'; - end - if(strcmpi(options,'centred')) then - for i = 1:l, - temp= t-(i-1)/fc; - index= (temp >= -0.5/fc) & (temp<=0.5*fc); - for j1= 1:size(y,2) - x1(i,j1) = sum(y(index,j1))*fc/fs; - end - end - x1(1,:) = x1(1,:)*2; - elseif(strcmpi(options,'left')) then - for i=1:l, - temp = t-(i-1)/fc; - index= (temp>=0) & (temp <1/fc) ; - for j2= 1:size(y,2) - x1(i,j2) = sum(y(index,j2))*fc/fs; - end - end - else - error("Invalid option"); - end - elseif(strcmpi(method,'ppm')) then - y=y>0.5; - t= (0:1/fs:(l-1)/fs)'; - l= ceil(l*fc/fs); //length of the message signal - x1= zeros(l,size(y,2)); - for i=1:l, - temp = t-(i-1); - index= find(temp>=0) & (temp <1) ; - for j3= 1:size(y,2) //accessing each element columnwise - index2 = y(index,j3)==1; - x1(i,j3) = temp(min(index,index2)); - end - end - elseif(strcmpi(method,'qam')) then - t= (0:1/fs:(len-1)/fs)'; - t=t(:,ones(1,size(y,2))); - x1= 2*.y*cos(2*%pi*fc*t); - x2= 2*.y*sin(2*%pi*fc*t); - [b,a]= butter(5,fc*2/fs); - for i=1:size(y,2) - x1(:,i)= filtfilt(b,a,x1(:,i)); - x2(:,i)= filtfilt(b,a,x2(:,i)); - end - - if(row==1) then - x2=x2'; //converting to column vector - end - end - - if(row==1) then - x1=x1'; - end - -endfunction From afcdbd54ffbdc6a4f93fe50c0bd678683d507021 Mon Sep 17 00:00:00 2001 From: Shrenik Nambiar Date: Tue, 25 Jul 2017 23:24:56 +0530 Subject: [PATCH 04/15] Delete sfdr.sci --- .../Signal Processing functions/sfdr.sci | 228 ------------------ 1 file changed, 228 deletions(-) delete mode 100644 Functions/Signal Processing functions/sfdr.sci diff --git a/Functions/Signal Processing functions/sfdr.sci b/Functions/Signal Processing functions/sfdr.sci deleted file mode 100644 index d7821a3..0000000 --- a/Functions/Signal Processing functions/sfdr.sci +++ /dev/null @@ -1,228 +0,0 @@ -function [varargout]= sfdr(varargin) - - if(argn(1)<0 | argn(1)>3) then - error("Output arguments should lie between 0 and 3"); - end - - if(argn(2)<1 | argn(2)>4) then - error("Input arguments should lie between 1 and 4"); - end - - if (~isvector(x) & (type(x) ~=8 | type(x) ~= 1)) then - error("x should be a vector of type doule or integer"); - end - - if (~isscalar(fs) & fs<0) then - error("fs must be positive scalar"); - end - - if (~isscalar(msd) & msd<0) then - error("msd must be positive scalar"); - end - - if(~isvector(sxx) & (type(sxx) ~=8 | type(sxx) ~= 1) & sxx<0) then - error("power estimate vector must be non-negative vector of type double or integer"); - end - - if(~isvector(f) & (type(f) ~=8 | type(f) ~= 1)) then - error(" f must be a vector of type double or integer"); - end - - if argn(1)==0 then - flag=1; - else - flag=0; - end - if(argn(2)<2) then - x=varargin(1); - fs=1; - msd=0; - [r, spurpow, spurfreq]= timesfdr(x,fs,msd); - elseif(argn(2)==2) then - x=varargin(1); - fs=varargin(2); - msd=0; - [r, spurpow, spurfreq]= timesfdr(x,fs,msd); - elseif(argn(2)==3 & type(varargin(3)~=10)) then - x=varargin(1); - fs=varargin(2); - msd=varargin(3); - [r, spurpow, spurfreq]= timesfdr(x,fs,msd); - elseif(argn(2) == 3 & strcmpi(varargin(3),'power')) then - sxx= varargin(1); - f= varargin(2); - msd=0; - [r, spurpow, spurfreq]= powersfdr(sxx,f,msd); - elseif(argn(2)== 4 & strcmpi(varargin(4),'power')) then - sxx= varargin(1) ; - f= varargin(2); - msd= varargin(3); - [r, totdistpow]= powersfdr(sxx,f,msd); - else - error("The valid flag is power"); - end - -endfunction - -function [r,totdistpow] = timesfdr(flag,x,fs,msd) - - if max(size(x))==length(x) then - x=x(:); - end - n= length(x); - x=x-mean(x); - w= window('kr',n,38); - rbw= enbw(w,fs); - [pxx, f] = periodogram(x,w,n,fs); - - signalCopy=pxx; - pxx(1)= 2*pxx(2); - [pfreq,rfreq,ifreq,left,right] = dcremove(pxx,f,rbw,0); - pxx(left:right)= 0; - dcindex = [left;right]; - - [pfreq,rfreq,ifreq,left,right] = dcremove(pxx,f,rbw); - pxx(left:right)= 0; - freqindex = [left;right]; - - pxx(abs(f-ffreq) sxx(freqbin:$-1),1,'first')-1; - if isempty(leftbin) - leftbin = 1; - end - - if isempty(rightbin) - rightbin = length(sxx); - end - - leftbinex = find(F <= fundfreq - msd, 1, 'last'); - rightbinex = find(fundfreq + msd < f, 1, 'first'); - if ~isempty(leftbinex) & leftbinex < leftbin - leftbin = leftbinex; - end - if ~isempty(rightbinex) & rightbinex > rightbin - rightbin = rightbinex; - end - -endfunction - -function[r,spurpow, spurfreq] = powersfdr (flag,sxx,f,msd) - - if(f(1) ~=0) then - error("sxx must be one-sided"); - end - - sigSCopy = sxx; - - sxx(1) = 2*sxx(1); - lastindex = find(sxx(1:$-1) 0 & pxx(indexleft) <= pxx(indexleft+1) - indexleft = indexleft - 1; - end - - - while indexright <= length(pxx) & pxx(indexright-1) >= pxx(indexright) - indexright = indexright + 1; - end - - indexleft = indexleft+1; - indexright = indexright-1; - ffreq = f(indexleft:indexright); - sfreq = pxx(indexleft:indexright); - fr = (ffreq.*sfreq) ./ sum(sfreq); - - if (indexleft Date: Tue, 25 Jul 2017 23:25:07 +0530 Subject: [PATCH 05/15] Delete sinad.sci --- .../Signal Processing functions/sinad.sci | 192 ------------------ 1 file changed, 192 deletions(-) delete mode 100644 Functions/Signal Processing functions/sinad.sci diff --git a/Functions/Signal Processing functions/sinad.sci b/Functions/Signal Processing functions/sinad.sci deleted file mode 100644 index 21512fc..0000000 --- a/Functions/Signal Processing functions/sinad.sci +++ /dev/null @@ -1,192 +0,0 @@ -function [varargout]= sinad(varargin) - - if(argn(1)<0 | argn(1)>2) then - error("Output arguments should lie between 0 and 2"); - end - - if(argn(2)<1 | argn(2)>4) then - error("Input arguments should lie between 1 and 4"); - end - - if (~isvector(x) & (type(x) ~=8 | type(x) ~= 1)) then - error("x should be a vector of type doule or integer"); - end - - if (~isscalar(fs) & fs<0) then - error("fs must be positive scalar"); - end - - if(~isvector(pxx) & (type(pxx) ~=8 | type(pxx) ~= 1) & pxx<0) then - error("psd estimate vector must be non-negative vector of type double or integer"); - end - - if(~isvector(sxx) & (type(sxx) ~=8 | type(sxx) ~= 1) & sxx<0) then - error("power estimate vector must be non-negative vector of type double or integer"); - end - - if(~isvector(f) & (type(f) ~=8 | type(f) ~= 1)) then - error(" f must be a vector of type double or integer"); - end - - - if(~isscalar(rbw) & (type(rbw) ~=8 | type(rbw) ~= 1) & rbw<0) then - error("rbw must be positive scalar"); - end - - if(argn(1)==0) then - flag=1; - else - flag=0; - end - - - if(argn(2)<2) then - x=varargin(1); - fs=1; - [r, totdistpow]= sampsinad(x,fs); - elseif(argn(2)==2) then - x=varargin(1); - fs=varargin(2); - [r, totdistpow]= sampsinad(x,fs); - elseif(argn(2) == 3 & strcmpi(varargin(3),'psd')) then - pxx= varargin(1); - f= varargin(2); - [r, totdistpow]= psdsinad(pxx,f); - elseif(argn(2)== 4 & strcmpi(varargin(4),'power')) then - sxx= varargin(1) ; - f= varargin(2); - rbw= varargin(3); - [r, totdistpow]= powersinad(sxx,f,rbw); - else - error("The valid flags are psd and power"); - end -endfunction - -function [r,totdistpow] = sampsinad(flag,x,fs) - - if max(size(x))==length(x) then - x=x(:); - end - - x=x-mean(x); - n=length(x); - //w= window('kr',n,38); - //rbw= enbw(w,fs); - //[pxx, f] = periodogram(x,w,n,fs,'psd'); - - [r, totdistpow]= sinadcalc(flag,pxx,f,rbw); - -endfunction - -function [r,totdistpow]= powersinad(flag,sxx,f,rbw) - if(f(1) ~=0) then - error("pxx must be one-sided"); - end - df= mean(diff(f)); - [r, totdistpow]= sinadcalc(flag,sxx/rbw,f,rbw) -endfunction - -function [r,totdistpow]= psdsinad(flag,pxx,f,rbw) - if(f(1) ~=0) then - error("pxx must be one-sided"); - end - df= mean(diff(f)); - [r, totdistpow]= sinadcalc(flag,pxx,f,df); -endfunction - -function [r, noisepower] = sinadcalc(flag,pxx,f,rbw) - signalCopy= pxx; - pxx(1)= 2*pxx(1); - [pfreq,rfreq,ifreq,left,right] = dcremove(pxx,f,rbw,0); - pxx(left:right)= 0; - dcindex = [left;right]; - - [pfreq,rfreq,ifreq,left,right] = dcremove(pxx,f,rbw); - pxx(left:right)= 0; - freqindex = [left;right]; - - noiseden= median(pxx(pxx>0)) - pxx(pxx == 0)= noiseden; - - pxx= min([pxx signalCopy], [],2); - totalnoise= bandpower(pxx,f,'psd'); - - r= 10*log10(pfreq/totalnoise); - noisepower= 10*log10(totalnoise); - - if flag then - plotfunction(signalCopy,f,rbw,ifreq,dcindex,freqindex); - end - -endfunction - -function plotfunction(pxx,f,rbw,ifreq,dcindex,freqindex) - pxx=pxx*rbw; - - xd= f(freqindex(1):freqindex(2)); - yd=10*log10(pxx(freqindex(1):freqindex(2))); - plot(xd,yd,'r'); - - - xd=f; - yd=10*log10(pxx); - plot(xd,yd,'g'); - - - xd=f(dcindex(1):dcindex(2)); - yd=10*log10(pxx(dcindex(1):dcindex(2))); - plot(xd,yd,'b'); - - -endfunction - -function [power, fr, indextone, indexleft, indexright]= dcremove(pxx, f, rbw, tonefreq) - - if(f(1)<=tonefreq & tonefreq<=f($)) then - [s, indextone] = min(abs(f-tonefreq)); - iLeft = max(1,indextone-1); - iRight = min(indextone+1,length(pxx)); - [s, indexmax] = max(pxx(iLeft:iRight)); - indextone = iLeft+indexmax-1; - else - power = NaN; - fr = NaN; - indextone = []; - indexleft = []; - indexright = []; - end - - indexleft = indextone - 1; - indexright = indextone + 1; - while indexleft > 0 & pxx(indexleft) <= pxx(indexleft+1) - indexleft = indexleft - 1; - end - - - while indexright <= length(pxx) & pxx(indexright-1) >= pxx(indexright) - indexright = indexright + 1; - end - - indexleft = indexleft+1; - indexright = indexright-1; - ffreq = f(indexleft:indexright); - sfreq = pxx(indexleft:indexright); - fr = (ffreq.*sfreq) ./ sum(sfreq); - - if (indexleft Date: Tue, 25 Jul 2017 23:25:17 +0530 Subject: [PATCH 06/15] Delete stepz.sci --- .../Signal Processing functions/stepz.sci | 108 ------------------ 1 file changed, 108 deletions(-) delete mode 100644 Functions/Signal Processing functions/stepz.sci diff --git a/Functions/Signal Processing functions/stepz.sci b/Functions/Signal Processing functions/stepz.sci deleted file mode 100644 index 5f4c4c6..0000000 --- a/Functions/Signal Processing functions/stepz.sci +++ /dev/null @@ -1,108 +0,0 @@ -function [h,t] = stepz(b,varargin) - if(argn(2)<1 | argn(2)>4) then - error("Input arguments should lie between 1 and 4"); - end - - if(argn(1) ~=2) then - error("Outpu argument should be 2"); - end - flag= true; - if(size(b)> [1 1]) then - - if(size(b,2) ~= 6) then - error(" SOS must be k by 6 matrix"); - end - flag = false; - if argn(2)>1 then - n= varargin(1); - else - n=[]; - end - - if argn(2)>2 then - fs = varargin(2); - else - fs=1; - end - - if( type(n) ~=8) then - error("n must be of type double"); - end - - if(type(fs) ~= 8) then - error("fs must be of type double"); - end - - if (type(b) ~=8) then - error(" "); - end - end - - - - if flag then - if(argn(2)>1) - a= varargin(1); - if (size(a)> [1 1]) then - error(" a has wrong input size"); - end - else - a=1; - end - - if(argn(2)>2) then - n= varargin(2); - else - n=[]; - end - - if(argn(2)>3) then - fs= varargin(3); - else - fs=1; - end - - if(type(n) ~=8) then - error(" n must be of type double"); - end - - if(type(fs) ~=8) then - error(" fs must be of type double"); - end - - if( type(b) ~=8 & type(a)~= 8) then - error("b and a should be of type double"); - end - - end - - t=0; - N=[]; - - if (argn(2)<2) then - if flag - n =impzlength(b,a); - else - n= impzlength(b); - end - elseif(length(n)>1) - N= round(n); - n =max(N)+1; - M= min(min(N),0); - end - - t1 = (t:(n-1))'/fs; - - x = ones(size(t1)); - if flag - s= filter(b,a,x); - else - s= sfilter(b,x); - end - - if ~isempty(N) then - s= s(N-m+1); - t1= t1(N-m+1); - end - -endfunction From a46b596bcbdf23826bb0cc69f10ec8de067aae47 Mon Sep 17 00:00:00 2001 From: Shrenik Nambiar Date: Tue, 25 Jul 2017 23:25:27 +0530 Subject: [PATCH 07/15] Delete tf2latc.sci --- .../Signal Processing functions/tf2latc.sci | 133 ------------------ 1 file changed, 133 deletions(-) delete mode 100644 Functions/Signal Processing functions/tf2latc.sci diff --git a/Functions/Signal Processing functions/tf2latc.sci b/Functions/Signal Processing functions/tf2latc.sci deleted file mode 100644 index 3a4689e..0000000 --- a/Functions/Signal Processing functions/tf2latc.sci +++ /dev/null @@ -1,133 +0,0 @@ -function [k,v]= tf2latc(varargin) - -// To convert transfer function filter parameters to lattice filter form -// Calling sequences -// -// -//[k,v]= tf2latc(b,a) : GIves both the lattice and ladder parameters on providing the numerator and -// denominator transfer function coefficients -// -//k= tf2latc(1,a) : Outputs the lattice parameters for an all pole lattice filter -// -//[k,v]= tf2latc(1,a) : Outputs both the lattice and ladder parameters for an all pole lattice filter -// -//k= tf2latc(b) : Gives the lattice parameters for an FIR lattice filter -// -//k= tf2latc(b,'phase') : 'phase' denotes the type of FIR filter, which can be 'max'(maximum phase filter) and 'min' (minimum phase filter) - -//Input parameters: -// b: Numerator coefficients of the transfer function -// a: Denominator coefficients of the transfer function -// -//Output Parametrs: -// k: lattice parameters -// v: ladder parmeters -// -//Example: -// -// Convert an IIR filters to its corresponding lattice parameters -// a=[1 1/5 3/5]; -// k=tf2latc(1,a); -// -//Author: Shrenik Nambiar -// -//References: John G.Proakis, Dimitris G.Manolakis, Digital Signal Processing, Pearson Publishers,//Fourth Edition -// M.H Hayes, Statistical Digital Signal Processing and Modelling,John Wiley and Sons,1996 -// -//Input validation statements - - - if(argn(2)<1) then - error("Atleast one input argument required"); - end - - b= varargin(1); - a = []; - phase=''; - - if (max(abs(b)) == 0) then - error("Numerator coefficients should not be zero"); - end - -//b= b./b(1); //normalizing -//a= a/a(1); - - b=b(:); //converting into column vectors - a=a(:); - -//According to the input given by the user,the below piece of code will direct the flow exectution to the appropriate function. - - if(argn(1)==2 & length(varargin)==2) then - if(varargin(1)==1) then - a= varargin(2); - [k v]= allpole2latc(b,a); - else - b= varargin(1); - a= varargin(2); - [k v]= iir2latc(b,a); - end - elseif(argn(1)==1 & length(varargin)==2) then - if(type(varargin(2))==10) then - b= varargin(1); - phase= varargin(2); - select phase - case "max" then - [k v]= fir2latc(b,a); - case "min" then - [k v]= fir2latc(b,a); - else - error("Invalid option, input should either be max or min"); - end - else - a= varargin(2); - b= varargin(1); - [k v]= allpole2latc(b,a); - end - elseif(argn(1)==1 & length(varargin)==1) then - b= varargin(1); - [k v]= fir2latc(b,a); - else - error("Too many input arguments"); - end - - -endfunction - -function [k,v]= allpole2latc(b,a) - - k= poly2rc(a); - v= [b;zeros(length(k))]; - -endfunction - - -function [k,v]= iir2latc(b,a) - - [b,a] = eqtflength(b,a); //to make the size of numerator and denominator equal - len= length(a); - k= poly2rc(a); - - [p,temp] = rlevinson(a,1); - v= zeros(len,1); - - for i = len:-1:1, - term= temp*v; - v(i)= b(i)-term(i); - end - v=flipdim(v,1); -endfunction - -function [k,v]= fir2latc(b,a) - - v = []; - if(argn(2)==1) then - v=b; - k=zeros(length(v)-1,1); - elseif(argn(2)==2) then - if(strcmpi(phase,'max')) then - b= conj(b($:-1:1)); //conjugating the polynomial to make it minimum phase filter - end - k= poly2rc(a); - end - -endfunction From 18c2a65d7e39539a4607fc4945d18fc5faafd242 Mon Sep 17 00:00:00 2001 From: Shrenik Nambiar Date: Tue, 25 Jul 2017 23:25:40 +0530 Subject: [PATCH 08/15] Delete toi.sci --- Functions/Signal Processing functions/toi.sci | 176 ------------------ 1 file changed, 176 deletions(-) delete mode 100644 Functions/Signal Processing functions/toi.sci diff --git a/Functions/Signal Processing functions/toi.sci b/Functions/Signal Processing functions/toi.sci deleted file mode 100644 index 97379ec..0000000 --- a/Functions/Signal Processing functions/toi.sci +++ /dev/null @@ -1,176 +0,0 @@ -function[oip3, fundpow, fundfreq, imodpow, imodfreq]= toi(varargin) - - if(argn(1)<0 | argn(1)>5) then - error("Output arguments should lie between 0 and 5"); - end - - if(argn(2)<1 | argn(2)>4) then - error("Input arguments should lie between 1 and 4"); - end - - if (~isvector(x) & (type(x) ~=8 | type(x) ~= 1)) then - error("x should be a vector of type doule or integer"); - end - - if (~isscalar(fs) & fs<0) then - error("fs must be positive scalar"); - end - - if(~isvector(pxx) & (type(pxx) ~=8 | type(pxx) ~= 1) & pxx<0) then - error("psd estimate vector must be non-negative vector of type double or integer"); - end - - - if(~isvector(sxx) & (type(sxx) ~=8 | type(sxx) ~= 1) & sxx<0) then - error("power estimate vector must be non-negative vector of type double or integer"); - end - - if(~isvector(f) & (type(f) ~=8 | type(f) ~= 1)) then - error(" f must be a vector of type double or integer"); - end - - - if(~isscalar(rbw) & (type(rbw) ~=8 | type(rbw) ~= 1) & rbw<0) then - error("rbw must be positive scalar"); - end - - if(argn(1)==0) then - flag=1; - else - flag=0; - end - - if(argn(2)<2) then - x=varargin(1); - fs=1; - [oip3, fundpow, fundfreq, imodpow, imodfreq]= timetoi(flag,x,fs); - elseif(argn(2)==2) then - x=varargin(1); - fs=varargin(2); - [oip3, fundpow, fundfreq, imodpow, imodfreq]= timetoi(flag,x,fs); - elseif(argn(2) == 3 & strcmpi(varargin(3),'psd')) then - pxx= varargin(1); - f= varargin(2); - [oip3, fundpow, fundfreq, imodpow, imodfreq]= psdtoi(flag,pxx,f); - elseif(argn(2)== 4 & strcmpi(varargin(4),'power')) then - sxx= varargin(1) ; - f= varargin(2); - rbw= varargin(3); - [oip3, fundpow, fundfreq, imodpow, imodfreq]= powertoi(flag,sxx,f,rbw); - else - error("The valid flags are psd and power"); - end - -endfunction - -function [oip3, fundpow, fundfreq, imodpow, imodfreq] = timetoi(flag,x,fs) - - if max(size(x))==length(x) then - x=x(:); - end - - x=x-mean(x); - n=length(x); - w= window('kr',n,38); - rbw= enbw(w,fs); - [pxx, f] = periodogram(x,w,n,fs,'psd'); - - [oip3, fundpow, fundfreq, imodpow, imodfreq]= toicalc(flag,pxx,f,rbw); - -endfunction - -function [oip3, fundpow, fundfreq, imodpow, imodfreq]= powertoi(flag,sxx,f,rbw) - if(f(1) ~=0) then - error("pxx must be one-sided"); - end - df= mean(diff(f)); - - if(rbw 0 & pxx(indexleft) <= pxx(indexleft+1) - indexleft = indexleft - 1; - end - - - while indexright <= length(pxx) & pxx(indexright-1) >= pxx(indexright) - indexright = indexright + 1; - end - - indexleft = indexleft+1; - indexright = indexright-1; - ffreq = f(indexleft:indexright); - sfreq = pxx(indexleft:indexright); - fr = (ffreq.*sfreq) ./ sum(sfreq); - - if (indexleft Date: Tue, 25 Jul 2017 23:28:03 +0530 Subject: [PATCH 09/15] Add files via upload --- Signal Processing functions/bandpower.sci | 203 +++++++++++++++++++ Signal Processing functions/demod.sci | 202 +++++++++++++++++++ Signal Processing functions/sfdr.sci | 228 ++++++++++++++++++++++ Signal Processing functions/sinad.sci | 192 ++++++++++++++++++ Signal Processing functions/stepz.sci | 108 ++++++++++ Signal Processing functions/tf2latc.sci | 133 +++++++++++++ Signal Processing functions/toi.sci | 176 +++++++++++++++++ 7 files changed, 1242 insertions(+) create mode 100644 Signal Processing functions/bandpower.sci create mode 100644 Signal Processing functions/demod.sci create mode 100644 Signal Processing functions/sfdr.sci create mode 100644 Signal Processing functions/sinad.sci create mode 100644 Signal Processing functions/stepz.sci create mode 100644 Signal Processing functions/tf2latc.sci create mode 100644 Signal Processing functions/toi.sci diff --git a/Signal Processing functions/bandpower.sci b/Signal Processing functions/bandpower.sci new file mode 100644 index 0000000..be61250 --- /dev/null +++ b/Signal Processing functions/bandpower.sci @@ -0,0 +1,203 @@ +function power= bandpower(varargin) +// To find the bandpower of an input signal +// Calling sequences +// +//power= bandpower(x) : It returns the average power of the input matrix,x +// +//power= bandpower(x,fs,freqrange) : Returns the average power in the frequency range whose length must be 2. This function uses periodogram to determine the average power. +// +//power= bandpower(pxx,f,'psd') : In this case the average power is computed by integrating the power spectral density estimate,pxx. The input f is a vector of frequencies corresponding to pxx. 'psd' indicates its not time series data. +// +//power= bandpower(pxx,f,freqrange,'psd') : Similar to the above type except the average power is computed within the frequency range specified. +// +//Input parameters: +// x: Time series input of type double or scalar +// fs: Sampling frequency and must be positive scalar +// freqrange: The frequency range within which the average power is to be computed +// pxx: Power spectral density estimates. Must be nonnegatuve of type double or inte//ger +// f: Frequency vector for psd estimates. Must be of type double or integer +// +//Output Parameters: +// +// power: Average band power of type double or integer. +// +//Example: Create a signal consisting of a 100 Hz sine wave in additive N(0,1) white Gaussian noise. +// t = 0:0.001:1-0.001; +// x = cos(2*pi*100*t)+randn(size(t)); +// p = bandpower(x) +//Author: Shrenik Nambiar +// +//Input validation statements +// +// + if(argn(1) ~= 1) then + error(" Only one output argument allowed"); + end + if(argn(2)<1 | argn(2)>4 | argn(2)== 2) then + error("The no. of input arguments should be 1,3 or 4"); + end + + flag= find(strcmpi(varargin(:),'psd')); + varargin(flag)= []; + + if (flag) then + power= bandpowerfrompsd(varargin(1),varargin(2),varargin(3)); + else + power= bandpowerfromsignal(varargin(1),varargin(2),varargin(3)); + end + +endfunction + +function power = bandpowerfromsignal(x,fs,freqrange) + +// To convert the vector into column vector + if isvector(x) then + x=x(:); + end + +// THe input vector should either be a 1D vector or a 2D matrix + if (ndims(x)~= 1 | ndims(x)~= 2) then + error(" x should either be a vector or 2 matrix"); + end + +//Checking for argument type + if(type(x)~= 1 | type(x)~= 8) then + error(" Argument should be of type int or double"); + end + +//Performing Typecasting + x=double(x); + +// When the function has only 1 input parameter + if(argn(2)== 1) then + x2=x.^2; + power= sum(x2,'r'); + end + +// fs must be positive scalar + if length(fs)~= 1 then + error("fs must not be a vector"); + end + + if(type(fs)~= 1 | type(fs)~= 8) then + error(" Argument should be of type int or double"); + end + fs= double(fs); + +// Checking the freqrange parameter + if ~isempty(freqrange) then + if length(freqrange)~=2 then + error("freqrange must be a vector of 2 elements"); + end + if(type(freqrange)~= 1 | type(freqrange)~= 8) then + error(" Argument should be of type int or double"); + end + if freqrange(1)>=freqrange(2) then + error("1st element should be smaller than the second element"); + end + +//Performing Typecasting + freqrange = double(freqrange(:)); + end + + n = size(x,1); + + if isreal(x) then + [pxx, f] = periodogram(x, hamming(n), n, fs); + else + [pxx, f] = periodogram(x, hamming(n), n, fs, 'centered'); + end + power = bandpowerfrompsd(pxx, f, freqrange); + +endfunction + +function power= bandpowerfrompsd(pxx,f,freqrange) + +//Making it column vector + if isvector(pxx) then + pxx=pxx(:); + end + + if ndims(pxx)<1 | ndims(pxx)>2 then + error("Wrong dimesnion for argument #1 (pxx); must be vector or a 2D matrix"); + end + + if(type(pxx)~= 1 | type(pxx)~= 8) then + error(" Argument should be of type int or double"); + end + +// All the elements of pxx must b non-negative + for i=1:length(pxx) + if(pxx(i)<0) then + error("pxx must be non negative") + end + end + +//Performing Typecasting + pxx = double(pxx); + +//Checking the f parameter + if ~isvector(f) | size(pxx,1)~=length(f) then + error(" f should be a vector of same size as pxx"); + end + if(type(f)~= 1 | type(f)~= 8) then + error("Argument should be of type int or double"); + end + + if (diff(f)<=0) then + error("f must be strictly increasing"); + end + f = double(f(:)); + +//Checking for freqrange parameter + if ~isempty(freqrange) then + + if length(freqrange)~=2 then + error("freqrange must be a vector of 2 elements"); + end + if(type(freqrange)~= 1 | type(freqrange)~= 8) then + error("Argument should be of type int or double"); + end + + if freqrange(1)>=freqrange(2) then + error("1st element should be smaller than the second element"); + end + + if freqrange(1)f($) then + error("freqrange should lie between f"); + end + freqrangeflag=true; + freqrange = double(freqrange(:)); + else + + freqrange= [f(1) f($)]; + freqrangeflag= false; + + end + + f = f(:); + index1= find(f<=freqrange(1),1); + index2= find(f>=freqrange(2),1); + +//As we are approximating the integral using the rectangle method, we must find the width of the rectangle + + binwidth= diff(f); + +//For n is even,the nyquist point is fs/2, hence the emissing range is at the beginning of the vector + if freqrangeflag then + lastbinwidth=0; + binwidth= [binwidth; lastbinwidth]; + else + +//if the no. of points is odd, then the missing frequencies is present at both ends,but as the signal spectrum is symmetric the missing frequency can be assumedto be at the bginning of the vector + missingbinwidth = (f($) - f(1)) / (length(f) - 1); + centre = (f(1)==0); + if ~centre then + binwidths = [missingbinwidth; binwidths]; + else + binwidths = [binwidths; missingbinwidth]; + end + end + power = binwidths(index1:index2)'*pxx(index1:index2,:); + +endfunction diff --git a/Signal Processing functions/demod.sci b/Signal Processing functions/demod.sci new file mode 100644 index 0000000..1ac7a75 --- /dev/null +++ b/Signal Processing functions/demod.sci @@ -0,0 +1,202 @@ +function [x1,varargout]= demod (y,fc,fs,method,varargin) +//Demodulation for communication systems +//Calling Sequences +// +//x = demod(y,fc,fs,'method') +//x = demod(y,fc,fs,'method',opt) +//x = demod(y,fc,fs,'pwm',centered) +// +//Input parameters: +// y: Real carrier signal +// fc: Carrier frequency +// fs: Sampling frequency +// method: There are 9 methods for demodulating a modulated signal and a few of them//also accepts an extra parameter , opt + +// amdsb-sc or am: +// Amplitude demodulation (am), double sideband (sdb), suppressed carrier(sc) : Multiplies y by a sinusoid of frequency fc and applies a fifth-order Butterworth lowpass filter using filtfilt. +// +// amdsb-tc: +// Amplitude demodulation, double sideband, transmitted carrier (tc). Multiplies y by a sinusoid of frequency fc and applies a fifth-order Butterworth lowpass filter using filtfilt. +// If opt is specified, demod subtracts scalar opt from x. The default value for opt is 0. + +// amssb: +// Amplitude demodulation, single sideband. Multiplies y by a sinusoid of frequency fc and applies a fifth-order Butterworth lowpass filter using filtfilt. +// +// fm: +// Frequency demodulation. Demodulates the FM waveform by modulating the Hilbert transform of y by a complex exponential of frequency -fc Hz and obtains the instantaneous frequency of the result. +// +// pm: +// Phase demodulation. Demodulates the PM waveform by modulating the Hilbert transform of y by a complex exponential of frequency -fc Hz and obtains the instantaneous phase of the result. +// +// ppm: +// Pulse-position demodulation. Finds the pulse positions of a pulse-position modulated signal y. For correct demodulation, the pulses cannot overlap. x is length length(t)*fc/fs. +// +// pwm: +// Pulse-width demodulation. Finds the pulse widths of a pulse-width modulated signal y. demod returns x a vector whose elements specify the width of each pulse in fractions of a period. The pulses in y should start at the beginning of each carrier period, that is, they should be left justified. +// +// qam: +// Quadrature amplitude demodulation. +// +// [x1,x2] = demod(y,fc,fs,'qam') multiplies y by a cosine and a sine of frequency fc and applies a fifth-order Butterworth lowpass filter using filtfilt. +// +// The default method is am. +// +//Output parameters: +// x1: Demodulated signal. In all cases except ppm and pwm,x is the same size as y +// +// +//Author: Shrenik Nambiar +// +//References: B.P. Lathi, Modern digital and analog communication systems, Oxford University Press, 1998. +// Rappaport, Theodore S. Wireless Communications: Principles and Practice. Upper Saddle River, NJ: Prentice Hall, 1996 +// +//Input validation statements + + [out,in] = argn(0); + + if(in ~=3 | in ~=4 | in~= 5) then + error(" Number of Input parameters should either be 4 or 5"); + end + + if(out ~= 1 | out~= 2) then + error("Number of output parameters should either be 1 or 2"); + end + +//Checking whether the user entered arguments are of numeric type + + if(isnumeric(fc) & isnumeric(fs) & isnumeric(y)) then + fc= float(fc); + fs= float(fs); + y= float(y); + else + error(" All three parameters should be of numeric type"); + end + +//To check if it satisfies Nyquist Theorem + if(~(fs > 2*fc)) then + error("Not obeying the Nyquist theorem"); + end + + + method= ''; + + if(in == 3) then + method= 'am'; + end + + [row,col] = size(y); + if row==0 | col==0 then + x1=[]; + end + +// Column vector conversion + if(row==1) then + y=y(:); + l=col; + else + l=row; + end + +//For each type of demoulation technique enterd by the user, one of the if elseif block will be executed + if(strcmpi(method,'am') | strcmpi(method,'amdsb-sc')) | strcmpi(method,'amdsb-tc') | strcmpi(method,'amssb') then + + t= (0:1/fs:(l-1)/fs)'; + t=t(:,ones(1,size(y,2))); + x1= y.*cos(2*%pi*fc*t); + [b,a]= butter(5,fc*2/fs); + + for i=1:size(y,2) + x1(:,i) = filtfilt(b,a,x1(:,i)); + end + + if strcmpi(method,'amdsb-tc') then + if(in<5) then + options=0; + end + options=float(options); + + x1=x1-options; + end + + elseif(strcmpi(method,'fm')) then + if(in<5) then + options=1; + end + + options=float(options); + t= (0:1/fs:(l-1)/fs)'; + t=t(:,ones(1,size(y,2))); + yh= hilbert(y).*exp(-%i*2*%pi*fc*t); + x1= (1/options)*[zeros(1,size(yh,2));diff(unwrap(angle(yh)))]; + elseif(strcmpi(method,'pm')) then + if(in<5) then + options=1; + end + + options=float(options); + t= (0:1/fs:(l-1)/fs)'; + t=t(:,ones(1,size(y,2))); + yh= hilbert(y).*exp(-%i*2*%pi*fc*t); + x1= (1/options)*angle(yh); + elseif(strcmpi(method,'pwm') & type(varargin(1))== 10) then + y=y>0.5; //for thresholding purposes + t= (0:1/fs:(l-1)/fs)'; + l= ceil(l*fc/fs); //length of the signal + x1= zeros(l,size(y,2)); //initializing the vector + if(in<5) then + options = 'left'; + end + if(strcmpi(options,'centred')) then + for i = 1:l, + temp= t-(i-1)/fc; + index= (temp >= -0.5/fc) & (temp<=0.5*fc); + for j1= 1:size(y,2) + x1(i,j1) = sum(y(index,j1))*fc/fs; + end + end + x1(1,:) = x1(1,:)*2; + elseif(strcmpi(options,'left')) then + for i=1:l, + temp = t-(i-1)/fc; + index= (temp>=0) & (temp <1/fc) ; + for j2= 1:size(y,2) + x1(i,j2) = sum(y(index,j2))*fc/fs; + end + end + else + error("Invalid option"); + end + elseif(strcmpi(method,'ppm')) then + y=y>0.5; + t= (0:1/fs:(l-1)/fs)'; + l= ceil(l*fc/fs); //length of the message signal + x1= zeros(l,size(y,2)); + for i=1:l, + temp = t-(i-1); + index= find(temp>=0) & (temp <1) ; + for j3= 1:size(y,2) //accessing each element columnwise + index2 = y(index,j3)==1; + x1(i,j3) = temp(min(index,index2)); + end + end + elseif(strcmpi(method,'qam')) then + t= (0:1/fs:(len-1)/fs)'; + t=t(:,ones(1,size(y,2))); + x1= 2*.y*cos(2*%pi*fc*t); + x2= 2*.y*sin(2*%pi*fc*t); + [b,a]= butter(5,fc*2/fs); + for i=1:size(y,2) + x1(:,i)= filtfilt(b,a,x1(:,i)); + x2(:,i)= filtfilt(b,a,x2(:,i)); + end + + if(row==1) then + x2=x2'; //converting to column vector + end + end + + if(row==1) then + x1=x1'; + end + +endfunction diff --git a/Signal Processing functions/sfdr.sci b/Signal Processing functions/sfdr.sci new file mode 100644 index 0000000..d7821a3 --- /dev/null +++ b/Signal Processing functions/sfdr.sci @@ -0,0 +1,228 @@ +function [varargout]= sfdr(varargin) + + if(argn(1)<0 | argn(1)>3) then + error("Output arguments should lie between 0 and 3"); + end + + if(argn(2)<1 | argn(2)>4) then + error("Input arguments should lie between 1 and 4"); + end + + if (~isvector(x) & (type(x) ~=8 | type(x) ~= 1)) then + error("x should be a vector of type doule or integer"); + end + + if (~isscalar(fs) & fs<0) then + error("fs must be positive scalar"); + end + + if (~isscalar(msd) & msd<0) then + error("msd must be positive scalar"); + end + + if(~isvector(sxx) & (type(sxx) ~=8 | type(sxx) ~= 1) & sxx<0) then + error("power estimate vector must be non-negative vector of type double or integer"); + end + + if(~isvector(f) & (type(f) ~=8 | type(f) ~= 1)) then + error(" f must be a vector of type double or integer"); + end + + if argn(1)==0 then + flag=1; + else + flag=0; + end + if(argn(2)<2) then + x=varargin(1); + fs=1; + msd=0; + [r, spurpow, spurfreq]= timesfdr(x,fs,msd); + elseif(argn(2)==2) then + x=varargin(1); + fs=varargin(2); + msd=0; + [r, spurpow, spurfreq]= timesfdr(x,fs,msd); + elseif(argn(2)==3 & type(varargin(3)~=10)) then + x=varargin(1); + fs=varargin(2); + msd=varargin(3); + [r, spurpow, spurfreq]= timesfdr(x,fs,msd); + elseif(argn(2) == 3 & strcmpi(varargin(3),'power')) then + sxx= varargin(1); + f= varargin(2); + msd=0; + [r, spurpow, spurfreq]= powersfdr(sxx,f,msd); + elseif(argn(2)== 4 & strcmpi(varargin(4),'power')) then + sxx= varargin(1) ; + f= varargin(2); + msd= varargin(3); + [r, totdistpow]= powersfdr(sxx,f,msd); + else + error("The valid flag is power"); + end + +endfunction + +function [r,totdistpow] = timesfdr(flag,x,fs,msd) + + if max(size(x))==length(x) then + x=x(:); + end + n= length(x); + x=x-mean(x); + w= window('kr',n,38); + rbw= enbw(w,fs); + [pxx, f] = periodogram(x,w,n,fs); + + signalCopy=pxx; + pxx(1)= 2*pxx(2); + [pfreq,rfreq,ifreq,left,right] = dcremove(pxx,f,rbw,0); + pxx(left:right)= 0; + dcindex = [left;right]; + + [pfreq,rfreq,ifreq,left,right] = dcremove(pxx,f,rbw); + pxx(left:right)= 0; + freqindex = [left;right]; + + pxx(abs(f-ffreq) sxx(freqbin:$-1),1,'first')-1; + if isempty(leftbin) + leftbin = 1; + end + + if isempty(rightbin) + rightbin = length(sxx); + end + + leftbinex = find(F <= fundfreq - msd, 1, 'last'); + rightbinex = find(fundfreq + msd < f, 1, 'first'); + if ~isempty(leftbinex) & leftbinex < leftbin + leftbin = leftbinex; + end + if ~isempty(rightbinex) & rightbinex > rightbin + rightbin = rightbinex; + end + +endfunction + +function[r,spurpow, spurfreq] = powersfdr (flag,sxx,f,msd) + + if(f(1) ~=0) then + error("sxx must be one-sided"); + end + + sigSCopy = sxx; + + sxx(1) = 2*sxx(1); + lastindex = find(sxx(1:$-1) 0 & pxx(indexleft) <= pxx(indexleft+1) + indexleft = indexleft - 1; + end + + + while indexright <= length(pxx) & pxx(indexright-1) >= pxx(indexright) + indexright = indexright + 1; + end + + indexleft = indexleft+1; + indexright = indexright-1; + ffreq = f(indexleft:indexright); + sfreq = pxx(indexleft:indexright); + fr = (ffreq.*sfreq) ./ sum(sfreq); + + if (indexleft2) then + error("Output arguments should lie between 0 and 2"); + end + + if(argn(2)<1 | argn(2)>4) then + error("Input arguments should lie between 1 and 4"); + end + + if (~isvector(x) & (type(x) ~=8 | type(x) ~= 1)) then + error("x should be a vector of type doule or integer"); + end + + if (~isscalar(fs) & fs<0) then + error("fs must be positive scalar"); + end + + if(~isvector(pxx) & (type(pxx) ~=8 | type(pxx) ~= 1) & pxx<0) then + error("psd estimate vector must be non-negative vector of type double or integer"); + end + + if(~isvector(sxx) & (type(sxx) ~=8 | type(sxx) ~= 1) & sxx<0) then + error("power estimate vector must be non-negative vector of type double or integer"); + end + + if(~isvector(f) & (type(f) ~=8 | type(f) ~= 1)) then + error(" f must be a vector of type double or integer"); + end + + + if(~isscalar(rbw) & (type(rbw) ~=8 | type(rbw) ~= 1) & rbw<0) then + error("rbw must be positive scalar"); + end + + if(argn(1)==0) then + flag=1; + else + flag=0; + end + + + if(argn(2)<2) then + x=varargin(1); + fs=1; + [r, totdistpow]= sampsinad(x,fs); + elseif(argn(2)==2) then + x=varargin(1); + fs=varargin(2); + [r, totdistpow]= sampsinad(x,fs); + elseif(argn(2) == 3 & strcmpi(varargin(3),'psd')) then + pxx= varargin(1); + f= varargin(2); + [r, totdistpow]= psdsinad(pxx,f); + elseif(argn(2)== 4 & strcmpi(varargin(4),'power')) then + sxx= varargin(1) ; + f= varargin(2); + rbw= varargin(3); + [r, totdistpow]= powersinad(sxx,f,rbw); + else + error("The valid flags are psd and power"); + end +endfunction + +function [r,totdistpow] = sampsinad(flag,x,fs) + + if max(size(x))==length(x) then + x=x(:); + end + + x=x-mean(x); + n=length(x); + //w= window('kr',n,38); + //rbw= enbw(w,fs); + //[pxx, f] = periodogram(x,w,n,fs,'psd'); + + [r, totdistpow]= sinadcalc(flag,pxx,f,rbw); + +endfunction + +function [r,totdistpow]= powersinad(flag,sxx,f,rbw) + if(f(1) ~=0) then + error("pxx must be one-sided"); + end + df= mean(diff(f)); + [r, totdistpow]= sinadcalc(flag,sxx/rbw,f,rbw) +endfunction + +function [r,totdistpow]= psdsinad(flag,pxx,f,rbw) + if(f(1) ~=0) then + error("pxx must be one-sided"); + end + df= mean(diff(f)); + [r, totdistpow]= sinadcalc(flag,pxx,f,df); +endfunction + +function [r, noisepower] = sinadcalc(flag,pxx,f,rbw) + signalCopy= pxx; + pxx(1)= 2*pxx(1); + [pfreq,rfreq,ifreq,left,right] = dcremove(pxx,f,rbw,0); + pxx(left:right)= 0; + dcindex = [left;right]; + + [pfreq,rfreq,ifreq,left,right] = dcremove(pxx,f,rbw); + pxx(left:right)= 0; + freqindex = [left;right]; + + noiseden= median(pxx(pxx>0)) + pxx(pxx == 0)= noiseden; + + pxx= min([pxx signalCopy], [],2); + totalnoise= bandpower(pxx,f,'psd'); + + r= 10*log10(pfreq/totalnoise); + noisepower= 10*log10(totalnoise); + + if flag then + plotfunction(signalCopy,f,rbw,ifreq,dcindex,freqindex); + end + +endfunction + +function plotfunction(pxx,f,rbw,ifreq,dcindex,freqindex) + pxx=pxx*rbw; + + xd= f(freqindex(1):freqindex(2)); + yd=10*log10(pxx(freqindex(1):freqindex(2))); + plot(xd,yd,'r'); + + + xd=f; + yd=10*log10(pxx); + plot(xd,yd,'g'); + + + xd=f(dcindex(1):dcindex(2)); + yd=10*log10(pxx(dcindex(1):dcindex(2))); + plot(xd,yd,'b'); + + +endfunction + +function [power, fr, indextone, indexleft, indexright]= dcremove(pxx, f, rbw, tonefreq) + + if(f(1)<=tonefreq & tonefreq<=f($)) then + [s, indextone] = min(abs(f-tonefreq)); + iLeft = max(1,indextone-1); + iRight = min(indextone+1,length(pxx)); + [s, indexmax] = max(pxx(iLeft:iRight)); + indextone = iLeft+indexmax-1; + else + power = NaN; + fr = NaN; + indextone = []; + indexleft = []; + indexright = []; + end + + indexleft = indextone - 1; + indexright = indextone + 1; + while indexleft > 0 & pxx(indexleft) <= pxx(indexleft+1) + indexleft = indexleft - 1; + end + + + while indexright <= length(pxx) & pxx(indexright-1) >= pxx(indexright) + indexright = indexright + 1; + end + + indexleft = indexleft+1; + indexright = indexright-1; + ffreq = f(indexleft:indexright); + sfreq = pxx(indexleft:indexright); + fr = (ffreq.*sfreq) ./ sum(sfreq); + + if (indexleft4) then + error("Input arguments should lie between 1 and 4"); + end + + if(argn(1) ~=2) then + error("Outpu argument should be 2"); + end + flag= true; + if(size(b)> [1 1]) then + + if(size(b,2) ~= 6) then + error(" SOS must be k by 6 matrix"); + end + flag = false; + if argn(2)>1 then + n= varargin(1); + else + n=[]; + end + + if argn(2)>2 then + fs = varargin(2); + else + fs=1; + end + + if( type(n) ~=8) then + error("n must be of type double"); + end + + if(type(fs) ~= 8) then + error("fs must be of type double"); + end + + if (type(b) ~=8) then + error(" "); + end + end + + + + if flag then + if(argn(2)>1) + a= varargin(1); + if (size(a)> [1 1]) then + error(" a has wrong input size"); + end + else + a=1; + end + + if(argn(2)>2) then + n= varargin(2); + else + n=[]; + end + + if(argn(2)>3) then + fs= varargin(3); + else + fs=1; + end + + if(type(n) ~=8) then + error(" n must be of type double"); + end + + if(type(fs) ~=8) then + error(" fs must be of type double"); + end + + if( type(b) ~=8 & type(a)~= 8) then + error("b and a should be of type double"); + end + + end + + t=0; + N=[]; + + if (argn(2)<2) then + if flag + n =impzlength(b,a); + else + n= impzlength(b); + end + elseif(length(n)>1) + N= round(n); + n =max(N)+1; + M= min(min(N),0); + end + + t1 = (t:(n-1))'/fs; + + x = ones(size(t1)); + if flag + s= filter(b,a,x); + else + s= sfilter(b,x); + end + + if ~isempty(N) then + s= s(N-m+1); + t1= t1(N-m+1); + end + +endfunction diff --git a/Signal Processing functions/tf2latc.sci b/Signal Processing functions/tf2latc.sci new file mode 100644 index 0000000..3a4689e --- /dev/null +++ b/Signal Processing functions/tf2latc.sci @@ -0,0 +1,133 @@ +function [k,v]= tf2latc(varargin) + +// To convert transfer function filter parameters to lattice filter form +// Calling sequences +// +// +//[k,v]= tf2latc(b,a) : GIves both the lattice and ladder parameters on providing the numerator and +// denominator transfer function coefficients +// +//k= tf2latc(1,a) : Outputs the lattice parameters for an all pole lattice filter +// +//[k,v]= tf2latc(1,a) : Outputs both the lattice and ladder parameters for an all pole lattice filter +// +//k= tf2latc(b) : Gives the lattice parameters for an FIR lattice filter +// +//k= tf2latc(b,'phase') : 'phase' denotes the type of FIR filter, which can be 'max'(maximum phase filter) and 'min' (minimum phase filter) + +//Input parameters: +// b: Numerator coefficients of the transfer function +// a: Denominator coefficients of the transfer function +// +//Output Parametrs: +// k: lattice parameters +// v: ladder parmeters +// +//Example: +// +// Convert an IIR filters to its corresponding lattice parameters +// a=[1 1/5 3/5]; +// k=tf2latc(1,a); +// +//Author: Shrenik Nambiar +// +//References: John G.Proakis, Dimitris G.Manolakis, Digital Signal Processing, Pearson Publishers,//Fourth Edition +// M.H Hayes, Statistical Digital Signal Processing and Modelling,John Wiley and Sons,1996 +// +//Input validation statements + + + if(argn(2)<1) then + error("Atleast one input argument required"); + end + + b= varargin(1); + a = []; + phase=''; + + if (max(abs(b)) == 0) then + error("Numerator coefficients should not be zero"); + end + +//b= b./b(1); //normalizing +//a= a/a(1); + + b=b(:); //converting into column vectors + a=a(:); + +//According to the input given by the user,the below piece of code will direct the flow exectution to the appropriate function. + + if(argn(1)==2 & length(varargin)==2) then + if(varargin(1)==1) then + a= varargin(2); + [k v]= allpole2latc(b,a); + else + b= varargin(1); + a= varargin(2); + [k v]= iir2latc(b,a); + end + elseif(argn(1)==1 & length(varargin)==2) then + if(type(varargin(2))==10) then + b= varargin(1); + phase= varargin(2); + select phase + case "max" then + [k v]= fir2latc(b,a); + case "min" then + [k v]= fir2latc(b,a); + else + error("Invalid option, input should either be max or min"); + end + else + a= varargin(2); + b= varargin(1); + [k v]= allpole2latc(b,a); + end + elseif(argn(1)==1 & length(varargin)==1) then + b= varargin(1); + [k v]= fir2latc(b,a); + else + error("Too many input arguments"); + end + + +endfunction + +function [k,v]= allpole2latc(b,a) + + k= poly2rc(a); + v= [b;zeros(length(k))]; + +endfunction + + +function [k,v]= iir2latc(b,a) + + [b,a] = eqtflength(b,a); //to make the size of numerator and denominator equal + len= length(a); + k= poly2rc(a); + + [p,temp] = rlevinson(a,1); + v= zeros(len,1); + + for i = len:-1:1, + term= temp*v; + v(i)= b(i)-term(i); + end + v=flipdim(v,1); +endfunction + +function [k,v]= fir2latc(b,a) + + v = []; + if(argn(2)==1) then + v=b; + k=zeros(length(v)-1,1); + elseif(argn(2)==2) then + if(strcmpi(phase,'max')) then + b= conj(b($:-1:1)); //conjugating the polynomial to make it minimum phase filter + end + k= poly2rc(a); + end + +endfunction diff --git a/Signal Processing functions/toi.sci b/Signal Processing functions/toi.sci new file mode 100644 index 0000000..97379ec --- /dev/null +++ b/Signal Processing functions/toi.sci @@ -0,0 +1,176 @@ +function[oip3, fundpow, fundfreq, imodpow, imodfreq]= toi(varargin) + + if(argn(1)<0 | argn(1)>5) then + error("Output arguments should lie between 0 and 5"); + end + + if(argn(2)<1 | argn(2)>4) then + error("Input arguments should lie between 1 and 4"); + end + + if (~isvector(x) & (type(x) ~=8 | type(x) ~= 1)) then + error("x should be a vector of type doule or integer"); + end + + if (~isscalar(fs) & fs<0) then + error("fs must be positive scalar"); + end + + if(~isvector(pxx) & (type(pxx) ~=8 | type(pxx) ~= 1) & pxx<0) then + error("psd estimate vector must be non-negative vector of type double or integer"); + end + + + if(~isvector(sxx) & (type(sxx) ~=8 | type(sxx) ~= 1) & sxx<0) then + error("power estimate vector must be non-negative vector of type double or integer"); + end + + if(~isvector(f) & (type(f) ~=8 | type(f) ~= 1)) then + error(" f must be a vector of type double or integer"); + end + + + if(~isscalar(rbw) & (type(rbw) ~=8 | type(rbw) ~= 1) & rbw<0) then + error("rbw must be positive scalar"); + end + + if(argn(1)==0) then + flag=1; + else + flag=0; + end + + if(argn(2)<2) then + x=varargin(1); + fs=1; + [oip3, fundpow, fundfreq, imodpow, imodfreq]= timetoi(flag,x,fs); + elseif(argn(2)==2) then + x=varargin(1); + fs=varargin(2); + [oip3, fundpow, fundfreq, imodpow, imodfreq]= timetoi(flag,x,fs); + elseif(argn(2) == 3 & strcmpi(varargin(3),'psd')) then + pxx= varargin(1); + f= varargin(2); + [oip3, fundpow, fundfreq, imodpow, imodfreq]= psdtoi(flag,pxx,f); + elseif(argn(2)== 4 & strcmpi(varargin(4),'power')) then + sxx= varargin(1) ; + f= varargin(2); + rbw= varargin(3); + [oip3, fundpow, fundfreq, imodpow, imodfreq]= powertoi(flag,sxx,f,rbw); + else + error("The valid flags are psd and power"); + end + +endfunction + +function [oip3, fundpow, fundfreq, imodpow, imodfreq] = timetoi(flag,x,fs) + + if max(size(x))==length(x) then + x=x(:); + end + + x=x-mean(x); + n=length(x); + w= window('kr',n,38); + rbw= enbw(w,fs); + [pxx, f] = periodogram(x,w,n,fs,'psd'); + + [oip3, fundpow, fundfreq, imodpow, imodfreq]= toicalc(flag,pxx,f,rbw); + +endfunction + +function [oip3, fundpow, fundfreq, imodpow, imodfreq]= powertoi(flag,sxx,f,rbw) + if(f(1) ~=0) then + error("pxx must be one-sided"); + end + df= mean(diff(f)); + + if(rbw 0 & pxx(indexleft) <= pxx(indexleft+1) + indexleft = indexleft - 1; + end + + + while indexright <= length(pxx) & pxx(indexright-1) >= pxx(indexright) + indexright = indexright + 1; + end + + indexleft = indexleft+1; + indexright = indexright-1; + ffreq = f(indexleft:indexright); + sfreq = pxx(indexleft:indexright); + fr = (ffreq.*sfreq) ./ sum(sfreq); + + if (indexleft Date: Tue, 25 Jul 2017 23:35:33 +0530 Subject: [PATCH 10/15] Add files via upload --- DSP functions/Filter conversions.sce | 38 ++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 DSP functions/Filter conversions.sce diff --git a/DSP functions/Filter conversions.sce b/DSP functions/Filter conversions.sce new file mode 100644 index 0000000..46b10fc --- /dev/null +++ b/DSP functions/Filter conversions.sce @@ -0,0 +1,38 @@ +// Zero,pole, gain frequency transformation + +b = [0.1969,0.4449,0.4449,0.1969]; //[b,a]=ellip(3,0.1,30,0.409) (taken from matlab) +a = [1.0000,-0.1737,0.5160,-0.0588]; +z = roots(b); +p = roots(a); +k = b(1); +[z1,p1,k1] = zpklp2mb(z, p, k, 0.5, [2 4 6 8]/10, 'pass'); +[xm,fr]=frmag(b,a,256); +[xm1,fr1]=frmag(real(k1)*real(poly(z1,'s')), real(poly(p1,'s')),256); +scf(0); +plot(fr*2,20*log(abs(xm))/log(10),'b',fr1*2,20*log(abs(xm1))/log(10),'r'); +xlabel('Normaliized Frequency'); +ylabel('Magnituse(dB)'); +title('Low pass to multi band pass'); +[z2,p2,k2] = zpklp2hp(z, p, k, 0.5, 0.8); +[xm2,fr2]=frmag(real(k2)*real(poly(z2,'s')), real(poly(p2,'s')),256); +scf(1); +plot(fr*2,20*log(abs(xm))/log(10),'b',fr2*2,20*log(abs(xm2))/log(10),'r'); +xlabel('Normaliized Frequency'); +ylabel('Magnituse(dB)'); +title('Low pass to high pass'); +// +[z3,p3,k3] = zpklp2bp(z, p, k, 0.5, [0.45,0.75]); +[xm3,fr3]=frmag(real(k3)*real(poly(z3,'s')), real(poly(p3,'s')),256); +scf(2); +plot(fr*2,20*log(abs(xm))/log(10),'b',fr3*2,20*log(abs(xm3))/log(10),'r'); +xlabel('Normaliized Frequency'); +ylabel('Magnituse(dB)'); +title('Low pass to band pass'); +// +[z4,p4,k4] = zpklp2bs(z, p, k, 0.5, [0.4,0.7]); +[xm4,fr4]=frmag(real(k4)*real(poly(z4,'s')), real(poly(p4,'s')),256); +scf(3); +plot(fr*2,20*log(abs(xm))/log(10),'b',fr4*2,20*log(abs(xm4))/log(10),'r'); +xlabel('Normaliized Frequency'); +ylabel('Magnituse(dB)'); +title('Low pass to band stop'); From b7ac6b7a17e934fb490de716203f1f7a9f83f8e1 Mon Sep 17 00:00:00 2001 From: Shrenik Nambiar Date: Tue, 25 Jul 2017 23:39:10 +0530 Subject: [PATCH 11/15] Add files via upload --- .../allpassbpc2bpc/allpassbpc2bpc.sci | 58 +++++++++++++ DSP functions/allpassbpc2bpc/test_1.sce | 7 ++ DSP functions/allpassbpc2bpc/test_10.sce | 13 +++ DSP functions/allpassbpc2bpc/test_2.sce | 5 ++ DSP functions/allpassbpc2bpc/test_3.sce | 5 ++ DSP functions/allpassbpc2bpc/test_4.sce | 7 ++ DSP functions/allpassbpc2bpc/test_5.sce | 7 ++ DSP functions/allpassbpc2bpc/test_6.sce | 7 ++ DSP functions/allpassbpc2bpc/test_7.sce | 10 +++ DSP functions/allpassbpc2bpc/test_8.sce | 7 ++ DSP functions/allpassbpc2bpc/test_9.sce | 13 +++ DSP functions/allpasslp2bp/allpasslp2bp.sci | 56 ++++++++++++ DSP functions/allpasslp2bp/test_1.sce | 7 ++ DSP functions/allpasslp2bp/test_10.sce | 13 +++ DSP functions/allpasslp2bp/test_2.sce | 5 ++ DSP functions/allpasslp2bp/test_3.sce | 5 ++ DSP functions/allpasslp2bp/test_4.sce | 7 ++ DSP functions/allpasslp2bp/test_5.sce | 7 ++ DSP functions/allpasslp2bp/test_6.sce | 7 ++ DSP functions/allpasslp2bp/test_7.sce | 10 +++ DSP functions/allpasslp2bp/test_8.sce | 7 ++ DSP functions/allpasslp2bp/test_9.sce | 13 +++ DSP functions/allpasslp2bpc/allpasslp2bpc.sci | 57 +++++++++++++ DSP functions/allpasslp2bpc/test_1.sce | 7 ++ DSP functions/allpasslp2bpc/test_10.sce | 13 +++ DSP functions/allpasslp2bpc/test_2.sce | 5 ++ DSP functions/allpasslp2bpc/test_3.sce | 5 ++ DSP functions/allpasslp2bpc/test_4.sce | 7 ++ DSP functions/allpasslp2bpc/test_5.sce | 7 ++ DSP functions/allpasslp2bpc/test_6.sce | 7 ++ DSP functions/allpasslp2bpc/test_7.sce | 10 +++ DSP functions/allpasslp2bpc/test_8.sce | 7 ++ DSP functions/allpasslp2bpc/test_9.sce | 13 +++ DSP functions/allpasslp2bs/allpasslp2bs.sci | 57 +++++++++++++ DSP functions/allpasslp2bs/test_1.sce | 7 ++ DSP functions/allpasslp2bs/test_10.sce | 13 +++ DSP functions/allpasslp2bs/test_2.sce | 5 ++ DSP functions/allpasslp2bs/test_3.sce | 5 ++ DSP functions/allpasslp2bs/test_4.sce | 7 ++ DSP functions/allpasslp2bs/test_5.sce | 7 ++ DSP functions/allpasslp2bs/test_6.sce | 7 ++ DSP functions/allpasslp2bs/test_7.sce | 10 +++ DSP functions/allpasslp2bs/test_8.sce | 7 ++ DSP functions/allpasslp2bs/test_9.sce | 13 +++ DSP functions/allpasslp2bsc/allpasslp2bsc.sci | 57 +++++++++++++ DSP functions/allpasslp2bsc/test_1.sce | 7 ++ DSP functions/allpasslp2bsc/test_10.sce | 13 +++ DSP functions/allpasslp2bsc/test_2.sce | 5 ++ DSP functions/allpasslp2bsc/test_3.sce | 5 ++ DSP functions/allpasslp2bsc/test_4.sce | 7 ++ DSP functions/allpasslp2bsc/test_5.sce | 7 ++ DSP functions/allpasslp2bsc/test_6.sce | 7 ++ DSP functions/allpasslp2bsc/test_7.sce | 10 +++ DSP functions/allpasslp2bsc/test_8.sce | 7 ++ DSP functions/allpasslp2bsc/test_9.sce | 13 +++ DSP functions/allpasslp2hp/allpasslp2hp.sci | 57 +++++++++++++ DSP functions/allpasslp2hp/test_1.sce | 5 ++ DSP functions/allpasslp2hp/test_10.sce | 7 ++ DSP functions/allpasslp2hp/test_11.sce | 13 +++ DSP functions/allpasslp2hp/test_12.sce | 13 +++ DSP functions/allpasslp2hp/test_13.sce | 7 ++ DSP functions/allpasslp2hp/test_2.sce | 5 ++ DSP functions/allpasslp2hp/test_3.sce | 5 ++ DSP functions/allpasslp2hp/test_4.sce | 7 ++ DSP functions/allpasslp2hp/test_5.sce | 7 ++ DSP functions/allpasslp2hp/test_6.sce | 7 ++ DSP functions/allpasslp2hp/test_7.sce | 7 ++ DSP functions/allpasslp2hp/test_8.sce | 10 +++ DSP functions/allpasslp2hp/test_9.sce | 7 ++ DSP functions/allpasslp2lp/allpasslp2lp.sci | 54 ++++++++++++ DSP functions/allpasslp2lp/test_1.sce | 7 ++ DSP functions/allpasslp2lp/test_10.sce | 7 ++ DSP functions/allpasslp2lp/test_11.sce | 13 +++ DSP functions/allpasslp2lp/test_12.sce | 13 +++ DSP functions/allpasslp2lp/test_13.sce | 7 ++ DSP functions/allpasslp2lp/test_2.sce | 5 ++ DSP functions/allpasslp2lp/test_3.sce | 5 ++ DSP functions/allpasslp2lp/test_4.sce | 7 ++ DSP functions/allpasslp2lp/test_5.sce | 7 ++ DSP functions/allpasslp2lp/test_6.sce | 7 ++ DSP functions/allpasslp2lp/test_7.sce | 7 ++ DSP functions/allpasslp2lp/test_8.sce | 10 +++ DSP functions/allpasslp2lp/test_9.sce | 7 ++ DSP functions/allpasslp2mb/allpasslp2mb.sci | 85 +++++++++++++++++++ DSP functions/allpasslp2mb/test_1.sce | 7 ++ DSP functions/allpasslp2mb/test_10.sce | 10 +++ DSP functions/allpasslp2mb/test_11.sce | 7 ++ DSP functions/allpasslp2mb/test_12.sce | 13 +++ DSP functions/allpasslp2mb/test_13.sce | 13 +++ DSP functions/allpasslp2mb/test_14.sce | 13 +++ DSP functions/allpasslp2mb/test_2.sce | 7 ++ DSP functions/allpasslp2mb/test_3.sce | 5 ++ DSP functions/allpasslp2mb/test_4.sce | 7 ++ DSP functions/allpasslp2mb/test_5.sce | 7 ++ DSP functions/allpasslp2mb/test_6.sce | 7 ++ DSP functions/allpasslp2mb/test_7.sce | 7 ++ DSP functions/allpasslp2mb/test_8.sce | 7 ++ DSP functions/allpasslp2mb/test_9.sce | 7 ++ 98 files changed, 1205 insertions(+) create mode 100644 DSP functions/allpassbpc2bpc/allpassbpc2bpc.sci create mode 100644 DSP functions/allpassbpc2bpc/test_1.sce create mode 100644 DSP functions/allpassbpc2bpc/test_10.sce create mode 100644 DSP functions/allpassbpc2bpc/test_2.sce create mode 100644 DSP functions/allpassbpc2bpc/test_3.sce create mode 100644 DSP functions/allpassbpc2bpc/test_4.sce create mode 100644 DSP functions/allpassbpc2bpc/test_5.sce create mode 100644 DSP functions/allpassbpc2bpc/test_6.sce create mode 100644 DSP functions/allpassbpc2bpc/test_7.sce create mode 100644 DSP functions/allpassbpc2bpc/test_8.sce create mode 100644 DSP functions/allpassbpc2bpc/test_9.sce create mode 100644 DSP functions/allpasslp2bp/allpasslp2bp.sci create mode 100644 DSP functions/allpasslp2bp/test_1.sce create mode 100644 DSP functions/allpasslp2bp/test_10.sce create mode 100644 DSP functions/allpasslp2bp/test_2.sce create mode 100644 DSP functions/allpasslp2bp/test_3.sce create mode 100644 DSP functions/allpasslp2bp/test_4.sce create mode 100644 DSP functions/allpasslp2bp/test_5.sce create mode 100644 DSP functions/allpasslp2bp/test_6.sce create mode 100644 DSP functions/allpasslp2bp/test_7.sce create mode 100644 DSP functions/allpasslp2bp/test_8.sce create mode 100644 DSP functions/allpasslp2bp/test_9.sce create mode 100644 DSP functions/allpasslp2bpc/allpasslp2bpc.sci create mode 100644 DSP functions/allpasslp2bpc/test_1.sce create mode 100644 DSP functions/allpasslp2bpc/test_10.sce create mode 100644 DSP functions/allpasslp2bpc/test_2.sce create mode 100644 DSP functions/allpasslp2bpc/test_3.sce create mode 100644 DSP functions/allpasslp2bpc/test_4.sce create mode 100644 DSP functions/allpasslp2bpc/test_5.sce create mode 100644 DSP functions/allpasslp2bpc/test_6.sce create mode 100644 DSP functions/allpasslp2bpc/test_7.sce create mode 100644 DSP functions/allpasslp2bpc/test_8.sce create mode 100644 DSP functions/allpasslp2bpc/test_9.sce create mode 100644 DSP functions/allpasslp2bs/allpasslp2bs.sci create mode 100644 DSP functions/allpasslp2bs/test_1.sce create mode 100644 DSP functions/allpasslp2bs/test_10.sce create mode 100644 DSP functions/allpasslp2bs/test_2.sce create mode 100644 DSP functions/allpasslp2bs/test_3.sce create mode 100644 DSP functions/allpasslp2bs/test_4.sce create mode 100644 DSP functions/allpasslp2bs/test_5.sce create mode 100644 DSP functions/allpasslp2bs/test_6.sce create mode 100644 DSP functions/allpasslp2bs/test_7.sce create mode 100644 DSP functions/allpasslp2bs/test_8.sce create mode 100644 DSP functions/allpasslp2bs/test_9.sce create mode 100644 DSP functions/allpasslp2bsc/allpasslp2bsc.sci create mode 100644 DSP functions/allpasslp2bsc/test_1.sce create mode 100644 DSP functions/allpasslp2bsc/test_10.sce create mode 100644 DSP functions/allpasslp2bsc/test_2.sce create mode 100644 DSP functions/allpasslp2bsc/test_3.sce create mode 100644 DSP functions/allpasslp2bsc/test_4.sce create mode 100644 DSP functions/allpasslp2bsc/test_5.sce create mode 100644 DSP functions/allpasslp2bsc/test_6.sce create mode 100644 DSP functions/allpasslp2bsc/test_7.sce create mode 100644 DSP functions/allpasslp2bsc/test_8.sce create mode 100644 DSP functions/allpasslp2bsc/test_9.sce create mode 100644 DSP functions/allpasslp2hp/allpasslp2hp.sci create mode 100644 DSP functions/allpasslp2hp/test_1.sce create mode 100644 DSP functions/allpasslp2hp/test_10.sce create mode 100644 DSP functions/allpasslp2hp/test_11.sce create mode 100644 DSP functions/allpasslp2hp/test_12.sce create mode 100644 DSP functions/allpasslp2hp/test_13.sce create mode 100644 DSP functions/allpasslp2hp/test_2.sce create mode 100644 DSP functions/allpasslp2hp/test_3.sce create mode 100644 DSP functions/allpasslp2hp/test_4.sce create mode 100644 DSP functions/allpasslp2hp/test_5.sce create mode 100644 DSP functions/allpasslp2hp/test_6.sce create mode 100644 DSP functions/allpasslp2hp/test_7.sce create mode 100644 DSP functions/allpasslp2hp/test_8.sce create mode 100644 DSP functions/allpasslp2hp/test_9.sce create mode 100644 DSP functions/allpasslp2lp/allpasslp2lp.sci create mode 100644 DSP functions/allpasslp2lp/test_1.sce create mode 100644 DSP functions/allpasslp2lp/test_10.sce create mode 100644 DSP functions/allpasslp2lp/test_11.sce create mode 100644 DSP functions/allpasslp2lp/test_12.sce create mode 100644 DSP functions/allpasslp2lp/test_13.sce create mode 100644 DSP functions/allpasslp2lp/test_2.sce create mode 100644 DSP functions/allpasslp2lp/test_3.sce create mode 100644 DSP functions/allpasslp2lp/test_4.sce create mode 100644 DSP functions/allpasslp2lp/test_5.sce create mode 100644 DSP functions/allpasslp2lp/test_6.sce create mode 100644 DSP functions/allpasslp2lp/test_7.sce create mode 100644 DSP functions/allpasslp2lp/test_8.sce create mode 100644 DSP functions/allpasslp2lp/test_9.sce create mode 100644 DSP functions/allpasslp2mb/allpasslp2mb.sci create mode 100644 DSP functions/allpasslp2mb/test_1.sce create mode 100644 DSP functions/allpasslp2mb/test_10.sce create mode 100644 DSP functions/allpasslp2mb/test_11.sce create mode 100644 DSP functions/allpasslp2mb/test_12.sce create mode 100644 DSP functions/allpasslp2mb/test_13.sce create mode 100644 DSP functions/allpasslp2mb/test_14.sce create mode 100644 DSP functions/allpasslp2mb/test_2.sce create mode 100644 DSP functions/allpasslp2mb/test_3.sce create mode 100644 DSP functions/allpasslp2mb/test_4.sce create mode 100644 DSP functions/allpasslp2mb/test_5.sce create mode 100644 DSP functions/allpasslp2mb/test_6.sce create mode 100644 DSP functions/allpasslp2mb/test_7.sce create mode 100644 DSP functions/allpasslp2mb/test_8.sce create mode 100644 DSP functions/allpasslp2mb/test_9.sce diff --git a/DSP functions/allpassbpc2bpc/allpassbpc2bpc.sci b/DSP functions/allpassbpc2bpc/allpassbpc2bpc.sci new file mode 100644 index 0000000..852d109 --- /dev/null +++ b/DSP functions/allpassbpc2bpc/allpassbpc2bpc.sci @@ -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 diff --git a/DSP functions/allpassbpc2bpc/test_1.sce b/DSP functions/allpassbpc2bpc/test_1.sce new file mode 100644 index 0000000..aa7964d --- /dev/null +++ b/DSP functions/allpassbpc2bpc/test_1.sce @@ -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(); diff --git a/DSP functions/allpassbpc2bpc/test_10.sce b/DSP functions/allpassbpc2bpc/test_10.sce new file mode 100644 index 0000000..e03966b --- /dev/null +++ b/DSP functions/allpassbpc2bpc/test_10.sce @@ -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 diff --git a/DSP functions/allpassbpc2bpc/test_2.sce b/DSP functions/allpassbpc2bpc/test_2.sce new file mode 100644 index 0000000..82b5917 --- /dev/null +++ b/DSP functions/allpassbpc2bpc/test_2.sce @@ -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 diff --git a/DSP functions/allpassbpc2bpc/test_3.sce b/DSP functions/allpassbpc2bpc/test_3.sce new file mode 100644 index 0000000..acf0331 --- /dev/null +++ b/DSP functions/allpassbpc2bpc/test_3.sce @@ -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 diff --git a/DSP functions/allpassbpc2bpc/test_4.sce b/DSP functions/allpassbpc2bpc/test_4.sce new file mode 100644 index 0000000..c9796b1 --- /dev/null +++ b/DSP functions/allpassbpc2bpc/test_4.sce @@ -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]); diff --git a/DSP functions/allpassbpc2bpc/test_5.sce b/DSP functions/allpassbpc2bpc/test_5.sce new file mode 100644 index 0000000..be70ae7 --- /dev/null +++ b/DSP functions/allpassbpc2bpc/test_5.sce @@ -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]); diff --git a/DSP functions/allpassbpc2bpc/test_6.sce b/DSP functions/allpassbpc2bpc/test_6.sce new file mode 100644 index 0000000..8bf9c73 --- /dev/null +++ b/DSP functions/allpassbpc2bpc/test_6.sce @@ -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]); diff --git a/DSP functions/allpassbpc2bpc/test_7.sce b/DSP functions/allpassbpc2bpc/test_7.sce new file mode 100644 index 0000000..573ee47 --- /dev/null +++ b/DSP functions/allpassbpc2bpc/test_7.sce @@ -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 diff --git a/DSP functions/allpassbpc2bpc/test_8.sce b/DSP functions/allpassbpc2bpc/test_8.sce new file mode 100644 index 0000000..c773ba2 --- /dev/null +++ b/DSP functions/allpassbpc2bpc/test_8.sce @@ -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); diff --git a/DSP functions/allpassbpc2bpc/test_9.sce b/DSP functions/allpassbpc2bpc/test_9.sce new file mode 100644 index 0000000..d801dd7 --- /dev/null +++ b/DSP functions/allpassbpc2bpc/test_9.sce @@ -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 diff --git a/DSP functions/allpasslp2bp/allpasslp2bp.sci b/DSP functions/allpasslp2bp/allpasslp2bp.sci new file mode 100644 index 0000000..c3691c6 --- /dev/null +++ b/DSP functions/allpasslp2bp/allpasslp2bp.sci @@ -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 diff --git a/DSP functions/allpasslp2bp/test_1.sce b/DSP functions/allpasslp2bp/test_1.sce new file mode 100644 index 0000000..a599ca2 --- /dev/null +++ b/DSP functions/allpasslp2bp/test_1.sce @@ -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(); diff --git a/DSP functions/allpasslp2bp/test_10.sce b/DSP functions/allpasslp2bp/test_10.sce new file mode 100644 index 0000000..239fc9c --- /dev/null +++ b/DSP functions/allpasslp2bp/test_10.sce @@ -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 diff --git a/DSP functions/allpasslp2bp/test_2.sce b/DSP functions/allpasslp2bp/test_2.sce new file mode 100644 index 0000000..a267051 --- /dev/null +++ b/DSP functions/allpasslp2bp/test_2.sce @@ -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 diff --git a/DSP functions/allpasslp2bp/test_3.sce b/DSP functions/allpasslp2bp/test_3.sce new file mode 100644 index 0000000..513fd87 --- /dev/null +++ b/DSP functions/allpasslp2bp/test_3.sce @@ -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 diff --git a/DSP functions/allpasslp2bp/test_4.sce b/DSP functions/allpasslp2bp/test_4.sce new file mode 100644 index 0000000..fff1c0c --- /dev/null +++ b/DSP functions/allpasslp2bp/test_4.sce @@ -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]); diff --git a/DSP functions/allpasslp2bp/test_5.sce b/DSP functions/allpasslp2bp/test_5.sce new file mode 100644 index 0000000..1c4b992 --- /dev/null +++ b/DSP functions/allpasslp2bp/test_5.sce @@ -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]); diff --git a/DSP functions/allpasslp2bp/test_6.sce b/DSP functions/allpasslp2bp/test_6.sce new file mode 100644 index 0000000..f9d4c2b --- /dev/null +++ b/DSP functions/allpasslp2bp/test_6.sce @@ -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]); diff --git a/DSP functions/allpasslp2bp/test_7.sce b/DSP functions/allpasslp2bp/test_7.sce new file mode 100644 index 0000000..d99930d --- /dev/null +++ b/DSP functions/allpasslp2bp/test_7.sce @@ -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 diff --git a/DSP functions/allpasslp2bp/test_8.sce b/DSP functions/allpasslp2bp/test_8.sce new file mode 100644 index 0000000..2ebf3e2 --- /dev/null +++ b/DSP functions/allpasslp2bp/test_8.sce @@ -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]); diff --git a/DSP functions/allpasslp2bp/test_9.sce b/DSP functions/allpasslp2bp/test_9.sce new file mode 100644 index 0000000..a11ffa4 --- /dev/null +++ b/DSP functions/allpasslp2bp/test_9.sce @@ -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 diff --git a/DSP functions/allpasslp2bpc/allpasslp2bpc.sci b/DSP functions/allpasslp2bpc/allpasslp2bpc.sci new file mode 100644 index 0000000..f8f6756 --- /dev/null +++ b/DSP functions/allpasslp2bpc/allpasslp2bpc.sci @@ -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 diff --git a/DSP functions/allpasslp2bpc/test_1.sce b/DSP functions/allpasslp2bpc/test_1.sce new file mode 100644 index 0000000..fca5f5e --- /dev/null +++ b/DSP functions/allpasslp2bpc/test_1.sce @@ -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(); diff --git a/DSP functions/allpasslp2bpc/test_10.sce b/DSP functions/allpasslp2bpc/test_10.sce new file mode 100644 index 0000000..52b1df4 --- /dev/null +++ b/DSP functions/allpasslp2bpc/test_10.sce @@ -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 diff --git a/DSP functions/allpasslp2bpc/test_2.sce b/DSP functions/allpasslp2bpc/test_2.sce new file mode 100644 index 0000000..dd8bc85 --- /dev/null +++ b/DSP functions/allpasslp2bpc/test_2.sce @@ -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 diff --git a/DSP functions/allpasslp2bpc/test_3.sce b/DSP functions/allpasslp2bpc/test_3.sce new file mode 100644 index 0000000..31bd0aa --- /dev/null +++ b/DSP functions/allpasslp2bpc/test_3.sce @@ -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 diff --git a/DSP functions/allpasslp2bpc/test_4.sce b/DSP functions/allpasslp2bpc/test_4.sce new file mode 100644 index 0000000..eecc2cc --- /dev/null +++ b/DSP functions/allpasslp2bpc/test_4.sce @@ -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]); diff --git a/DSP functions/allpasslp2bpc/test_5.sce b/DSP functions/allpasslp2bpc/test_5.sce new file mode 100644 index 0000000..3a2d1d5 --- /dev/null +++ b/DSP functions/allpasslp2bpc/test_5.sce @@ -0,0 +1,7 @@ +// Test #5 : Input Argument #1 range test +exec('./allpasslp2bpc.sci',-1); +[n,d]=allpasslp2bpc(4,[0.23,0.9]); +//!--error 10000 +//Wo must lie between 0 and 1 +//at line 39 of function allpasslp2bpc called by : +//[n,d]=allpasslp2bpc(4,[0.23,0.9]); diff --git a/DSP functions/allpasslp2bpc/test_6.sce b/DSP functions/allpasslp2bpc/test_6.sce new file mode 100644 index 0000000..732e701 --- /dev/null +++ b/DSP functions/allpasslp2bpc/test_6.sce @@ -0,0 +1,7 @@ +// Test #6 : Input Argument #2 range test +exec('./allpasslp2bpc.sci',-1); +[n,d]=allpasslp2bpc(0.848,[-3,0.2]); +//!--error 10000 +//Wt must lie between 0 and 1 +//at line 46 of function allpasslp2bpc called by : +//[n,d]=allpasslp2bpc(0.848,[-3,0.2]); diff --git a/DSP functions/allpasslp2bpc/test_7.sce b/DSP functions/allpasslp2bpc/test_7.sce new file mode 100644 index 0000000..63ed294 --- /dev/null +++ b/DSP functions/allpasslp2bpc/test_7.sce @@ -0,0 +1,10 @@ +// Test #7 : For 1 output argument +exec('./allpasslp2bpc.sci',-1); +[n]=allpasslp2bpc(0.41,[0.35,0.9]); +disp(n); +// +//Scilab Output +//n=- 0.2391553 -0.3826834 + 0.9238795i +// +//Matlab Output +//n= -0.2392 + 0.0000i -0.3827 + 0.9239i diff --git a/DSP functions/allpasslp2bpc/test_8.sce b/DSP functions/allpasslp2bpc/test_8.sce new file mode 100644 index 0000000..f7f8ce9 --- /dev/null +++ b/DSP functions/allpasslp2bpc/test_8.sce @@ -0,0 +1,7 @@ +// Test # 8 : Input Argument #1 or #2 length test +exec('./allpasslp2bpc.sci',-1); +[n,d]=allpasslp2bpc(0.3,[0.56,0.8,0.99]); +//!--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.3,[0.56,0.8,0.99]); diff --git a/DSP functions/allpasslp2bpc/test_9.sce b/DSP functions/allpasslp2bpc/test_9.sce new file mode 100644 index 0000000..9b5b5d6 --- /dev/null +++ b/DSP functions/allpasslp2bpc/test_9.sce @@ -0,0 +1,13 @@ +// Test # 9 : Valid input test case #1 +exec('./allpasslp2bpc.sci',-1); +[n,d]=allpasslp2bpc(0.8,[0.426,0.633]); +disp(d); +disp(n); +// +//Scilab Output +//d=1. 0.0831792 - 0.8949461i +//n=-0.8988033 -0.0925444 + 0.9957086i + +//Matlab Output +//n= -0.8988 + 0.0000i -0.0925 + 0.9957i +//d= 1.0000 + 0.0000i 0.0832 - 0.8949i diff --git a/DSP functions/allpasslp2bs/allpasslp2bs.sci b/DSP functions/allpasslp2bs/allpasslp2bs.sci new file mode 100644 index 0000000..b225c7c --- /dev/null +++ b/DSP functions/allpasslp2bs/allpasslp2bs.sci @@ -0,0 +1,57 @@ +function [AllpassNum,AllpassDen]= allpasslp2bs (Wo,Wt) +// Allpass filter for lowpass to bandstop transformation +// +//Calling Sequence: +//[AllpassNum,AllpassDen] = allpasslp2bs(Wo,Wt): returns the numerator, AllpassNum, and the denominator, AllpassDen, of the second-order allpass mapping filter for performing a real lowpass to real bandstop 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. This transformation implements the "Nyquist Mobility," which means that the DC feature stays at DC, but the Nyquist feature moves to a location dependent on the selection of Wo and 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.65 to the real–valued bandstop filter with cutoff frequencies at Wt1=0.23 and Wt2=0.45. +// +// Wo = 0.65; Wt = [0.23 0.45]; +// [AllpassNum, AllpassDen] = allpasslp2bs(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 be either 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 + Wc = sum(Wt) / 2; + bw = max(Wt) - min(Wt); + al = cos(%pi*(Wo+bw)/2) / cos(%pi*(Wo-bw)/2); + be = cos(%pi*Wc) / cos(%pi*bw/2); + AllpassDen = [1 -be*(1+al) al]; + AllpassNum = flipdim(AllpassDen,2); + +endfunction diff --git a/DSP functions/allpasslp2bs/test_1.sce b/DSP functions/allpasslp2bs/test_1.sce new file mode 100644 index 0000000..d04887b --- /dev/null +++ b/DSP functions/allpasslp2bs/test_1.sce @@ -0,0 +1,7 @@ +// Test # 1 : No Input Arguments +exec('./allpasslp2bs.sci',-1); +[n,d]=allpasslp2bs(); +//!--error 10000 +//Number of input arguments should be 2 +//at line 28 of function allpasslp2bs called by : +//[n,d]=allpasslp2bs(); diff --git a/DSP functions/allpasslp2bs/test_10.sce b/DSP functions/allpasslp2bs/test_10.sce new file mode 100644 index 0000000..a2d2e8d --- /dev/null +++ b/DSP functions/allpasslp2bs/test_10.sce @@ -0,0 +1,13 @@ +// Test #10 : Valid input test case #2 +exec('./allpasslp2bs.sci',-1); +[n,d]=allpasslp2bs(0.23,[0.2,0.67]); +disp(d); +disp(n); +// +//Scilab Output +//d=1. -0.4080468 0.4882792 +//n=0.4882792 - 0.4080468 1. + +//Matlab Output +//n= 0.4883 -0.4080 1.0000 +//d= 1.0000 -0.4080 0.4883 diff --git a/DSP functions/allpasslp2bs/test_2.sce b/DSP functions/allpasslp2bs/test_2.sce new file mode 100644 index 0000000..2833f95 --- /dev/null +++ b/DSP functions/allpasslp2bs/test_2.sce @@ -0,0 +1,5 @@ +// Test # 2 : Excess Input Arguments +exec('./allpasslp2bs.sci',-1); +[n,d]=allpasslp2bs(0.1,[0.1,0.2],0.3); +//!--error 58 +//Wrong number of input arguments diff --git a/DSP functions/allpasslp2bs/test_3.sce b/DSP functions/allpasslp2bs/test_3.sce new file mode 100644 index 0000000..a7fb211 --- /dev/null +++ b/DSP functions/allpasslp2bs/test_3.sce @@ -0,0 +1,5 @@ +// Test # 3 : Incorrect number of output Arguments +exec('./allpasslp2bs.sci',-1); +[n,d,e]=allpasslp2bs(0.1,[0.2,0.3]); +//!--error 59 +//Wrong number of output arguments diff --git a/DSP functions/allpasslp2bs/test_4.sce b/DSP functions/allpasslp2bs/test_4.sce new file mode 100644 index 0000000..3182dd5 --- /dev/null +++ b/DSP functions/allpasslp2bs/test_4.sce @@ -0,0 +1,7 @@ +// Test # 4 : When either Input Argument #1 or #2 is of complex type +exec('./allpasslp2bs.sci',-1); +[n,d]=allpasslp2bs(0.3,[0.4,0.2*%i]); +//!--error 10000 +//Wt must be real and numeric and must contain only 2 elements +//at line 43 of function allpasslp2bs called by : +//[n,d]=allpasslp2bs(0.3,[0.4,0.2*%i]); diff --git a/DSP functions/allpasslp2bs/test_5.sce b/DSP functions/allpasslp2bs/test_5.sce new file mode 100644 index 0000000..4d811ac --- /dev/null +++ b/DSP functions/allpasslp2bs/test_5.sce @@ -0,0 +1,7 @@ +// Test #5 : Input Argument #1 range test +exec('./allpasslp2bs.sci',-1); +[n,d]=allpasslp2bs(11,[0.35,0.53]); +//!--error 10000 +//Wo must lie between 0 and 1 +//at line 39 of function allpasslp2bs called by : +//[n,d]=allpasslp2bs(11,[0.35,0.53]); diff --git a/DSP functions/allpasslp2bs/test_6.sce b/DSP functions/allpasslp2bs/test_6.sce new file mode 100644 index 0000000..25d0fa2 --- /dev/null +++ b/DSP functions/allpasslp2bs/test_6.sce @@ -0,0 +1,7 @@ +// Test #6 : Input Argument #2 range test +exec('./allpasslp2bs.sci',-1); +[n,d]=allpasslp2bs(0.4,[-4,0.39]); +//!--error 10000 +//Wt must lie between 0 and 1 +//at line 46 of function allpasslp2bs called by : +//[n,d]=allpasslp2bs(0.4,[-4,0.39]); diff --git a/DSP functions/allpasslp2bs/test_7.sce b/DSP functions/allpasslp2bs/test_7.sce new file mode 100644 index 0000000..6b92f08 --- /dev/null +++ b/DSP functions/allpasslp2bs/test_7.sce @@ -0,0 +1,10 @@ +// Test #7 : For 1 output argument +exec('./allpasslp2bs.sci',-1); +[n]=allpasslp2bs(0.67,[0.2,0.73]); +disp(n); +// +//Scilab Output +//n=-0.3166428 -0.1114210 1. +// +//Matlab Output +//n=-0.3166 -0.1114 1.0000 diff --git a/DSP functions/allpasslp2bs/test_8.sce b/DSP functions/allpasslp2bs/test_8.sce new file mode 100644 index 0000000..45368c7 --- /dev/null +++ b/DSP functions/allpasslp2bs/test_8.sce @@ -0,0 +1,7 @@ +// Test # 8 : Input Argument #1 or #2 length test +exec('./allpasslp2bs.sci',-1); +[n,d]=allpasslp2bs(0.3,[0.11,0.2,0.9]); +//!--error 10000 +//Wt must be real and numeric and must contain only 2 elements +//at line 43 of function allpasslp2bs called by : +//[n,d]=allpasslp2bs(0.3,[0.11,0.2,0.9]); diff --git a/DSP functions/allpasslp2bs/test_9.sce b/DSP functions/allpasslp2bs/test_9.sce new file mode 100644 index 0000000..eb8e098 --- /dev/null +++ b/DSP functions/allpasslp2bs/test_9.sce @@ -0,0 +1,13 @@ +// Test # 9 : Valid input test case #1 +exec('./allpasslp2bs.sci',-1); +[n,d]=allpasslp2bs(0.2,[0.9,0.98]); +disp(d); +disp(n); +// +//Scilab Output +//d=1. 1.902113 0.9211430 +//n=0.9211430 1.902113 1. +// +//Matlab Output +//n=0.9211 1.9021 1.0000 +//d=1.0000 1.9021 0.9211 diff --git a/DSP functions/allpasslp2bsc/allpasslp2bsc.sci b/DSP functions/allpasslp2bsc/allpasslp2bsc.sci new file mode 100644 index 0000000..69a60b0 --- /dev/null +++ b/DSP functions/allpasslp2bsc/allpasslp2bsc.sci @@ -0,0 +1,57 @@ +function [AllpassNum,AllpassDen]= allpasslp2bsc (Wo,Wt) +// Allpass filter for lowpass to complex bandstop transformation +// +//Calling Sequence: +//[AllpassNum,AllpassDen] = allpasslp2bsc(Wo,Wt) returns the numerator, AllpassNum, and the denominator, AllpassDen, of the first-order allpass mapping filter for performing a real lowpass to complex bandstop 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. Additionally the transformation swaps passbands with stopbands in the target filter. +// +//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 bandstop filter with cutoff frequencies at Wt1=0.3 and Wt2=0.4. +// +// Wo = 0.6; Wt = [0.3 0.4]; +// [AllpassNum, AllpassDen] = allpasslp2bsc(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 + Wc = sum(Wt) / 2; + bw = max(Wt) - min(Wt); + al = cos(%pi*(Wo+bw/2)/2) / cos(%pi*(Wo-bw/2)/2); + be = exp(-%pi*%i*Wc); + AllpassNum = flipdim((conj([-be +al])),2); + AllpassDen = flipdim((conj([-al*be 1])),2); + +endfunction diff --git a/DSP functions/allpasslp2bsc/test_1.sce b/DSP functions/allpasslp2bsc/test_1.sce new file mode 100644 index 0000000..513b0a1 --- /dev/null +++ b/DSP functions/allpasslp2bsc/test_1.sce @@ -0,0 +1,7 @@ +// Test # 1 : No Input Arguments +exec('./allpasslp2bsc.sci',-1); +[n,d]=allpasslp2bsc(); +//!--error 10000 +//Number of input arguments should be 2 +//at line 28 of function allpasslp2bsc called by : +//[n,d]=allpasslp2bsc(); diff --git a/DSP functions/allpasslp2bsc/test_10.sce b/DSP functions/allpasslp2bsc/test_10.sce new file mode 100644 index 0000000..562093b --- /dev/null +++ b/DSP functions/allpasslp2bsc/test_10.sce @@ -0,0 +1,13 @@ +// Test #10 : Valid input test case #2 +exec('./allpasslp2bsc.sci',-1); +[n,d]=allpasslp2bsc(0.786,[0.549,0.8746]); +disp(d); +disp(n); +// +//Scilab Output +//d=1. 0.0888982 - 0.1132783i +//n=0.1439960 0.6173655 - 0.7866765i +// +//Matlab Output +//n= 0.1440 + 0.0000i 0.6174 - 0.7867i +//d= 1.0000 + 0.0000i 0.0889 - 0.1133i diff --git a/DSP functions/allpasslp2bsc/test_2.sce b/DSP functions/allpasslp2bsc/test_2.sce new file mode 100644 index 0000000..1490f53 --- /dev/null +++ b/DSP functions/allpasslp2bsc/test_2.sce @@ -0,0 +1,5 @@ +// Test # 2 : Excess Input Arguments +exec('./allpasslp2bsc.sci',-1); +[n,d]=allpasslp2bsc(0.4,[0.5,0.6],6); +//!--error 58 +//Wrong number of input arguments diff --git a/DSP functions/allpasslp2bsc/test_3.sce b/DSP functions/allpasslp2bsc/test_3.sce new file mode 100644 index 0000000..8eab355 --- /dev/null +++ b/DSP functions/allpasslp2bsc/test_3.sce @@ -0,0 +1,5 @@ +// Test # 3 : Incorrect number of output Arguments +exec('./allpasslp2bsc.sci',-1); +[n,d,e]=allpasslp2bsc(0.98,[0.1,0.2]); +//!--error 59 +//Wrong number of output arguments diff --git a/DSP functions/allpasslp2bsc/test_4.sce b/DSP functions/allpasslp2bsc/test_4.sce new file mode 100644 index 0000000..b7a0275 --- /dev/null +++ b/DSP functions/allpasslp2bsc/test_4.sce @@ -0,0 +1,7 @@ +// Test # 4 : When either Input Argument #1 or #2 is of complex type +exec('./allpasslp2bsc.sci',-1); +[n,d]=allpasslp2bsc(0.1*%i,[0.2,0.7]); +//!--error 10000 +//Wo must be real ,numeric and scalar +//at line 36 of function allpasslp2bsc called by : +//[n,d]=allpasslp2bsc(0.1*%i,[0.2,0.7]); diff --git a/DSP functions/allpasslp2bsc/test_5.sce b/DSP functions/allpasslp2bsc/test_5.sce new file mode 100644 index 0000000..ad17b96 --- /dev/null +++ b/DSP functions/allpasslp2bsc/test_5.sce @@ -0,0 +1,7 @@ +// Test #5 : Input Argument #1 range test +exec('./allpasslp2bsc.sci',-1); +[n,d]=allpasslp2bsc(-32,[0.5,0.89]); +//!--error 10000 +//Wo must lie between 0 and 1 +//at line 39 of function allpasslp2bsc called by : +//[n,d]=allpasslp2bsc(-32,[0.5,0.89]); diff --git a/DSP functions/allpasslp2bsc/test_6.sce b/DSP functions/allpasslp2bsc/test_6.sce new file mode 100644 index 0000000..8a850b2 --- /dev/null +++ b/DSP functions/allpasslp2bsc/test_6.sce @@ -0,0 +1,7 @@ +// Test #6 : Input Argument #2 range test +exec('./allpasslp2bsc.sci',-1); +[n,d]=allpasslp2bsc(0.2,[0.4,-0.39]); +//!--error 10000 +//Wt must lie between 0 and 1 +//at line 46 of function allpasslp2bsc called by : +//[n,d]=allpasslp2bsc(0.2,[0.4,-0.39]); diff --git a/DSP functions/allpasslp2bsc/test_7.sce b/DSP functions/allpasslp2bsc/test_7.sce new file mode 100644 index 0000000..5e97411 --- /dev/null +++ b/DSP functions/allpasslp2bsc/test_7.sce @@ -0,0 +1,10 @@ +// Test #7 : For 1 output argument +exec('./allpasslp2bsc.sci',-1); +[n]=allpasslp2bsc(0.22,[0.45,0.93]); +disp(n); +// +//Scilab Output +//n=0.7504814 0.5620834 - 0.8270806i +// +//Matlab Output +//n=0.7505 + 0.0000i 0.5621 - 0.8271i diff --git a/DSP functions/allpasslp2bsc/test_8.sce b/DSP functions/allpasslp2bsc/test_8.sce new file mode 100644 index 0000000..5ce142f --- /dev/null +++ b/DSP functions/allpasslp2bsc/test_8.sce @@ -0,0 +1,7 @@ +// Test # 8 : Input Argument #1 or #2 length test +exec('./allpasslp2bsc.sci',-1); +[n,d]=allpasslp2bsc([0.3,0.4],[0.3,0.42]); +//!--error 10000 +//Wo must be real ,numeric and scalar +//at line 36 of function allpasslp2bsc called by : +//[n,d]=allpasslp2bsc([0.3,0.4],[0.3,0.42]); diff --git a/DSP functions/allpasslp2bsc/test_9.sce b/DSP functions/allpasslp2bsc/test_9.sce new file mode 100644 index 0000000..2b1cad7 --- /dev/null +++ b/DSP functions/allpasslp2bsc/test_9.sce @@ -0,0 +1,13 @@ +// Test # 9 : Valid input test case #1 +exec('./allpasslp2bsc.sci',-1); +[n,d]=allpasslp2bsc(0.65,[0.34,0.56]); +disp(d); +disp(n); +// +//Scilab Output +//d=1. -0.0870805-0.5498046i +//n=0.5566580 -0.1564345-0.9876883i +// +//Matlab Output +//n= 0.5567 + 0.0000i -0.1564 - 0.9877i +//d= 1.0000 + 0.0000i -0.0871 - 0.5498i diff --git a/DSP functions/allpasslp2hp/allpasslp2hp.sci b/DSP functions/allpasslp2hp/allpasslp2hp.sci new file mode 100644 index 0000000..e2230a5 --- /dev/null +++ b/DSP functions/allpasslp2hp/allpasslp2hp.sci @@ -0,0 +1,57 @@ +function [AllpassNum,AllpassDen] = allpasslp2hp(Wo,Wt) +// Allpass filter for lowpass to highpass transformation +// +//Calling Sequence: +//[AllpassNum,AllpassDen] = allpasslp2hp(Wo,Wt) returns the numerator, AllpassNum, and the denominator, AllpassDen, of the first-order allpass mapping filter for performing a real lowpass to real highpass frequency transformation. This transformation effectively places one feature of an original filter, located originally at frequency, Wo, at the required target frequency location, Wt, at the same time rotating the whole frequency response by half of the sampling frequency. Result is that the DC and Nyquist features swap places. +// +//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 filter changing the lowpass filter to the highpass filter with its cutoff frequency moved from Wo = 0.5 to Wt = 0.2. +// +// Wo = 0.5; Wt =0.2; +// [AllpassNum, AllpassDen] = allpasslp2hp(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 ~isscalar(Wt) | ~isreal(Wt) then + error("Wt must be real,numeric and scalar"); + end + + if Wt<=0 | Wt>=1 then + error("Wt must lie between 0 and 1"); + end + +//Calculating the numerator and denominator for the mapping filter + al = -cos(%pi*(Wo+Wt)/2) / cos(%pi*(Wo-Wt)/2); + AllpassNum = [-al -1]; + AllpassDen = flipdim(-AllpassNum,2); + +endfunction diff --git a/DSP functions/allpasslp2hp/test_1.sce b/DSP functions/allpasslp2hp/test_1.sce new file mode 100644 index 0000000..b515b5e --- /dev/null +++ b/DSP functions/allpasslp2hp/test_1.sce @@ -0,0 +1,5 @@ +// Test # 1 : No Input Arguments +exec('./allpasslp2hp.sci',-1); +[n,d]=allpasslp2hp(); +//!--error 10000 +//Number of input arguments should be 2 diff --git a/DSP functions/allpasslp2hp/test_10.sce b/DSP functions/allpasslp2hp/test_10.sce new file mode 100644 index 0000000..d54fb06 --- /dev/null +++ b/DSP functions/allpasslp2hp/test_10.sce @@ -0,0 +1,7 @@ +// Test # 10 : Input Argument #2 length +exec('./allpasslp2hp.sci',-1); +[n,d]=allpasslp2hp(0.3,[0.6,0.2]); +//!--error 10000 +//Wt must be real,numeric and scalar +//at line 45 of function allpasslp2hp called by : +//[n,d]= allpasslp2hp(0.3,[0.6,0.2]) diff --git a/DSP functions/allpasslp2hp/test_11.sce b/DSP functions/allpasslp2hp/test_11.sce new file mode 100644 index 0000000..04881f6 --- /dev/null +++ b/DSP functions/allpasslp2hp/test_11.sce @@ -0,0 +1,13 @@ +// Test # 11 : Valid input test case #1 +exec('./allpasslp2hp.sci',-1); +[n,d]=allpasslp2hp(0.3,0.6); +disp(d); +disp(n); +// +//Scilab Output +//d= 1 -0.1755705 +//n= 0.1755705 -1 + +//Matlab Output +//d = 1.0000 -0.1756 +//n = 0.1756 -1.0000 diff --git a/DSP functions/allpasslp2hp/test_12.sce b/DSP functions/allpasslp2hp/test_12.sce new file mode 100644 index 0000000..7ecf31e --- /dev/null +++ b/DSP functions/allpasslp2hp/test_12.sce @@ -0,0 +1,13 @@ +// Test # 12 : Valid input test case #2 +exec('./allpasslp2hp.sci',-1); +[n,d]=allpasslp2hp(0.256,0.877); +disp(d); +disp(n); +// +//Scilab Output +//d =1. 0.3698388 +//n =- 0.3698388 - 1 +// +//Matlab Output +//d = 1.0000 0.3698 +//n = -0.3698 -1.0000 diff --git a/DSP functions/allpasslp2hp/test_13.sce b/DSP functions/allpasslp2hp/test_13.sce new file mode 100644 index 0000000..bd88725 --- /dev/null +++ b/DSP functions/allpasslp2hp/test_13.sce @@ -0,0 +1,7 @@ +// Test # 13 : For zero valued inputs +exec('./allpasslp2hp.sci',-1); +[n,d]=allpasslp2hp(0,0); +// !--error 10000 +//Wo must lie between 0 and 1 +//at line 41 of function allpasslp2hp called by : +//[n,d]=allpasslp2hp(0,0) diff --git a/DSP functions/allpasslp2hp/test_2.sce b/DSP functions/allpasslp2hp/test_2.sce new file mode 100644 index 0000000..15da38f --- /dev/null +++ b/DSP functions/allpasslp2hp/test_2.sce @@ -0,0 +1,5 @@ +// Test # 2 : Excess Input Arguments +exec('./allpasslp2hp.sci',-1); +[n,d]=allpasslp2hp(0.3,0.2,0.7); +//!--error 58 +//Wrong number of input arguments diff --git a/DSP functions/allpasslp2hp/test_3.sce b/DSP functions/allpasslp2hp/test_3.sce new file mode 100644 index 0000000..dd51d8f --- /dev/null +++ b/DSP functions/allpasslp2hp/test_3.sce @@ -0,0 +1,5 @@ +// Test # 3 : Incorrect number of output Arguments +exec('./allpasslp2hp.sci',-1); +[n,d,e]=allpasslp2hp(0.3,0.2); +//!--error 59 +//Wrong number of output arguments diff --git a/DSP functions/allpasslp2hp/test_4.sce b/DSP functions/allpasslp2hp/test_4.sce new file mode 100644 index 0000000..3be3880 --- /dev/null +++ b/DSP functions/allpasslp2hp/test_4.sce @@ -0,0 +1,7 @@ +// Test # 4 : Input Argument #1 is of complex type +exec('./allpasslp2hp.sci',-1); +[n,d]=allpasslp2hp(%i,0.3); +//!--error 10000 +//Wo must be real ,numeric and scalar +//at line 37 of function allpasslp2hp called by : +//[n,d]= allpasslp2hp(%i,0.3) diff --git a/DSP functions/allpasslp2hp/test_5.sce b/DSP functions/allpasslp2hp/test_5.sce new file mode 100644 index 0000000..7360e95 --- /dev/null +++ b/DSP functions/allpasslp2hp/test_5.sce @@ -0,0 +1,7 @@ +// Test # 5 : Input Argument #2 is of complex type +exec('./allpasslp2hp.sci',-1); +[n,d]=allpasslp2hp(0.3,%i); +//!--error 10000 +//Wt must be real,numeric and scalar +//at line 45 of function allpasslp2hp called by : +//[n,d]= allpasslp2hp(0.3,%i) diff --git a/DSP functions/allpasslp2hp/test_6.sce b/DSP functions/allpasslp2hp/test_6.sce new file mode 100644 index 0000000..e9964d8 --- /dev/null +++ b/DSP functions/allpasslp2hp/test_6.sce @@ -0,0 +1,7 @@ +// Test # 6 : Input Argument #1 range test +exec('./allpasslp2hp.sci',-1); +[n,d]=allpasslp2hp(1.1,0.9); +//!--error 10000 +//Wo must lie between 0 and 1 +//at line 41 of function allpasslp2hp called by : +//[n,d]= allpasslp2hp(1.1,0.9) diff --git a/DSP functions/allpasslp2hp/test_7.sce b/DSP functions/allpasslp2hp/test_7.sce new file mode 100644 index 0000000..09503d0 --- /dev/null +++ b/DSP functions/allpasslp2hp/test_7.sce @@ -0,0 +1,7 @@ +// Test # 7 : Input Argument #2 range test +exec('./allpasslp2hp.sci',-1); +[n,d]=allpasslp2hp(0.3,1.1); +//!--error 10000 +//Wt must lie between 0 and 1 +//at line 49 of function allpasslp2hp called by : +//[n,d]= allpasslp2hp(0.3,1.1) diff --git a/DSP functions/allpasslp2hp/test_8.sce b/DSP functions/allpasslp2hp/test_8.sce new file mode 100644 index 0000000..d35157b --- /dev/null +++ b/DSP functions/allpasslp2hp/test_8.sce @@ -0,0 +1,10 @@ +// Test # 8 : For 1 output argument +exec('./allpasslp2hp.sci',-1); +[n]=allpasslp2hp(0.3,0.2); +disp(n); + +//Scilab Output +//n= 0.7159210 -1 + +//Matlab Output +//n= 0.7159 -1.0000 diff --git a/DSP functions/allpasslp2hp/test_9.sce b/DSP functions/allpasslp2hp/test_9.sce new file mode 100644 index 0000000..3cf7692 --- /dev/null +++ b/DSP functions/allpasslp2hp/test_9.sce @@ -0,0 +1,7 @@ +// Test # 9 : Input Argument #1 length +exec('./allpasslp2hp.sci',-1); +[n,d]=allpasslp2hp([0.3,0.2],0.6); +//!--error 10000 +//Wo must be real ,numeric and scalar +//at line 37 of function allpasslp2hp called by : +//[n,d]= allpasslp2hp([0.3,0.2],0.6) diff --git a/DSP functions/allpasslp2lp/allpasslp2lp.sci b/DSP functions/allpasslp2lp/allpasslp2lp.sci new file mode 100644 index 0000000..e6cde24 --- /dev/null +++ b/DSP functions/allpasslp2lp/allpasslp2lp.sci @@ -0,0 +1,54 @@ +function [AllpassNum,AllpassDen] = allpasslp2lp(Wo,Wt) +// Allpass filter for lowpass to lowpass transformation +// +//Calling Sequence: +//[AllpassNum,AllpassDen] = allpasslp2lp(Wo,Wt) returns the numerator, AllpassNum, and the denominator, AllpassDen, of the first-order allpass mapping filter for performing a real lowpass to real lowpass frequency transformation. This transformation effectively places one feature of an original filter, located originally at frequency Wo, at the required target frequency location, 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 filter changing the lowpass filter cutoff frequency originally at Wo=0.5 to Wt=0.35. Plot the phase response normalized to pi, which is in effect the mapping function Wo(Wt). +// +// Wo = 0.5; Wt =0.35; +// [AllpassNum, AllpassDen] = allpasslp2lp(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 ~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 ~isscalar(Wt) | ~isreal(Wt) then + error("Wt must be real,numeric and scalar"); + end + if Wt<=0 | Wt>=1 then + error("Wt must lie between 0 and 1"); + end + +//Calculating the numerator and denominator for the mapping filter + al = sin(%pi*(Wo-Wt)/2) / sin(%pi*(Wo+Wt)/2); + AllpassNum = [-al 1]; + AllpassDen = [1 -al]; + +endfunction diff --git a/DSP functions/allpasslp2lp/test_1.sce b/DSP functions/allpasslp2lp/test_1.sce new file mode 100644 index 0000000..e482f75 --- /dev/null +++ b/DSP functions/allpasslp2lp/test_1.sce @@ -0,0 +1,7 @@ +// Test # 1 : No Input Arguments +exec('./allpasslp2lp.sci',-1); +[n,d]=allpasslp2lp(); +//!--error 10000 +//Number of input arguments should be 2 +//at line 28 of function allpasslp2lp called by : +//[n,d]=allpasslp2lp(); diff --git a/DSP functions/allpasslp2lp/test_10.sce b/DSP functions/allpasslp2lp/test_10.sce new file mode 100644 index 0000000..2897554 --- /dev/null +++ b/DSP functions/allpasslp2lp/test_10.sce @@ -0,0 +1,7 @@ +// Test # 10 : Input Argument #2 length +exec('./allpasslp2lp.sci',-1); +[n,d]=allpasslp2lp(0.63,[0.26,0.72]); +//!--error 10000 +//Wt must be real,numeric and scalar +//at line 43 of function allpasslp2lp called by : +//[n,d]=allpasslp2lp(0.63,[0.26,0.72]) diff --git a/DSP functions/allpasslp2lp/test_11.sce b/DSP functions/allpasslp2lp/test_11.sce new file mode 100644 index 0000000..4202818 --- /dev/null +++ b/DSP functions/allpasslp2lp/test_11.sce @@ -0,0 +1,13 @@ +// Test # 11 : Valid input test case #1 +exec('./allpasslp2lp.sci',-1); +[n,d]=allpasslp2lp(0.753,0.946); +disp(d); +disp(n); +// +//Scilab Output +//d =1. 0.6555731 +//n = 0.6555731 1. +// +//Matlab Output +//d = 1.0000 0.6556 +//n =0.6556 1.0000 diff --git a/DSP functions/allpasslp2lp/test_12.sce b/DSP functions/allpasslp2lp/test_12.sce new file mode 100644 index 0000000..7046a1a --- /dev/null +++ b/DSP functions/allpasslp2lp/test_12.sce @@ -0,0 +1,13 @@ +// Test # 11 : Valid input test case #1 +exec('./allpasslp2lp.sci',-1); +[n,d]=allpasslp2lp(0.64,0.12); +disp(d); +disp(n); +// +//Scilab Output +//d =1. -0.7840257 +//n =-0.7840257 1. + +//Matlab Output +//d = 1.0000 -0.7840 +//n = -0.7840 1.0000 diff --git a/DSP functions/allpasslp2lp/test_13.sce b/DSP functions/allpasslp2lp/test_13.sce new file mode 100644 index 0000000..8d44279 --- /dev/null +++ b/DSP functions/allpasslp2lp/test_13.sce @@ -0,0 +1,7 @@ +// Test # 13 : For zero valued inputs +exec('./allpasslp2lp.sci',-1); +[n,d]=allpasslp2lp(0,0); +// !--error 10000 +//Wo must lie between 0 and 1 +//at line 39 of function allpasslp2lp called by : +//[n,d]=allpasslp2lp(0,0) diff --git a/DSP functions/allpasslp2lp/test_2.sce b/DSP functions/allpasslp2lp/test_2.sce new file mode 100644 index 0000000..2adba12 --- /dev/null +++ b/DSP functions/allpasslp2lp/test_2.sce @@ -0,0 +1,5 @@ +// Test # 2 : Excess Input Arguments +exec('./allpasslp2lp.sci',-1); +[n,d]=allpasslp2lp(0.1,0.2,0.9); +//!--error 58 +//Wrong number of input arguments diff --git a/DSP functions/allpasslp2lp/test_3.sce b/DSP functions/allpasslp2lp/test_3.sce new file mode 100644 index 0000000..d8bbc74 --- /dev/null +++ b/DSP functions/allpasslp2lp/test_3.sce @@ -0,0 +1,5 @@ +// Test # 3 : Incorrect number of output Arguments +exec('./allpasslp2lp.sci',-1); +[n,d,e]=allpasslp2lp(0.1,0.2); +//!--error 59 +//Wrong number of output arguments diff --git a/DSP functions/allpasslp2lp/test_4.sce b/DSP functions/allpasslp2lp/test_4.sce new file mode 100644 index 0000000..e68c067 --- /dev/null +++ b/DSP functions/allpasslp2lp/test_4.sce @@ -0,0 +1,7 @@ +// Test # 4 : Input Argument #1 is of complex type +exec('./allpasslp2lp.sci',-1); +[n,d]=allpasslp2lp(%i,0.2); +//!--error 10000 +//Wo must be real ,numeric and scalar +//at line 36 of function allpasslp2lp called by : +//[n,d]=allpasslp2lp(%i,0.2) diff --git a/DSP functions/allpasslp2lp/test_5.sce b/DSP functions/allpasslp2lp/test_5.sce new file mode 100644 index 0000000..da46ab2 --- /dev/null +++ b/DSP functions/allpasslp2lp/test_5.sce @@ -0,0 +1,7 @@ +// Test # 4 : Input Argument #2 is of complex type +exec('./allpasslp2mb.sci',-1); +[n,d]=allpasslp2lp(0.3,%i); +//!--error 10000 +//Wo must be real ,numeric and scalar +//at line 37 of function allpasslp2lp called by : +//[n,d]=allpasslp2lp(0.3,%i) diff --git a/DSP functions/allpasslp2lp/test_6.sce b/DSP functions/allpasslp2lp/test_6.sce new file mode 100644 index 0000000..5afd7e7 --- /dev/null +++ b/DSP functions/allpasslp2lp/test_6.sce @@ -0,0 +1,7 @@ +// Test # 6 : Input Argument #1 range test +exec('./allpasslp2lp.sci',-1); +[n,d]=allpasslp2lp(1.1,0.9); +//!--error 10000 +//Wo must lie between 0 and 1 +//at line 39 of function allpasslp2lp called by : +//[n,d]=allpasslp2lp(1.1,0.9) diff --git a/DSP functions/allpasslp2lp/test_7.sce b/DSP functions/allpasslp2lp/test_7.sce new file mode 100644 index 0000000..e176616 --- /dev/null +++ b/DSP functions/allpasslp2lp/test_7.sce @@ -0,0 +1,7 @@ +// Test # 7 : Input Argument #2 range test +exec('./allpasslp2lp.sci',-1); +[n,d]=allpasslp2lp(0.3,1.1); +//!--error 10000 +//Wt must lie between 0 and 1 +//at line 46 of function allpasslp2lp called by : +//[n,d]=allpasslp2lp(0.3,1.1) diff --git a/DSP functions/allpasslp2lp/test_8.sce b/DSP functions/allpasslp2lp/test_8.sce new file mode 100644 index 0000000..3e73c85 --- /dev/null +++ b/DSP functions/allpasslp2lp/test_8.sce @@ -0,0 +1,10 @@ +// Test # 8 : For 1 output argument +exec('./allpasslp2lp.sci',-1); +[n]=allpasslp2lp(0.3,0.434); +disp(n); +// +//Scilab Output +// n = 0.2286023 1. + +//Matlab Output +//n = 0.2286 1.0000 diff --git a/DSP functions/allpasslp2lp/test_9.sce b/DSP functions/allpasslp2lp/test_9.sce new file mode 100644 index 0000000..a63b1f3 --- /dev/null +++ b/DSP functions/allpasslp2lp/test_9.sce @@ -0,0 +1,7 @@ +// Test # 9 : Input Argument #1 length +exec('./allpasslp2lp.sci',-1); +[n,d]=allpasslp2lp([0.33,0.9],0.6); +//!--error 10000 +//Wo must be real ,numeric and scalar +//at line 36 of function allpasslp2lp called by : +//[n,d]=allpasslp2lp([0.33,0.9],0.6) diff --git a/DSP functions/allpasslp2mb/allpasslp2mb.sci b/DSP functions/allpasslp2mb/allpasslp2mb.sci new file mode 100644 index 0000000..149a63d --- /dev/null +++ b/DSP functions/allpasslp2mb/allpasslp2mb.sci @@ -0,0 +1,85 @@ +function [AllpassNum,AllpassDen]= allpasslp2mb (Wo,Wt,varargin) +// Allpass filter for lowpass to M-band transfomation +// +//Calling Sequence: +//[AllpassNum,AllpassDen] = allpasslp2mb(Wo,Wt) returns the numerator, AllpassNum, and the denominator, AllpassDen, of the Mth-order allpass mapping filter for performing a real lowpass to real multipassband frequency transformation. Parameter M is the number of times an original feature is replicated in the target filter. This transformation effectively places one feature of an original filter, located at frequency Wo, at the required target frequency locations, Wt1,...,WtM. +// +//[AllpassNum,AllpassDen] = allpasslp2mb(Wo,Wt,P) allows you to specify an additional parameter, Pass, which chooses between using the "DC Mobility" and the "Nyquist Mobility." In the first case the Nyquist feature stays at its original location and the DC feature is free to move. In the second case the DC feature is kept at an original frequency and the Nyquist feature is movable. + +//Input Parameters: +// Wo: Frequency value of the prototype filter +// Wt: Desired Frequencies for the target filter +// P: Choice ('pass'/'stop') of passband/stopband at DC, 'pass' being the default +//Output Parameters: +// AllpassNum: Numerator of mapping filer +// AllpassDen: Denominator of mapping filter +//Example: Design the allpass filter changing the real lowpass filter with the cutoff frequency of Wo=0.5 into a real multiband filter with band edges of Wt=[2:3:8]/10 precisely defined. Plot the phase response normalized to pi, which is in effect the mapping function Wo(Wt) +// +// Wo = 0.5; Wt =[0.2:0.3:0.8]; +// [AllpassNum, AllpassDen] = allpasslp2lp(Wo, Wt); +// [h, f] = freqz(AllpassNum, AllpassDen); +// plot(f/%pi,-angle(h)/%pi); +// +//Author: Shrenik Nambiar +// +//References: 1. Franchitti, J.C., "All-pass filter interpolation and frequency transformation problems,"MSc Thesis, Dept. of Electrical and Computer Engineering, University of Colorado, 1985. +// 2. Feyh, G., J.C. Franchitti and C.T. Mullis, "All-pass filter interpolation and frequency transformation problem," Proceedings 20th Asilomar Conference on Signals, Systems and Computers, Pacific Grove, California, pp. 164-168, November 1986. +// +// Input Validation Statements + if argn(2) <2 | argn(2) >3 then + error("Number of input arguments should either 2 or 3"); + 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 ~isvector(Wt) | ~isreal(Wt) then + error("Wt must be vector and real"); + end + + for i= 1:length(Wt) + if Wt(i) <=0 | Wt(i) >=1 then + error("Wt must be in normalised form"); + end + end + + if (length(varargin)==1) & (type(varargin(1))~=10) then + error("Input argument #3 must be of type char"); + end + + if length(varargin)==0 then + pass= -1; //pass being the default option + else + P=varargin(1); + select P + case 'pass' then + pass=-1; + case 'stop' then + pass=1; + else + error("Invalid option,input should be either pass or stop"); + end + end + l=length(Wt); +//Calculating the numerator and denominator for the mapping filter + Wold =%pi * Wo * (-1).^(0:l-1); + Wnew =%pi * Wt(:).'; + al=sin(Wnew.'/2 * (l-2:-2:-l) -Wold.'/2*ones(1,l)); + AllpassDen =[1 -sin(l*Wnew/2-Wold/2)/al']; + AllpassNum = (flipdim(AllpassDen,2))*pass; + +endfunction + + + + + + diff --git a/DSP functions/allpasslp2mb/test_1.sce b/DSP functions/allpasslp2mb/test_1.sce new file mode 100644 index 0000000..f874826 --- /dev/null +++ b/DSP functions/allpasslp2mb/test_1.sce @@ -0,0 +1,7 @@ +// Test # 1 : No Input Arguments +exec('./allpasslp2mb.sci',-1); +[n,d]=allpasslp2mb(); +//!--error 10000 +//Number of input arguments should either 2 or 3 +//at line 30 of function allpasslp2mb called by : +//[n,d] = allpasslp2mb() diff --git a/DSP functions/allpasslp2mb/test_10.sce b/DSP functions/allpasslp2mb/test_10.sce new file mode 100644 index 0000000..7d44d7c --- /dev/null +++ b/DSP functions/allpasslp2mb/test_10.sce @@ -0,0 +1,10 @@ +// Test # 10 : For 1 output argument +exec('./allpasslp2mb.sci',-1); +[n]=allpasslp2mb(0.3,[0.434,.731]); +disp(n); +// +//Scilab Output +//n=- 0.5915977 - 0.4567161 - 1. +// +//Matlab Output +//n= -0.5916 -0.4567 -1.0000 diff --git a/DSP functions/allpasslp2mb/test_11.sce b/DSP functions/allpasslp2mb/test_11.sce new file mode 100644 index 0000000..ecec7c9 --- /dev/null +++ b/DSP functions/allpasslp2mb/test_11.sce @@ -0,0 +1,7 @@ +// Test # 11 : Input Argument #1 length +exec('./allpasslp2mb.sci',-1); +[n,d]=allpasslp2mb([0.23,0.49],0.16); +//!--error 10000 +//Wo must be real ,numeric and scalar +//at line 38 of function allpasslp2mb called by : +//[n,d]=allpasslp2mb([0.23,0.49],0.16) diff --git a/DSP functions/allpasslp2mb/test_12.sce b/DSP functions/allpasslp2mb/test_12.sce new file mode 100644 index 0000000..2bb58d6 --- /dev/null +++ b/DSP functions/allpasslp2mb/test_12.sce @@ -0,0 +1,13 @@ +// Test # 12 : Valid input test case #1 +exec('./allpasslp2mb.sci',-1); +[n,d]=allpasslp2mb(0.753,[0.32,0.45,0.66]); +disp(d); +disp(n); +// +//Scilab Output +// d=1. - 0.5596341 0.8425653 - 0.3801107 +//n=0.3801107 - 0.8425653 0.5596341 - 1. +// +//Matlab Output +//d = 1.0000 -0.5596 0.8426 -0.3801 +//n = 0.3801 -0.8426 0.5596 -1.0000 diff --git a/DSP functions/allpasslp2mb/test_13.sce b/DSP functions/allpasslp2mb/test_13.sce new file mode 100644 index 0000000..199d441 --- /dev/null +++ b/DSP functions/allpasslp2mb/test_13.sce @@ -0,0 +1,13 @@ +// Test # 13 : Valid input test case #2 +exec('./allpasslp2mb.sci',-1); +[n,d]=allpasslp2mb(0.53,[0.32,0.21,0.65]); +disp(d); +disp(n); +// +//Scilab Output +//d= 1. - 1.4218628 0.8259669 0.3936125 +//n =- 0.3936125 - 0.8259669 1.4218628 - 1. +// +//Matlab Output +//d = 1.0000 -1.4219 0.8260 0.3936 +//n = -0.3936 -0.8260 1.4219 -1.0000 diff --git a/DSP functions/allpasslp2mb/test_14.sce b/DSP functions/allpasslp2mb/test_14.sce new file mode 100644 index 0000000..4eba6bd --- /dev/null +++ b/DSP functions/allpasslp2mb/test_14.sce @@ -0,0 +1,13 @@ +// Test # 14 : Valid input test case with flag +exec('./allpasslp2mb.sci',-1); +[n,d]=allpasslp2mb(0.21,[0.42,0.51,0.85],'stop'); +disp(d); +disp(n); +// +//Scilab Output +//d=1. 0.6936787 0.7879411 0.7612510 +//n=0.7612510 0.7879411 0.6936787 1. +// +//Matlab Output +//d = 1.0000 0.6937 0.7879 0.7613 +//n = 0.7613 0.7879 0.6937 1.0000 diff --git a/DSP functions/allpasslp2mb/test_2.sce b/DSP functions/allpasslp2mb/test_2.sce new file mode 100644 index 0000000..76c7fae --- /dev/null +++ b/DSP functions/allpasslp2mb/test_2.sce @@ -0,0 +1,7 @@ +// Test # 2 : Excess Input Arguments +exec('./allpasslp2mb.sci',-1); +[n,d]=allpasslp2mb(0.3,0.7,'pass',0.9); +//!--error 10000 +//Number of input arguments should either 2 or 3 +//at line 30 of function allpasslp2mb called by : +//[n,d]=allpasslp2mb(0.3,0.7,'pass',0.9) diff --git a/DSP functions/allpasslp2mb/test_3.sce b/DSP functions/allpasslp2mb/test_3.sce new file mode 100644 index 0000000..002cba7 --- /dev/null +++ b/DSP functions/allpasslp2mb/test_3.sce @@ -0,0 +1,5 @@ +// Test # 3 : Incorrect number of output Arguments +exec('./allpasslp2mb.sci',-1); +[n,d,e]=allpasslp2mb(0.3,0.2); +//!--error 59 +//Wrong number of output arguments diff --git a/DSP functions/allpasslp2mb/test_4.sce b/DSP functions/allpasslp2mb/test_4.sce new file mode 100644 index 0000000..b2e57db --- /dev/null +++ b/DSP functions/allpasslp2mb/test_4.sce @@ -0,0 +1,7 @@ +// Test # 4 : For zero valued inputs +exec('./allpasslp2mb.sci',-1); +[n,d]=allpasslp2mb(0,0); +// !--error 10000 +//Wo must lie between 0 and 1 +//at line 41 of function allpasslp2mb called by : +//[n,d]=allpasslp2mb(0,0) diff --git a/DSP functions/allpasslp2mb/test_5.sce b/DSP functions/allpasslp2mb/test_5.sce new file mode 100644 index 0000000..e953480 --- /dev/null +++ b/DSP functions/allpasslp2mb/test_5.sce @@ -0,0 +1,7 @@ +// Test # 5 : Input Argument #1 is of complex type +exec('./allpasslp2mb.sci',-1); +[n,d]=allpasslp2mb(%i,0.7); +//!--error 10000 +//Wo must be real ,numeric and scalar +//at line 38 of function allpasslp2mb called by : +//[n,d]=allpasslp2mb(%i,0.7) diff --git a/DSP functions/allpasslp2mb/test_6.sce b/DSP functions/allpasslp2mb/test_6.sce new file mode 100644 index 0000000..22aa8bd --- /dev/null +++ b/DSP functions/allpasslp2mb/test_6.sce @@ -0,0 +1,7 @@ +// Test # 6 : Input Argument #2 is of complex type +exec('./allpasslp2mb.sci',-1); +[n,d]=allpasslp2mb(0.33,%i); +//!--error 10000 +//Wt must be vector and real +//at line 45 of function allpasslp2mb called by : +//[n,d]=allpasslp2mb(0.33,%i) diff --git a/DSP functions/allpasslp2mb/test_7.sce b/DSP functions/allpasslp2mb/test_7.sce new file mode 100644 index 0000000..ad80018 --- /dev/null +++ b/DSP functions/allpasslp2mb/test_7.sce @@ -0,0 +1,7 @@ +// Test # 7 : Input Argument #1 range test +exec('./allpasslp2mb.sci',-1); +[n,d]=allpasslp2mb(1.1,0.9); +//!--error 10000 +//Wo must lie between 0 and 1 +//at line 41 of function allpasslp2mb called by : +//[n,d]=allpasslp2mb(1.1,0.9) diff --git a/DSP functions/allpasslp2mb/test_8.sce b/DSP functions/allpasslp2mb/test_8.sce new file mode 100644 index 0000000..3981a75 --- /dev/null +++ b/DSP functions/allpasslp2mb/test_8.sce @@ -0,0 +1,7 @@ +// Test # 8 : Input Argument #2 range test +exec('./allpasslp2mb.sci',-1); +[n,d]=allpasslp2mb(0.4,[0.3,1.2]); +//!--error 10000 +//Wt must be in normalised form +//at line 50 of function allpasslp2mb called by : +//[n,d]=allpasslp2mb(0.4,[0.3,1.2]) diff --git a/DSP functions/allpasslp2mb/test_9.sce b/DSP functions/allpasslp2mb/test_9.sce new file mode 100644 index 0000000..42acb96 --- /dev/null +++ b/DSP functions/allpasslp2mb/test_9.sce @@ -0,0 +1,7 @@ +// Test # 9 : Invalid flag test +exec('./allpasslp2mb.sci',-1); +[n,d]=allpasslp2mb(0.4,[0.3,0.4],'j'); +//!--error 10000 +//Invalid option,input should be either pass or stop +//at line 68 of function allpasslp2mb called by : +//[n,d]=allpasslp2mb(0.4,[0.3,0.4],'j') From fd2af45dbbcd70a656b86f750d4141b18559b44e Mon Sep 17 00:00:00 2001 From: Shrenik Nambiar Date: Tue, 25 Jul 2017 23:42:20 +0530 Subject: [PATCH 12/15] Add files via upload --- DSP functions/allpasslp2xn/allpasslp2xn.sci | 128 +++++++++++++++++ DSP functions/allpasslp2xn/test_1.sce | 7 + DSP functions/allpasslp2xn/test_2.sce | 7 + DSP functions/allpasslp2xn/test_3.sce | 5 + DSP functions/allpasslp2xn/test_4.sce | 7 + DSP functions/allpasslp2xn/test_5.sce | 7 + DSP functions/allpasslp2xn/test_6.sce | 7 + DSP functions/allpasslp2xn/test_7.sce | 14 ++ DSP functions/allpasslp2xn/test_8.sce | 14 ++ DSP functions/allpasslp2xn/test_9.sce | 13 ++ DSP functions/allpassrateup/allpassrateup.sci | 44 ++++++ DSP functions/allpassrateup/test_1.sce | 7 + DSP functions/allpassrateup/test_2.sce | 5 + DSP functions/allpassrateup/test_3.sce | 5 + DSP functions/allpassrateup/test_4.sce | 7 + DSP functions/allpassrateup/test_5.sce | 10 ++ DSP functions/allpassrateup/test_6.sce | 6 + DSP functions/allpassrateup/test_7.sce | 13 ++ DSP functions/allpassshift/allpassshift.sci | 57 ++++++++ DSP functions/allpassshift/test_1.sce | 7 + DSP functions/allpassshift/test_10.sce | 7 + DSP functions/allpassshift/test_11.sce | 10 ++ DSP functions/allpassshift/test_12.sce | 13 ++ DSP functions/allpassshift/test_13.sce | 13 ++ DSP functions/allpassshift/test_2.sce | 5 + DSP functions/allpassshift/test_3.sce | 5 + DSP functions/allpassshift/test_4.sce | 7 + DSP functions/allpassshift/test_5.sce | 7 + DSP functions/allpassshift/test_6.sce | 7 + DSP functions/allpassshift/test_7.sce | 7 + DSP functions/allpassshift/test_8.sce | 7 + DSP functions/allpassshift/test_9.sce | 7 + DSP functions/allpassshiftc/allpassshiftc.sci | 53 +++++++ DSP functions/allpassshiftc/test_1.sce | 7 + DSP functions/allpassshiftc/test_10.sce | 7 + DSP functions/allpassshiftc/test_11.sce | 10 ++ DSP functions/allpassshiftc/test_12.sce | 13 ++ DSP functions/allpassshiftc/test_13.sce | 13 ++ DSP functions/allpassshiftc/test_14.sce | 13 ++ DSP functions/allpassshiftc/test_2.sce | 5 + DSP functions/allpassshiftc/test_3.sce | 5 + DSP functions/allpassshiftc/test_4.sce | 7 + DSP functions/allpassshiftc/test_5.sce | 7 + DSP functions/allpassshiftc/test_6.sce | 7 + DSP functions/allpassshiftc/test_7.sce | 7 + DSP functions/allpassshiftc/test_8.sce | 13 ++ DSP functions/allpassshiftc/test_9.sce | 7 + DSP functions/iirpowcomp/iirpowcomp.sci | 108 ++++++++++++++ DSP functions/iirpowcomp/test_1.sce | 7 + DSP functions/iirpowcomp/test_2.sce | 7 + DSP functions/iirpowcomp/test_3.sce | 6 + DSP functions/iirpowcomp/test_4.sce | 11 ++ DSP functions/iirpowcomp/test_5.sce | 14 ++ DSP functions/iirpowcomp/test_6.sce | 13 ++ DSP functions/iirpowcomp/test_7.sce | 19 +++ DSP functions/tf2ca/test_1.sce | 7 + DSP functions/tf2ca/test_2.sce | 5 + DSP functions/tf2ca/test_3.sce | 5 + DSP functions/tf2ca/test_4.sce | 7 + DSP functions/tf2ca/test_5.sce | 16 +++ DSP functions/tf2ca/test_6.sce | 16 +++ DSP functions/tf2ca/test_7.sce | 7 + DSP functions/tf2ca/test_8.sce | 7 + DSP functions/tf2ca/tf2ca.sci | 133 ++++++++++++++++++ DSP functions/tf2cl/test_1.sce | 7 + DSP functions/tf2cl/test_2.sce | 5 + DSP functions/tf2cl/test_3.sce | 5 + DSP functions/tf2cl/test_4.sce | 8 ++ DSP functions/tf2cl/test_5.sce | 16 +++ DSP functions/tf2cl/tf2cl.sci | 59 ++++++++ DSP functions/zpkbpc2bpc/test_1.sce | 7 + DSP functions/zpkbpc2bpc/test_10.sce | 26 ++++ DSP functions/zpkbpc2bpc/test_2.sce | 5 + DSP functions/zpkbpc2bpc/test_3.sce | 7 + DSP functions/zpkbpc2bpc/test_4.sce | 5 + DSP functions/zpkbpc2bpc/test_5.sce | 7 + DSP functions/zpkbpc2bpc/test_6.sce | 7 + DSP functions/zpkbpc2bpc/test_7.sce | 7 + DSP functions/zpkbpc2bpc/test_8.sce | 16 +++ DSP functions/zpkbpc2bpc/test_9.sce | 28 ++++ DSP functions/zpkbpc2bpc/zpkbpc2bpc.sci | 99 +++++++++++++ DSP functions/zpklp2bp/test_1.sce | 7 + DSP functions/zpklp2bp/test_10.sce | 30 ++++ DSP functions/zpklp2bp/test_2.sce | 5 + DSP functions/zpklp2bp/test_3.sce | 7 + DSP functions/zpklp2bp/test_4.sce | 5 + DSP functions/zpklp2bp/test_5.sce | 7 + DSP functions/zpklp2bp/test_6.sce | 7 + DSP functions/zpklp2bp/test_7.sce | 7 + DSP functions/zpklp2bp/test_8.sce | 20 +++ DSP functions/zpklp2bp/test_9.sce | 31 ++++ DSP functions/zpklp2bp/zpklp2bp.sci | 92 ++++++++++++ 92 files changed, 1559 insertions(+) create mode 100644 DSP functions/allpasslp2xn/allpasslp2xn.sci create mode 100644 DSP functions/allpasslp2xn/test_1.sce create mode 100644 DSP functions/allpasslp2xn/test_2.sce create mode 100644 DSP functions/allpasslp2xn/test_3.sce create mode 100644 DSP functions/allpasslp2xn/test_4.sce create mode 100644 DSP functions/allpasslp2xn/test_5.sce create mode 100644 DSP functions/allpasslp2xn/test_6.sce create mode 100644 DSP functions/allpasslp2xn/test_7.sce create mode 100644 DSP functions/allpasslp2xn/test_8.sce create mode 100644 DSP functions/allpasslp2xn/test_9.sce create mode 100644 DSP functions/allpassrateup/allpassrateup.sci create mode 100644 DSP functions/allpassrateup/test_1.sce create mode 100644 DSP functions/allpassrateup/test_2.sce create mode 100644 DSP functions/allpassrateup/test_3.sce create mode 100644 DSP functions/allpassrateup/test_4.sce create mode 100644 DSP functions/allpassrateup/test_5.sce create mode 100644 DSP functions/allpassrateup/test_6.sce create mode 100644 DSP functions/allpassrateup/test_7.sce create mode 100644 DSP functions/allpassshift/allpassshift.sci create mode 100644 DSP functions/allpassshift/test_1.sce create mode 100644 DSP functions/allpassshift/test_10.sce create mode 100644 DSP functions/allpassshift/test_11.sce create mode 100644 DSP functions/allpassshift/test_12.sce create mode 100644 DSP functions/allpassshift/test_13.sce create mode 100644 DSP functions/allpassshift/test_2.sce create mode 100644 DSP functions/allpassshift/test_3.sce create mode 100644 DSP functions/allpassshift/test_4.sce create mode 100644 DSP functions/allpassshift/test_5.sce create mode 100644 DSP functions/allpassshift/test_6.sce create mode 100644 DSP functions/allpassshift/test_7.sce create mode 100644 DSP functions/allpassshift/test_8.sce create mode 100644 DSP functions/allpassshift/test_9.sce create mode 100644 DSP functions/allpassshiftc/allpassshiftc.sci create mode 100644 DSP functions/allpassshiftc/test_1.sce create mode 100644 DSP functions/allpassshiftc/test_10.sce create mode 100644 DSP functions/allpassshiftc/test_11.sce create mode 100644 DSP functions/allpassshiftc/test_12.sce create mode 100644 DSP functions/allpassshiftc/test_13.sce create mode 100644 DSP functions/allpassshiftc/test_14.sce create mode 100644 DSP functions/allpassshiftc/test_2.sce create mode 100644 DSP functions/allpassshiftc/test_3.sce create mode 100644 DSP functions/allpassshiftc/test_4.sce create mode 100644 DSP functions/allpassshiftc/test_5.sce create mode 100644 DSP functions/allpassshiftc/test_6.sce create mode 100644 DSP functions/allpassshiftc/test_7.sce create mode 100644 DSP functions/allpassshiftc/test_8.sce create mode 100644 DSP functions/allpassshiftc/test_9.sce create mode 100644 DSP functions/iirpowcomp/iirpowcomp.sci create mode 100644 DSP functions/iirpowcomp/test_1.sce create mode 100644 DSP functions/iirpowcomp/test_2.sce create mode 100644 DSP functions/iirpowcomp/test_3.sce create mode 100644 DSP functions/iirpowcomp/test_4.sce create mode 100644 DSP functions/iirpowcomp/test_5.sce create mode 100644 DSP functions/iirpowcomp/test_6.sce create mode 100644 DSP functions/iirpowcomp/test_7.sce create mode 100644 DSP functions/tf2ca/test_1.sce create mode 100644 DSP functions/tf2ca/test_2.sce create mode 100644 DSP functions/tf2ca/test_3.sce create mode 100644 DSP functions/tf2ca/test_4.sce create mode 100644 DSP functions/tf2ca/test_5.sce create mode 100644 DSP functions/tf2ca/test_6.sce create mode 100644 DSP functions/tf2ca/test_7.sce create mode 100644 DSP functions/tf2ca/test_8.sce create mode 100644 DSP functions/tf2ca/tf2ca.sci create mode 100644 DSP functions/tf2cl/test_1.sce create mode 100644 DSP functions/tf2cl/test_2.sce create mode 100644 DSP functions/tf2cl/test_3.sce create mode 100644 DSP functions/tf2cl/test_4.sce create mode 100644 DSP functions/tf2cl/test_5.sce create mode 100644 DSP functions/tf2cl/tf2cl.sci create mode 100644 DSP functions/zpkbpc2bpc/test_1.sce create mode 100644 DSP functions/zpkbpc2bpc/test_10.sce create mode 100644 DSP functions/zpkbpc2bpc/test_2.sce create mode 100644 DSP functions/zpkbpc2bpc/test_3.sce create mode 100644 DSP functions/zpkbpc2bpc/test_4.sce create mode 100644 DSP functions/zpkbpc2bpc/test_5.sce create mode 100644 DSP functions/zpkbpc2bpc/test_6.sce create mode 100644 DSP functions/zpkbpc2bpc/test_7.sce create mode 100644 DSP functions/zpkbpc2bpc/test_8.sce create mode 100644 DSP functions/zpkbpc2bpc/test_9.sce create mode 100644 DSP functions/zpkbpc2bpc/zpkbpc2bpc.sci create mode 100644 DSP functions/zpklp2bp/test_1.sce create mode 100644 DSP functions/zpklp2bp/test_10.sce create mode 100644 DSP functions/zpklp2bp/test_2.sce create mode 100644 DSP functions/zpklp2bp/test_3.sce create mode 100644 DSP functions/zpklp2bp/test_4.sce create mode 100644 DSP functions/zpklp2bp/test_5.sce create mode 100644 DSP functions/zpklp2bp/test_6.sce create mode 100644 DSP functions/zpklp2bp/test_7.sce create mode 100644 DSP functions/zpklp2bp/test_8.sce create mode 100644 DSP functions/zpklp2bp/test_9.sce create mode 100644 DSP functions/zpklp2bp/zpklp2bp.sci diff --git a/DSP functions/allpasslp2xn/allpasslp2xn.sci b/DSP functions/allpasslp2xn/allpasslp2xn.sci new file mode 100644 index 0000000..19f88d2 --- /dev/null +++ b/DSP functions/allpasslp2xn/allpasslp2xn.sci @@ -0,0 +1,128 @@ +function [AllpassNum,AllpassDen]= allpasslp2xn(Wo,Wt,varargin) + + if argn(2)<2 | argn(2)>3 then + error("Number of input arguments should be either 2 or 3"); + end + + if argn(1)<1 | argn(1)>2 then + error("Number of output arguments should be either 1 or 2"); + end + + if length(Wo)<1 | ~isreal(Wo) then + error("Wo must be vector and real"); + end + + m=length(Wo); + + for i= 1:m + if Wo(i) <=-1 | Wo(i) >=1 then + error("Wo must be in normalised"); + end + end + + sortedWo=gsort(Wo,'r','i'); + if Wo~=sortedWo then + error("Wo must in ascending order"); + end + + if length(Wt)<1 | ~isreal(Wt) then + error("Wt must be vector and real"); + end + + n=length(Wt); + + for i= 1:n + if Wt(i) <=-1 | Wt(i) >=1 then + error("Wt must be in normalised"); + end + end + + sortedWt=gsort(Wt,'r','i'); + if Wt~=sortedWt then + error("Wt must in ascending order"); + end + +//Flag checking + if (length(varargin)==1) & (type(varargin(1))~=10) then + error("Input argument #6 must be of type char"); + end + + if length(varargin)==0 then + pass= -1; //pass being the default option + else + Pa=varargin(1); + select Pa + case 'pass' then + pass=-1; + case 'stop' then + pass=1; + else + error("Invalid option,input should be either pass or stop"); + end + end + + + zo = exp(%i*%pi*Wo); + zn = exp(-%i*%pi*Wt); + + for k=1:m + a(k,:) = zo(k) * (zn(k).^(m-1:-1:0)) - pass*(zn(k).^(1:m)); + end + + b = pass - zo.' .*(zn.' .^m); + AllpassNum = real([1; a\b]); + + in= find(isnan(AllpassNum)); + if ~isempty(in) then + AllpassNum= real([1 linsolve(a,b)]) + end + + AllpassDen = flipdim(AllpassNum(:).',2); + AllpassNum = pass*AllpassNum(:).'; + + if isstable(AllpassDen) then + AllpassNum = flipdim(AllpassNum,2); + AllpassDen = flipdim(AllpassDen,2); + end + + z1= roots(AllpassNum); //computing zeros + p1= roots(AllpassDen); //computing poles + k1= frmag(AllpassNum,AllpassDen,1); //gain computation + + lp1= length(p1); + z2=[]; + +// for cancelling overlapping poles and zeros + p1index=zeros(1,lp1); + for j=1:length(z1), + fnd1 = find(abs(z1(j)-p1)<10^-6); + fnd2 = find(p1index(fnd1)<%eps); + fnd = fnd1(fnd2); + if isempty(fnd), + z2 = [z2, z1(j)]; + else + p1index(fnd(1)) = 1; + end + end + + p2= p1(p1index==0); + p2=p2(:).'; + k2=k1; +//the case in which all poles and zeros are cancelled + if isempty(z2) then + z2=0; + end +// Calculating the numerator and denominator for the mapping filter + if length(z2) ~= m then + AllpassNum =poly(z2,'s'); + AllpassDen = k2.*poly(p2,'s'); + s = sign(AllpassDen($)); + AllpassNum = AllpassNum./ s; + AllpassDen = AllpassDen./AllpassDen($); + + [AllpassNum,AllpassDen] = eqtflength(flipdim((AllpassNum),2), flipdim((allpassden),2)); + + end + +endfunction + diff --git a/DSP functions/allpasslp2xn/test_1.sce b/DSP functions/allpasslp2xn/test_1.sce new file mode 100644 index 0000000..0a9fad6 --- /dev/null +++ b/DSP functions/allpasslp2xn/test_1.sce @@ -0,0 +1,7 @@ +// Test # 1 : No Input Arguments +exec('./allpasslp2xn.sci',-1); +[n,d]=allpasslp2xn(); +//!--error 10000 +//Number of input arguments should either 2 or 3 +//at line 30 of function allpasslp2xn called by : +//[n,d] = allpasslp2xn() diff --git a/DSP functions/allpasslp2xn/test_2.sce b/DSP functions/allpasslp2xn/test_2.sce new file mode 100644 index 0000000..0bf4077 --- /dev/null +++ b/DSP functions/allpasslp2xn/test_2.sce @@ -0,0 +1,7 @@ +// Test # 2 : Excess Input Arguments +exec('./allpasslp2xn.sci',-1); +[n,d]=allpasslp2xn(0.3,0.7,'pass',0.9); +//!--error 10000 +//Number of input arguments should either 2 or 3 +//at line 30 of function allpasslp2xn called by : +//[n,d]=allpasslp2xn(0.3,0.7,'pass',0.9) diff --git a/DSP functions/allpasslp2xn/test_3.sce b/DSP functions/allpasslp2xn/test_3.sce new file mode 100644 index 0000000..132af33 --- /dev/null +++ b/DSP functions/allpasslp2xn/test_3.sce @@ -0,0 +1,5 @@ +// Test # 3 : Incorrect number of output Arguments +exec('./allpasslp2xn.sci',-1); +[n,d,e]=allpasslp2xn([0.1,0.2],[0.4,.76]); +//!--error 59 +//Wrong number of output arguments diff --git a/DSP functions/allpasslp2xn/test_4.sce b/DSP functions/allpasslp2xn/test_4.sce new file mode 100644 index 0000000..779532c --- /dev/null +++ b/DSP functions/allpasslp2xn/test_4.sce @@ -0,0 +1,7 @@ +// Test #4 : Input Argument #1 or #2 is of complex type +exec('./allpasslp2xn.sci',-1); +[n,d]=allpasslp2xn([0.33 0.4],[%i,0.5]); +//!--error 10000 +//Wt must be vector and real +//at line 29 of function allpasslp2xn called by : +//[n,d]=allpasslp2xn([0.33 0.4],[%i,0.5]); diff --git a/DSP functions/allpasslp2xn/test_5.sce b/DSP functions/allpasslp2xn/test_5.sce new file mode 100644 index 0000000..73d9dbc --- /dev/null +++ b/DSP functions/allpasslp2xn/test_5.sce @@ -0,0 +1,7 @@ +// Test #5 : Input Argument #1 or #2 range test +exec('./allpasslp2xn.sci',-1); +[n,d]=allpasslp2xn([1.1,0.9],[0.3,0.8]); +//!--error 10000 +//Wo must be in normalised +//at line 19 of function allpasslp2xn called by : +//[n,d]=allpasslp2xn([1.1,0.9],[0.3,0.8]); diff --git a/DSP functions/allpasslp2xn/test_6.sce b/DSP functions/allpasslp2xn/test_6.sce new file mode 100644 index 0000000..2016c34 --- /dev/null +++ b/DSP functions/allpasslp2xn/test_6.sce @@ -0,0 +1,7 @@ +// Test #6 : Invalid flag test +exec('./allpasslp2xn.sci',-1); +[n,d]=allpasslp2xn([0.4 0.6],[0.3,0.4],'j'); +//!--error 10000 +//Invalid option,input should be either pass or stop +//at line 60 of function allpasslp2xn called by : +//[n,d]=allpasslp2xn([0.4 0.6],[0.3,0.4],'j'); diff --git a/DSP functions/allpasslp2xn/test_7.sce b/DSP functions/allpasslp2xn/test_7.sce new file mode 100644 index 0000000..4f3b568 --- /dev/null +++ b/DSP functions/allpasslp2xn/test_7.sce @@ -0,0 +1,14 @@ +// Test # 7 : For 1 output argument +exec('./allpasslp2xn.sci',-1); +[n,d]=allpasslp2xn([0.2 0.5 0.7],[0.4,0.7,0.9],'pass'); +disp(d); +disp(n); +// +//Scilab Output +//d= 1. 0.4208078 -0.9021130 -0.2212317 +//n= 0.2212317 0.9021130 -0.4208078 -1. +// +//Matlab Output +//n= 0.2212 0.9021 -0.4208 -1.0000 +//d= 1.0000 0.4208 -0.9021 -0.2212 + diff --git a/DSP functions/allpasslp2xn/test_8.sce b/DSP functions/allpasslp2xn/test_8.sce new file mode 100644 index 0000000..c7e5f3a --- /dev/null +++ b/DSP functions/allpasslp2xn/test_8.sce @@ -0,0 +1,14 @@ +// Test #8 : For valid input case #1 +exec('./allpasslp2xn.sci',-1); +[n,d]=allpasslp2xn([0.2 0.5 0.7],[0.4,0.7,0.9],'pass'); +disp(d); +disp(n); +// +//Scilab Output +//d= 1. 0.4208078 -0.9021130 -0.2212317 +//n= 0.2212317 0.9021130 -0.4208078 -1. +// +//Matlab Output +//n= 0.2212 0.9021 -0.4208 -1.0000 +//d= 1.0000 0.4208 -0.9021 -0.2212 + diff --git a/DSP functions/allpasslp2xn/test_9.sce b/DSP functions/allpasslp2xn/test_9.sce new file mode 100644 index 0000000..3c78b63 --- /dev/null +++ b/DSP functions/allpasslp2xn/test_9.sce @@ -0,0 +1,13 @@ +// Test #9 : For valid input case #2 +exec('./allpasslp2xn.sci',-1); +[n,d]=allpasslp2xn([0.12 0.65 0.7],[0.4,0.9 0.97],'stop'); +disp(d); +disp(n); +// +//Scilab Output +//d=1. 2.5769939 2.1642515 0.5838982 +//n=0.5838982 2.1642515 2.5769939 1. +// +//Matlab Output +//n= 0.5839 2.1643 2.5770 1.0000 +//d= 1.0000 2.5770 2.1643 0.5839 diff --git a/DSP functions/allpassrateup/allpassrateup.sci b/DSP functions/allpassrateup/allpassrateup.sci new file mode 100644 index 0000000..8541d62 --- /dev/null +++ b/DSP functions/allpassrateup/allpassrateup.sci @@ -0,0 +1,44 @@ +function [AllpassNum,AllpassDen] = allpassrateup(N) +// Allpass filter for integer upsample transformation +// +//Calling Sequence: +//[AllpassNum,AllpassDen] = allpassrateup(N) returns the numerator, AllpassNum, and the denominator, AllpassDen, of the Nth-order allpass mapping filter for performing the rateup frequency transformation, which creates N equal replicas of the prototype filter frequency response. +// +//Input Parameters: +// N: Upsampling ratio +// +//Output Parameters: +// AllpassNum: Numerator of mapping filer +// AllpassDen: Denominator of mapping filter +//Example: Design the allpass filter creating the effect of upsampling the digital filter four times: +// +// N = 4; +// Wo = 0.2; Wt = Wo/N + 2*[0:N-1]/N; +// [AllpassNum, AllpassDen] = allpassrateup(N) +// +//Author: Shrenik Nambiar +// +//References: 1. Constantinides, A.G., "Spectral transformations for digital filters," IEEE® Proceedings, vol. 117, no. 8, pp. 1585-1590, August 1970. +// +// Input Validation Statements + if argn(2) ~=1 then + error("Number of input arguments should be 1"); + end + + if argn(1) <1 |argn(1)>2 then + error("Number of output arguments should either be 1 or 2"); + end + + if ~isscalar(N) | ~isreal(N) | N<0 then + error("N must be real and positive scalar"); + end + + if round(N)~=N & type(N) ~=8 then + error("N must be an integer"); + end + +//Calculating the numerator and denominator for the mapping filter + AllpassDen = [1 zeros(1,N)]; + AllpassNum = [zeros(1,N) 1]; + +endfunction diff --git a/DSP functions/allpassrateup/test_1.sce b/DSP functions/allpassrateup/test_1.sce new file mode 100644 index 0000000..b9501de --- /dev/null +++ b/DSP functions/allpassrateup/test_1.sce @@ -0,0 +1,7 @@ +// Test # 1 : No Input Arguments +exec('./allpassrateup.sci',-1); +[n,d]=allpassrateup(); +//!--error 10000 +//Number of input arguments should be 1 +//at line 25 of function allpassrateup called by : +//[n,d]=allpassrateup(); diff --git a/DSP functions/allpassrateup/test_2.sce b/DSP functions/allpassrateup/test_2.sce new file mode 100644 index 0000000..e6b608a --- /dev/null +++ b/DSP functions/allpassrateup/test_2.sce @@ -0,0 +1,5 @@ +// Test # 2 : Excess Input Arguments +exec('./allpassrateup.sci',-1); +[n,d]=allpassrateup(2,4); +//!--error 58 +//Wrong number of input arguments diff --git a/DSP functions/allpassrateup/test_3.sce b/DSP functions/allpassrateup/test_3.sce new file mode 100644 index 0000000..c2f3e76 --- /dev/null +++ b/DSP functions/allpassrateup/test_3.sce @@ -0,0 +1,5 @@ +// Test # 3 : Incorrect number of output Arguments +exec('./allpassrateup.sci',-1); +[n,d,e]=allpassrateup(3,7); +//!--error 59 +//Wrong number of output arguments diff --git a/DSP functions/allpassrateup/test_4.sce b/DSP functions/allpassrateup/test_4.sce new file mode 100644 index 0000000..cd5422a --- /dev/null +++ b/DSP functions/allpassrateup/test_4.sce @@ -0,0 +1,7 @@ +// Test # 4 : Input Argument #1 is of complex type +exec('./allpassrateup.sci',-1); +[n,d]=allpassrateup(%i); +//!--error 10000 +//N must be real and positive scalar +//at line 33 of function allpassrateup called by : +//[n,d]=allpassrateup(%i); diff --git a/DSP functions/allpassrateup/test_5.sce b/DSP functions/allpassrateup/test_5.sce new file mode 100644 index 0000000..4052b5e --- /dev/null +++ b/DSP functions/allpassrateup/test_5.sce @@ -0,0 +1,10 @@ +// Test #5 :For 1 output argument +exec('./allpassrateup.sci',-1); +[n]=allpassrateup(8); +disp(n); +// +//Scilab Output +//n= 0. 0. 0. 0. 0. 0. 0. 0. 1. +// +//Matlab Output +//n= 0 0 0 0 0 0 0 0 1 diff --git a/DSP functions/allpassrateup/test_6.sce b/DSP functions/allpassrateup/test_6.sce new file mode 100644 index 0000000..a1ad743 --- /dev/null +++ b/DSP functions/allpassrateup/test_6.sce @@ -0,0 +1,6 @@ +// Test #5 :For input of type double +exec('./allpassrateup.sci',-1); +[n,d]=allpassrateup(4.8); +//N must be an integer +//at line 37 of function allpassrateup called by : +//[n,d]=allpassrateup(4.8); diff --git a/DSP functions/allpassrateup/test_7.sce b/DSP functions/allpassrateup/test_7.sce new file mode 100644 index 0000000..cb7543c --- /dev/null +++ b/DSP functions/allpassrateup/test_7.sce @@ -0,0 +1,13 @@ +// Test # 12 : Valid inputs +exec('./allpassrateup.sci',-1); +[n,d]=allpassrateup(4); +disp(d); +disp(n); +// +//Scilab Output +//d= 1. 0. 0. 0. 0. +//n= 0. 0. 0. 0. 1. +// +//Matlab Output +//n= 0 0 0 0 1 +//d= 1 0 0 0 0 diff --git a/DSP functions/allpassshift/allpassshift.sci b/DSP functions/allpassshift/allpassshift.sci new file mode 100644 index 0000000..5491e88 --- /dev/null +++ b/DSP functions/allpassshift/allpassshift.sci @@ -0,0 +1,57 @@ +function [AllpassNum,AllpassDen] = allpassshift(Wo,Wt) +// Allpass filter for real shift transformation +// +//Calling Sequence: +//[AllpassNum,AllpassDen] = allpassshift(Wo,Wt) returns the numerator, AllpassNum, and the denominator, AllpassDen, of the second-order allpass mapping filter for performing a real frequency shift transformation. This transformation places one selected feature of an original filter, located at frequency Wo, at the required target frequency location, Wt. 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 Wo and 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 filter precisely shifting one feature of the lowpass filter originally at Wo=0.76 to the new frequencies of Wt=0.5: +// +// Wo = 0.76; Wt = 0.5; +// [AllpassNum, AllpassDen] = allpassshift(Wo, Wt) +// +//Author: Shrenik Nambiar +// +//References: 1. Constantinides, A.G., "Spectral transformations for digital filters," IEEE® Proceedings, vol. 117, no. 8, pp. 1585-1590, August 1970. +// +// 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 be 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 ~isscalar(Wt) | ~isreal(Wt) then + error("Wt must be real,numeric and scalar"); + end + if Wt<=0 | Wt>=1 then + error("Wt must lie between 0 and 1"); + end + +//Calculating the numerator and denominator for the mapping filter + be = cos(%pi*(Wo/2-Wt)); + if abs(be) < 1.0, + be = be/ cos(%pi*Wo/2); + else + be = sin(%pi*(Wo/2-Wt)) / sin(%pi*Wo/2); + end + + AllpassDen = [1 -be 0]; + AllpassNum = [0 be -1]; + +endfunction diff --git a/DSP functions/allpassshift/test_1.sce b/DSP functions/allpassshift/test_1.sce new file mode 100644 index 0000000..41ad768 --- /dev/null +++ b/DSP functions/allpassshift/test_1.sce @@ -0,0 +1,7 @@ +// Test # 1 : No Input Arguments +exec('./allpassshift.sci',-1); +[n,d]=allpassshift(); +//!--error 10000 +//Number of input arguments should be 2 +//at line 25 of function allpassshift called by : +//[n,d]=allpassshift(); diff --git a/DSP functions/allpassshift/test_10.sce b/DSP functions/allpassshift/test_10.sce new file mode 100644 index 0000000..9ccbd36 --- /dev/null +++ b/DSP functions/allpassshift/test_10.sce @@ -0,0 +1,7 @@ +// Test # 10 : Input Argument #2 length +exec('./allpassshift.sci',-1); +[n,d]=allpassshift(0.2,[0.1,0.9]); +//!--error 10000 +//Wt must be real,numeric and scalar +//at line 40 of function allpassshift called by : +//[n,d]=allpassshift(0.2,[0.1,0.9]); diff --git a/DSP functions/allpassshift/test_11.sce b/DSP functions/allpassshift/test_11.sce new file mode 100644 index 0000000..69e1b13 --- /dev/null +++ b/DSP functions/allpassshift/test_11.sce @@ -0,0 +1,10 @@ +// Test # 11 : For 1 output argument +exec('./allpassshift.sci',-1); +[n]=allpassshift(0.28,0.683); +disp(n); +// +//Scilab Output +//n= 0. - 0.1488439 - 1. + +//Matlab Output +//n= 0 -0.1488 -1.0000 diff --git a/DSP functions/allpassshift/test_12.sce b/DSP functions/allpassshift/test_12.sce new file mode 100644 index 0000000..afb5d6e --- /dev/null +++ b/DSP functions/allpassshift/test_12.sce @@ -0,0 +1,13 @@ +// Test # 12 : Valid input test case #1 +exec('./allpassshift.sci',-1); +[n,d]=allpassshift(0.4541,0.7584); +disp(d); +disp(n); +// +//Scilab Output +//d= 1. 0.1300301 0. +//n =0. - 0.1300301 - 1. +// +//Matlab Output +//d= 1.0000 0.1300 0 +//n= 0 -0.1300 -1.0000 diff --git a/DSP functions/allpassshift/test_13.sce b/DSP functions/allpassshift/test_13.sce new file mode 100644 index 0000000..e95bf5e --- /dev/null +++ b/DSP functions/allpassshift/test_13.sce @@ -0,0 +1,13 @@ +// Test # 13 : Valid input test case #2 +exec('./allpassshift.sci',-1); +[n,d]=allpassshift(0.561,0.177); +disp(d); +disp(n); +// +//Scilab Output +//d=1. -1.4894406 0. +//n=0. 1.4894406 -1. +// +//Matlab Output +//d=1.0000 -1.4894 0 +//n=0 1.4894 -1.0000 diff --git a/DSP functions/allpassshift/test_2.sce b/DSP functions/allpassshift/test_2.sce new file mode 100644 index 0000000..16510da --- /dev/null +++ b/DSP functions/allpassshift/test_2.sce @@ -0,0 +1,5 @@ +// Test # 2 : Excess Input Arguments +exec('./allpassshift.sci',-1); +[n,d]=allpassshift(0.2,0.4,0.6); +//!--error 58 +//Wrong number of input arguments diff --git a/DSP functions/allpassshift/test_3.sce b/DSP functions/allpassshift/test_3.sce new file mode 100644 index 0000000..9db2d85 --- /dev/null +++ b/DSP functions/allpassshift/test_3.sce @@ -0,0 +1,5 @@ +// Test # 3 : Incorrect number of output Arguments +exec('./allpassshift.sci',-1); +[n,d,e]=allpassshift(0.3,0.7); +//!--error 59 +//Wrong number of output arguments diff --git a/DSP functions/allpassshift/test_4.sce b/DSP functions/allpassshift/test_4.sce new file mode 100644 index 0000000..8670868 --- /dev/null +++ b/DSP functions/allpassshift/test_4.sce @@ -0,0 +1,7 @@ +// Test # 4 : Input Argument #1 is of complex type +exec('./allpassshift.sci',-1); +[n,d]=allpassshift(%i,0.6); +//!--error 10000 +//Wo must be real ,numeric and scalar +//at line 33 of function allpassshift called by : +//[n,d]=allpassshift(%i,0.6); diff --git a/DSP functions/allpassshift/test_5.sce b/DSP functions/allpassshift/test_5.sce new file mode 100644 index 0000000..9b78b55 --- /dev/null +++ b/DSP functions/allpassshift/test_5.sce @@ -0,0 +1,7 @@ +// Test # 5 : Input Argument #2 is of complex type +exec('./allpassshift.sci',-1); +[n,d]=allpassshift(0.1,%i); +//!--error 10000 +//Wt must be real,numeric and scalar +//at line 40 of function allpassshift called by : +//[n,d]=allpassshift(0.1,%i); diff --git a/DSP functions/allpassshift/test_6.sce b/DSP functions/allpassshift/test_6.sce new file mode 100644 index 0000000..5ce1160 --- /dev/null +++ b/DSP functions/allpassshift/test_6.sce @@ -0,0 +1,7 @@ +// Test # 6 : Input Argument #1 range test +exec('./allpassshift.sci',-1); +[n,d]=allpassshift(3,0.4); +//!--error 10000 +//Wo must lie between 0 and 1 +//at line 36 of function allpassshift called by : +//[n,d]=allpassshift(3,0.4); diff --git a/DSP functions/allpassshift/test_7.sce b/DSP functions/allpassshift/test_7.sce new file mode 100644 index 0000000..bfebccc --- /dev/null +++ b/DSP functions/allpassshift/test_7.sce @@ -0,0 +1,7 @@ +// Test # 7 : Input Argument #2 range test +exec('./allpassshift.sci',-1); +[n,d]=allpassshift(0.6,3.1); +//!--error 10000 +//Wt must lie between 0 and 1 +//at line 43 of function allpassshift called by : +//[n,d]=allpassshift(0.6,3.1); diff --git a/DSP functions/allpassshift/test_8.sce b/DSP functions/allpassshift/test_8.sce new file mode 100644 index 0000000..e9cca23 --- /dev/null +++ b/DSP functions/allpassshift/test_8.sce @@ -0,0 +1,7 @@ +// Test # 8 : For zero valued inputs +exec('./allpassshift.sci',-1); +[n,d]=allpassshift(0,0); +// !--error 10000 +//Wo must lie between 0 and 1 +//at line 36 of function allpassshift called by : +//[n,d]=allpassshift(0,0); diff --git a/DSP functions/allpassshift/test_9.sce b/DSP functions/allpassshift/test_9.sce new file mode 100644 index 0000000..6becac8 --- /dev/null +++ b/DSP functions/allpassshift/test_9.sce @@ -0,0 +1,7 @@ +// Test # 9 : Input Argument #1 length +exec('./allpassshift.sci',-1); +[n,d]=allpassshift([0.3,0.2],0.6); +//!--error 10000 +//Wo must be real ,numeric and scalar +//at line 33 of function allpassshift called by : +//[n,d]=allpassshift([0.3,0.2],0.6); diff --git a/DSP functions/allpassshiftc/allpassshiftc.sci b/DSP functions/allpassshiftc/allpassshiftc.sci new file mode 100644 index 0000000..99a22bf --- /dev/null +++ b/DSP functions/allpassshiftc/allpassshiftc.sci @@ -0,0 +1,53 @@ +function [AllpassNum,AllpassDen] = allpassshiftc(Wo,Wt) +// Allpass filter for complex shift transformation +// +//Calling Sequence: +//[AllpassNum,AllpassDen] = allpassshiftc(Wo,Wt) returns the numerator, AllpassNum, and denominator, AllpassDen, vectors of the allpass mapping filter for performing a complex frequency shift of the frequency response of the digital filter by an arbitrary amount. +// +//[AllpassNum,AllpassDen] = allpassshiftc(0,0.5) calculates the allpass filter for doing the Hilbert transformation, a 90 degree counterclockwise rotation of an original filter in the frequency domain. +// +//[AllpassNum,AllpassDen] = allpassshiftc(0,-0.5) calculates the allpass filter for doing an inverse Hilbert transformation, i.e. a 90 degree clockwise rotation of an original filter in the frequency domain. +//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 filter precisely shifting one feature of the lowpass filter originally at Wo=0.76 to the new frequencies of Wt=0.5: +// +// Wo = 0.76; Wt = 0.5; +// [AllpassNum, AllpassDen] = allpassshiftc(Wo, Wt) +// +//Author: Shrenik Nambiar +// +//References: 1. Constantinides, A.G., "Spectral transformations for digital filters," IEEE® Proceedings, vol. 117, no. 8, pp. 1585-1590, August 1970. +// +// 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 be 2"); + end + + if ~isscalar(Wo) | ~isreal(Wo) then + error("Wo must be real ,numeric and scalar"); + end + if Wo<=-1 | Wo>=1 then + error("Wo must lie between -1 and 1"); + end + + if ~isscalar(Wt) | ~isreal(Wt) then + error("Wt must be real,numeric and scalar "); + end + if Wt<=-1 | Wt>=1 then + error("Wt must lie between -1 and 1"); + end + +//Calculating the numerator and denominator for the mapping filter + AllpassNum = [0 1]*exp(%pi*%i*(Wt-Wo)); + AllpassDen = [1 0]; + +endfunction diff --git a/DSP functions/allpassshiftc/test_1.sce b/DSP functions/allpassshiftc/test_1.sce new file mode 100644 index 0000000..365ab3e --- /dev/null +++ b/DSP functions/allpassshiftc/test_1.sce @@ -0,0 +1,7 @@ +// Test # 1 : No Input Arguments +exec('./allpassshiftc.sci',-1); +[n,d]=allpassshiftc(); +//!--error 10000 +//Number of input arguments should be 2 +//at line 28 of function allpassshiftc called by : +//[n,d]=allpassshiftc(); diff --git a/DSP functions/allpassshiftc/test_10.sce b/DSP functions/allpassshiftc/test_10.sce new file mode 100644 index 0000000..0b6f154 --- /dev/null +++ b/DSP functions/allpassshiftc/test_10.sce @@ -0,0 +1,7 @@ +// Test # 10 : Input Argument #2 length +exec('./allpassshiftc.sci',-1); +[n,d]=allpassshiftc(0.1,[0.4,0.5]); +//!--error 10000 +//Wt must be real,numeric and scalar +//at line 43 of function allpassshiftc called by : +//[n,d]=allpassshiftc(0.1,[0.4,0.5]); diff --git a/DSP functions/allpassshiftc/test_11.sce b/DSP functions/allpassshiftc/test_11.sce new file mode 100644 index 0000000..bc7064a --- /dev/null +++ b/DSP functions/allpassshiftc/test_11.sce @@ -0,0 +1,10 @@ +// Test # 11 : For 1 output argument +exec('./allpassshiftc.sci',-1); +[n]=allpassshiftc(0.458,0.583); +disp(n); +// +//Scilab Output +//n=0 0.9238795 + 0.3826834i +// +//Matlab Output +//n=0.0000 + 0.0000i 0.9239 + 0.3827i diff --git a/DSP functions/allpassshiftc/test_12.sce b/DSP functions/allpassshiftc/test_12.sce new file mode 100644 index 0000000..13621a1 --- /dev/null +++ b/DSP functions/allpassshiftc/test_12.sce @@ -0,0 +1,13 @@ +// Test # 12 : Valid input test case #1 +exec('./allpassshiftc.sci',-1); +[n,d]=allpassshiftc(0.2541,0.454); +disp(d); +disp(n); +// +//Scilab Output +//d= 1. 0. +//n= 0 0.8092016 + 0.5875311i +// +//Matlab Output +//d= 1 0 +//n= 0.0000 + 0.0000i 0.8092 + 0.5875i diff --git a/DSP functions/allpassshiftc/test_13.sce b/DSP functions/allpassshiftc/test_13.sce new file mode 100644 index 0000000..a59939c --- /dev/null +++ b/DSP functions/allpassshiftc/test_13.sce @@ -0,0 +1,13 @@ +// Test # 13 : Valid input test case #2 +exec('./allpassshiftc.sci',-1); +[n,d]=allpassshiftc(0.861,0.546); +disp(d); +disp(n); +// +//Scilab Output +//d=1. 0. +//n= 0 0.5490228 - 0.8358074i +// +//Matlab Output +//d = 1 0 +//n = 0.0000 + 0.0000i 0.5490 - 0.8358i diff --git a/DSP functions/allpassshiftc/test_14.sce b/DSP functions/allpassshiftc/test_14.sce new file mode 100644 index 0000000..f7dcf0c --- /dev/null +++ b/DSP functions/allpassshiftc/test_14.sce @@ -0,0 +1,13 @@ +// Test # 13 : Valid input test case #3 +exec('./allpassshiftc.sci',-1); +[n,d]=allpassshiftc(-0.261,-0.346); +disp(d); +disp(n); +// +//Scilab Output +//d=1. 0. +//n=0 0.9645574 - 0.2638730i +// +//Matlab Output +//d=1 0 +//n=0.0000 + 0.0000i 0.9646 - 0.2639i diff --git a/DSP functions/allpassshiftc/test_2.sce b/DSP functions/allpassshiftc/test_2.sce new file mode 100644 index 0000000..eeb2621 --- /dev/null +++ b/DSP functions/allpassshiftc/test_2.sce @@ -0,0 +1,5 @@ +// Test # 2 : Excess Input Arguments +exec('./allpassshiftc.sci',-1); +[n,d]=allpassshiftc(0.3,0.24,0.16); +//!--error 58 +//Wrong number of input arguments diff --git a/DSP functions/allpassshiftc/test_3.sce b/DSP functions/allpassshiftc/test_3.sce new file mode 100644 index 0000000..a6c4340 --- /dev/null +++ b/DSP functions/allpassshiftc/test_3.sce @@ -0,0 +1,5 @@ +// Test # 3 : Incorrect number of output Arguments +exec('./allpassshiftc.sci',-1); +[n,d,e]=allpassshiftc(0.12,0.27); +//!--error 59 +//Wrong number of output arguments diff --git a/DSP functions/allpassshiftc/test_4.sce b/DSP functions/allpassshiftc/test_4.sce new file mode 100644 index 0000000..a81c8ec --- /dev/null +++ b/DSP functions/allpassshiftc/test_4.sce @@ -0,0 +1,7 @@ +// Test # 4 : Input Argument #1 is of complex type +exec('./allpassshiftc.sci',-1); +[n,d]=allpassshiftc(%i,0.2); +//!--error 10000 +//Wo must be real ,numeric and scalar +//at line 36 of function allpassshiftc called by : +//[n,d]=allpassshiftc(%i,0.2); diff --git a/DSP functions/allpassshiftc/test_5.sce b/DSP functions/allpassshiftc/test_5.sce new file mode 100644 index 0000000..f5a55ec --- /dev/null +++ b/DSP functions/allpassshiftc/test_5.sce @@ -0,0 +1,7 @@ +// Test # 5 : Input Argument #2 is of complex type +exec('./allpassshiftc.sci',-1); +[n,d]=allpassshiftc(0.4,%i); +//!--error 10000 +//Wt must be real,numeric and scalar +//at line 43 of function allpassshiftc called by : +//[n,d]=allpassshiftc(0.4,%i); diff --git a/DSP functions/allpassshiftc/test_6.sce b/DSP functions/allpassshiftc/test_6.sce new file mode 100644 index 0000000..ec1639e --- /dev/null +++ b/DSP functions/allpassshiftc/test_6.sce @@ -0,0 +1,7 @@ +// Test # 6 : Input Argument #1 range test +exec('./allpassshiftc.sci',-1); +[n,d]=allpassshiftc(6,0.4); +//!--error 10000 +//Wo must lie between -1 and 1 +//at line 39 of function allpassshiftc called by : +//[n,d]=allpassshiftc(6,0.4); diff --git a/DSP functions/allpassshiftc/test_7.sce b/DSP functions/allpassshiftc/test_7.sce new file mode 100644 index 0000000..c05c71b --- /dev/null +++ b/DSP functions/allpassshiftc/test_7.sce @@ -0,0 +1,7 @@ +// Test # 7 : Input Argument #2 range test +exec('./allpassshiftc.sci',-1); +[n,d]=allpassshiftc(0.2,53); +//!--error 10000 +//Wt must lie between -1 and 1 +//at line 46 of function allpassshiftc called by : +//[n,d]=allpassshiftc(0.2,53); diff --git a/DSP functions/allpassshiftc/test_8.sce b/DSP functions/allpassshiftc/test_8.sce new file mode 100644 index 0000000..261b273 --- /dev/null +++ b/DSP functions/allpassshiftc/test_8.sce @@ -0,0 +1,13 @@ +// Test # 13 : For zero valued inputs +exec('./allpassshiftc.sci',-1); +[n,d]=allpassshiftc(0,0); +disp(d); +disp(n); +// +//Scilab Output +//d=1. 0. +//n= 0 1. +// +//Matlab Output +//d= 1 0 +//n = 0 1 diff --git a/DSP functions/allpassshiftc/test_9.sce b/DSP functions/allpassshiftc/test_9.sce new file mode 100644 index 0000000..fb4a957 --- /dev/null +++ b/DSP functions/allpassshiftc/test_9.sce @@ -0,0 +1,7 @@ +// Test # 9 : Input Argument #1 length +exec('./allpassshiftc.sci',-1); +[n,d]=allpassshiftc([0.2,0.7],0.5); +//!--error 10000 +//Wo must be real ,numeric and scalar +//at line 36 of function allpassshiftc called by : +//[n,d]=allpassshiftc([0.2,0.7],0.5); diff --git a/DSP functions/iirpowcomp/iirpowcomp.sci b/DSP functions/iirpowcomp/iirpowcomp.sci new file mode 100644 index 0000000..9f77244 --- /dev/null +++ b/DSP functions/iirpowcomp/iirpowcomp.sci @@ -0,0 +1,108 @@ +function [bp,a]= iirpowcomp(b,a,varargin) +//Power complementary IIR filter +//Calling Sequences +// +//[bp,ap] = iirpowcomp(b,a) returns the coefficients of the power complementary IIR filter g(z) = bp(z)/ap(z) in vectors bp and ap, given the coefficients of the IIR filter h(z) = b(z)/a(z) in vectors b and a. b must be symmetric (Hermitian) or antisymmetric (antihermitian) and of the same length as a. +// +//[bp,ap] = iirpowcomp(b,a,c) where c is a complex scalar of unity magnitude, forces bp to satisfy the generalized hermitian property: +//conj(bp(end:-1:1)) = c*bp. +//When c is omitted, the function chooses c as follows: +//When b is real, the function chooses c as 1 or -1, whichever yields bp as real. +//When b is complex, c defaults to 1. +// +//Input Parameters: +// b: Coefficients of numerator of the IIR filter +// a: Coefficients of denominator of the IIR filter +// c: Complex scalar of unit magnitude +// +//Output Parameters +// bp: Coefficients of the numerator of the power complementary IIR filter +// ap: Coefficients of the denominator of the power complementary IIR filter +// +//Example: +// [b,a]=cheby1(10,.5,.4); +// [bp,ap]=iirpowcomp(b,a); +// [xm,fr]=frmag(bp,ap,256); +// plot(fr,xm); +// +//Author: Shrenik Nambiar +// +// Input validation statements +// + if argn(2)<2 | argn(2)>3 then + error("2/3 input arguments allowed"); + end + + if argn(1)~=2 then + error("The number of output arguments should be 2"); + end + + if ~(or(size(b)==1) | or(size(a)==1)) then + error("size of either b or a must not be 1"); + end + + if length(b)~=length(a) then + error("Both the vectors must be of equal length"); + end + + n= length(b)-1; //order of the numerator +//Converting both the vectors to row vectors + b=b(:).' ; + a=a(:).' ; + + if n<1 then + error("Order should be greater than 1 "); + end +// Reversed conjugated polynomial of b and a by replacing z with z^(-1) and conjugating the coefficients + rb= conj(b($:-1:1)); + ra= conj(a($:-1:1)); + + r= conv(rb,b)-conv(a,ra); + +// Computing the numerator of the power complementary filter + + if isreal(b) & argn(2)==2 then + bp= recursion(r,n,1); + if ~isreal(bp) then + bp=recursion(r,n,-1); + end + if ~isreal(bp) then + error("Filter type 4"); + end + else + + + if argn(2)==3 then + c=varargin(1); + if max(size(c))>1 then + error(warning("c must be scalar")); + end + if abs(c)-1 > %eps^(2/3) then + error(warning("Filter error")); + end + end + + bp= recursion(r,n,c); + end + +endfunction + +function [bp]= recursion(r,n,c) +// Computes the numerator q of the power complementary transfer function needed to compute the allpass decomposition. + bp=zeros(1,n+1); + bp(1)= sqrt(-r(1)./c); + bp(n+1)= conj(c*bp(1)); + bp(2)= -r(2)./(2*c*bp(1)); + bp(n)= conj(c*bp(2)); + + for i= 3:ceil(n/2) + bp(i)= (-r(i)./c - bp(2:i-1)*bp(i-1:-1:2).')./(2*bp(1)); + bp(n+2-i)= conj(c*bp(i)); + end + +// Compute middle coefficient separately when order is even + + if round(n/2) ==n/2 then + bp((n+2)/2)= (-r((n+2)/2)./c - bp(2:(n+2)/2 -1)*bp((n+2)/2 -1:-1:2).')./(2*bp(1)); + end +endfunction diff --git a/DSP functions/iirpowcomp/test_1.sce b/DSP functions/iirpowcomp/test_1.sce new file mode 100644 index 0000000..8d5d484 --- /dev/null +++ b/DSP functions/iirpowcomp/test_1.sce @@ -0,0 +1,7 @@ +// Test # 1 : No Input Arguments +exec('./iirpowcomp.sci',-1); +[b,p]=iirpowcomp(); +//!--error 10000 +//2/3 input arguments allowed +//at line 33 of function iirpowcomp called by : +//[b,p]=iirpowcomp() diff --git a/DSP functions/iirpowcomp/test_2.sce b/DSP functions/iirpowcomp/test_2.sce new file mode 100644 index 0000000..e24eea8 --- /dev/null +++ b/DSP functions/iirpowcomp/test_2.sce @@ -0,0 +1,7 @@ +// Test #2 : Excess Input Arguments +exec('./iirpowcomp.sci',-1); +[b,p]=iirpowcomp(3.33,0.444,90,9); +//!--error 10000 +//2/3 input arguments allowed +//at line 33 of function iirpowcomp called by : +//[b,p]=iirpowcomp(3.33,0.444,90,9) diff --git a/DSP functions/iirpowcomp/test_3.sce b/DSP functions/iirpowcomp/test_3.sce new file mode 100644 index 0000000..523e0b5 --- /dev/null +++ b/DSP functions/iirpowcomp/test_3.sce @@ -0,0 +1,6 @@ +// Test #3 : Incorect output Arguments +exec('./iirpowcomp.sci',-1); +[b,p,s]=iirpowcomp(3.2,3.4,%i); +//!--error 10000 +//!--error 59 +//Wrong number of output arguments. diff --git a/DSP functions/iirpowcomp/test_4.sce b/DSP functions/iirpowcomp/test_4.sce new file mode 100644 index 0000000..d93d2c5 --- /dev/null +++ b/DSP functions/iirpowcomp/test_4.sce @@ -0,0 +1,11 @@ +// Test #4 : For less number of output arguments +exec('./iirpowcomp.sci',-1); +b=iirpowcomp([3.3 0.43],[1.21 0.12]; +disp(b); +// +//Scilab Output +//b=- 4.2513585 +// 4.2513585 +// +//Matlab Output +//b= -4.2514 4.2514 diff --git a/DSP functions/iirpowcomp/test_5.sce b/DSP functions/iirpowcomp/test_5.sce new file mode 100644 index 0000000..358f5d3 --- /dev/null +++ b/DSP functions/iirpowcomp/test_5.sce @@ -0,0 +1,14 @@ +// Test #5 : Valid Input Arguments +exec('./iirpowcomp.sci',-1); +[b,p]=iirpowcomp([3.3 0.43],[1.21 0.12]; +disp(a); +disp(b); +// +//Scilab Output +//a=1.21 0.12 +//b=- 4.2513585 +// 4.2513585 +// +//Matlab Output +//b= -4.2514 4.2514 +//a= 1.2100 0.1200 diff --git a/DSP functions/iirpowcomp/test_6.sce b/DSP functions/iirpowcomp/test_6.sce new file mode 100644 index 0000000..8be6d24 --- /dev/null +++ b/DSP functions/iirpowcomp/test_6.sce @@ -0,0 +1,13 @@ +// Test #6 : Valid Input Arguments #2 +exec('./iirpowcomp.sci',-1); +[b,a]=iirpowcomp([0.0916,0.2749,0.2749,0.0916],[1.0000,-0.7601,0.7021,-0.2088]) +disp(a); +disp(b); +//Scilab Output +// +//a= 1. -0.7601 0.7021 -0.2088 +//b= 0.4660371 -0.8695094 0.8695094 -0.4660371 +// +//Matlab Output +//b = 0.4661 -0.8695 0.8695 -0.4661 +//a = 1.0000 -0.7601 0.7021 -0.2088 diff --git a/DSP functions/iirpowcomp/test_7.sce b/DSP functions/iirpowcomp/test_7.sce new file mode 100644 index 0000000..272eb3c --- /dev/null +++ b/DSP functions/iirpowcomp/test_7.sce @@ -0,0 +1,19 @@ +// Test #7 : Valid Input Arguments #3 with 3 inputs +exec('./iirpowcomp.sci',-1); +[b,a]=iirpowcomp([0.0916,0.2749,0.2749,0.0916],[1.0000,-0.7601,0.7021,-0.2088],%i) +disp(a); +disp(b); +//Scilab Output +// +//a= 1. - 0.7601 0.7021 - 0.2088 +//b= 0.3295380 + 0.3295380i +// - 0.6148360 - 0.6148360i +// 0.6148360 + 0.6148360i +// - 0.3295380 - 0.3295380i +// +//Matlab Output +//b =0.3295 + 0.3295i +// -0.6148 - 0.6148i +// 0.6148 + 0.6148i +// -0.3295 - 0.3295i +//a = 1.0000 -0.7601 0.7021 -0.2088 diff --git a/DSP functions/tf2ca/test_1.sce b/DSP functions/tf2ca/test_1.sce new file mode 100644 index 0000000..db4fc99 --- /dev/null +++ b/DSP functions/tf2ca/test_1.sce @@ -0,0 +1,7 @@ +// Test # 1 : No Input Arguments +exec('./tf2ca.sci',-1); +[d1,d2,b]=tf2ca(); +//!--error 10000 +//Only 2 input arguments allowed +//at line 37 of function tf2ca called by : +//[d1,d2,b]=tf2ca(); diff --git a/DSP functions/tf2ca/test_2.sce b/DSP functions/tf2ca/test_2.sce new file mode 100644 index 0000000..777fd3b --- /dev/null +++ b/DSP functions/tf2ca/test_2.sce @@ -0,0 +1,5 @@ +// Test # 1 : Excess Input Arguments +exec('./tf2ca.sci',-1); +[d1,d2,b]=tf2ca([0.1 0.5 0.1],[1 2 3],3); +//!--error 58 +//Wrong number of input arguments. diff --git a/DSP functions/tf2ca/test_3.sce b/DSP functions/tf2ca/test_3.sce new file mode 100644 index 0000000..ef43e5a --- /dev/null +++ b/DSP functions/tf2ca/test_3.sce @@ -0,0 +1,5 @@ +// Test # 3 : Excess output Arguments +exec('./tf2ca.sci',-1); +[d1,d2,b,c]=tf2ca([0.1 0.5 0.1],[1 2 3]); +//!--error 59 +//Wrong number of output arguments. diff --git a/DSP functions/tf2ca/test_4.sce b/DSP functions/tf2ca/test_4.sce new file mode 100644 index 0000000..fe30999 --- /dev/null +++ b/DSP functions/tf2ca/test_4.sce @@ -0,0 +1,7 @@ +// Test # 4 : When numerator is neither symmetric or anti-symmetric +exec('./tf2ca.sci',-1); +[d1,d2,b]=tf2ca([0.1 0.5 -0.1],[1 2 3]); +//!--error 10000 +//Numerator coeffcients must be either be symmetric or antisymmetric +//at line 71 of function tf2ca called by : +//[d1,d2,b]=tf2ca([0.1 0.5 -0.1],[1 2 3]) diff --git a/DSP functions/tf2ca/test_5.sce b/DSP functions/tf2ca/test_5.sce new file mode 100644 index 0000000..8329347 --- /dev/null +++ b/DSP functions/tf2ca/test_5.sce @@ -0,0 +1,16 @@ +// Test # 5 : Valid input case #1 +exec('./tf2ca.sci',-1); +[d1,d2,b]=tf2ca([0.1 0.5 0.1],[1 2.4 -33]); +disp(b); +disp(d2); +disp(d1); +// +//Scilab Output +//b= 0.0099450 - 0.2271061i +//d2=1. -0.5738043 + 0.0315922i +//d1=1. 0.5745561 + 0.0116049i +// +//Matlab Output +//d1= 1.0000 + 0.0000i 0.5746 + 0.0116i +//d2= 1.0000 + 0.0000i -0.5738 + 0.0316i +//b= 0.0099 - 0.2271i diff --git a/DSP functions/tf2ca/test_6.sce b/DSP functions/tf2ca/test_6.sce new file mode 100644 index 0000000..9a7adae --- /dev/null +++ b/DSP functions/tf2ca/test_6.sce @@ -0,0 +1,16 @@ +// Test # 6 : Valid input case #2 +exec('./tf2ca.sci',-1); +[d1,d2,b]=tf2ca([0.03 -0.5 -0.5 0.03],[1 2.4 -33 22]); +disp(b); +disp(d2); +disp(d1); +// +//Scilab Output +//b=1.7290007 + 0.4817393i +//d2= 1. -0.2593701 + 0.9083877i +//d1= 1. 0.7406299 - 0.9083877i -0.2593701 - 0.9083877i +// +//Matlab Output +//d1=1.0000 + 0.0000i 0.7406 - 0.9084i -0.2594 - 0.9084i +//d2=1.0000 + 0.0000i -0.2594 + 0.9084i +//b = 1.7290 + 0.4817i diff --git a/DSP functions/tf2ca/test_7.sce b/DSP functions/tf2ca/test_7.sce new file mode 100644 index 0000000..f8682f7 --- /dev/null +++ b/DSP functions/tf2ca/test_7.sce @@ -0,0 +1,7 @@ +// Test #7 : When either numerator or denominator have complex cefficients +exec('./tf2ca.sci',-1); +[d1,d2,b]=tf2ca([0.03 -0.5 -0.5 0.03],[1 2.4 -33*%i 22]); +//!--error 10000 +//Vectors must be real +//at line 56 of function tf2ca called by : +//[d1,d2,b]=tf2ca([0.03 -0.5 -0.5 0.03],[1 2.4 -33*%i 22] diff --git a/DSP functions/tf2ca/test_8.sce b/DSP functions/tf2ca/test_8.sce new file mode 100644 index 0000000..ee5dc63 --- /dev/null +++ b/DSP functions/tf2ca/test_8.sce @@ -0,0 +1,7 @@ +// Test #8: When numerator and denominator have differents lengths +exec('./tf2ca.sci',-1); +[d1,d2,b]=tf2ca([0.03 -0.5 -0.5 0.03],[1 2.4 -33); +//!--error 10000 +//Both the vectors must be of equal length +//at line 49 of function tf2ca called by : +//[d1,d2,b]=tf2ca([0.03 -0.5 -0.5 0.03],[1 2.4 -33] diff --git a/DSP functions/tf2ca/tf2ca.sci b/DSP functions/tf2ca/tf2ca.sci new file mode 100644 index 0000000..a2cc054 --- /dev/null +++ b/DSP functions/tf2ca/tf2ca.sci @@ -0,0 +1,133 @@ +function [d1,d2,be] = tf2ca(b,a) +// Transfer function to coupled allpass +// +//Calling Sequences +// +//[d1,d2] = tf2ca(b,a) where b is a real, symmetric vector of numerator coefficients and a is a real vector of denominator coefficients, corresponding to a stable digital filter, returns real vectors d1 and d2 containing the denominator coefficients of the allpass filters H1(z) and H2(z) +// +//[d1,d2] = tf2ca(b,a) where b is a real, antisymmetric vector of numerator coefficients and a is a real vector of denominator coefficients, corresponding to a stable digital filter, returns real vectors d1 and d2 containing the denominator coefficients of the allpass filters H1(z) and H2(z) such that +// +//H(z)=B(z)A(z)=(1/2)[H1(z)−H2(z)] +// +//[d1,d2,be] = tf2ca(b,a) returns complex vectors d1 and d2 containing the denominator coefficients of the allpass filters H1(z) and H2(z), and a complex scalar beta, satisfying |beta| = 1, such that +// +//H(z)=B(z)A(z)=(1/2)[β'*H1(z)+β*H2(z)] +// +//Input Parameters: +// b: Vector of numerator coefficients of the digital filters +// a: Vector of denominator coefficients of the digital filters +// +//Output Parameters: +// d1: Denominator coefficient of the all pass filter H1(z) +// d2: Denominator coefficient of the all pass filter H2(z) +// be: Complex Scalar +// +//Example: +// [b,a]=cheby1(9,.5,.4); +// [d1,d2]=tf2ca(b,a); +// num = 0.5*conv(fliplr(d1),d2)+0.5*conv(fliplr(d2),d1); +// den = conv(d1,d2); +// +//Author: Shrenik Nambiar +// +//References: S. K. Mitra, Digital Signal Processing, A Computer Based Approach, McGraw-Hill, N.Y., 1998 +// Input Validation Statements +// + if argn(2)~=2 then + error("Only 2 input arguments allowed"); + end + + if argn(1)<1 | argn(1)>3 then + error("The number of output arguments should be 1-3"); + end + + if ~(or(size(b)==1) & or(size(a)==1)) then + error("vectors must not be of size 1"); + end + + if length(b)~=length(a) then + error("Both the vectors must be of equal length"); + end +//Converting the vectors into row vectors + b=b(:).' ; + a=a(:).' ; + + if ~(isreal(b) & isreal(a)) then + error("Vectors must be real"); + end + + t= %eps^(2/3); //tolerance + +//To make sure the numerator is either symmetric or anti-symmetric + if max(abs(b- b($:-1:1))) <= t then + symm=1; + elseif max(abs(b+b($:-1:1))) <= t then + symm=2; + else + symm= 0; + end + + if symm==0 then + error("Numerator coeffcients must be either be symmetric or antisymmetric"); + end + + try + [c,a]= iirpowcomp(b,a); + catch + continue; + end + c=c' ; + [m,n]= numsort(b,c); //for sorting the numerators + + [d1,d2,be]= allpassd(m,n,a); //computing the denominator coefficients + +endfunction + + +function [m,n]= numsort(b,c) + +//If b is anti-symmetric then make b the second argument + if max(abs(b+b($:-1:1)))< %eps^(2/3) then + m=c; + n=b; + else + m=b; + n=c; + end + +endfunction + +function [d1,d2,be]= allpassd(m,n,a) + +//if n is real and anti-symmetric, maake n imaginary + if isreal(n) & (max(abs(n+n($:-1:1))) < %eps^(2/3)) then + n=n*%i; + end + + z= roots(m - n*%i); + + d1=1; + d2=1; +// Separate the zeros inside the unit circle and the ones outside to form the allpass functions + + for l=1:length(z) + if abs(z(l))<1 + d2= conv(d2,[1 -z(l)]); + else + d1= conv(d1,[1 -1/conj(z(l))]); + end + + end + +// To remove the roundoff imaginary parts + if max(abs(imag(d1))) < %eps^(2/3) then + d1= real(d1); + end + if max(abs(imag(d2))) < %eps^(2/3) then + d2= real(d2); + end + + be= sum(d2)*(sum(m)+%i*sum(n))./sum(a)./sum(conj(d2)); + +endfunction + diff --git a/DSP functions/tf2cl/test_1.sce b/DSP functions/tf2cl/test_1.sce new file mode 100644 index 0000000..cc83083 --- /dev/null +++ b/DSP functions/tf2cl/test_1.sce @@ -0,0 +1,7 @@ +// Test # 1 : No Input Arguments +exec('./tf2cl.sci',-1); +[k1,k2,b]=tf2cl(); +//!--error 10000 +//Only 2 input arguments allowed +//at line 38 of function tf2cl called by : +//[d1,d2,b]=tf2cl(); diff --git a/DSP functions/tf2cl/test_2.sce b/DSP functions/tf2cl/test_2.sce new file mode 100644 index 0000000..ecaa706 --- /dev/null +++ b/DSP functions/tf2cl/test_2.sce @@ -0,0 +1,5 @@ +// Test #2 : Excess Input Arguments +exec('./tf2cl.sci',-1); +[k1,k2,b]=tf2cl([0.5 -0.9 0.5],[1 2 3],7); +//!--error 58 +//Wrong number of input arguments. diff --git a/DSP functions/tf2cl/test_3.sce b/DSP functions/tf2cl/test_3.sce new file mode 100644 index 0000000..2a0f1d3 --- /dev/null +++ b/DSP functions/tf2cl/test_3.sce @@ -0,0 +1,5 @@ +// Test # 3 : Excess Output Arguments +exec('./tf2cl.sci',-1); +[k1,k2,b]=tf2cl([0.5 -0.9 0.5],[1 2 3]); +//!--error 59 +//Wrong number of output arguments. diff --git a/DSP functions/tf2cl/test_4.sce b/DSP functions/tf2cl/test_4.sce new file mode 100644 index 0000000..1b988ac --- /dev/null +++ b/DSP functions/tf2cl/test_4.sce @@ -0,0 +1,8 @@ +// Test # 4 : When numerator is neither symmetric or anti-symmetric +exec('./tf2cl.sci',-1); +//[d1,d2,b]=tf2cl([0.4 0.5 0.31],[6 32.4 -3]) +//!--error 10000 +//Numerator coeffcients must be either be symmetric or antisymmetric +//at line 71 of function tf2ca called by : +//at line 46 of function tf2cl called by : +//[d1,d2,b]=tf2cl([0.4 0.5 0.31],[6 32.4 -3]) diff --git a/DSP functions/tf2cl/test_5.sce b/DSP functions/tf2cl/test_5.sce new file mode 100644 index 0000000..a33122c --- /dev/null +++ b/DSP functions/tf2cl/test_5.sce @@ -0,0 +1,16 @@ +// Test #5 : Vaid Input case +exec('./tf2cl.sci',-1); +[k1,k2,b]=tf2cl([0.5 -0.9 0.5],[1 2 3]); +disp(b); +disp(k2); +disp(k1); +// +//Scilab Output +//b=-0.6154156 + 0.7883950i +//k2=0.3328796 + 0.4710837i +//k1=0.3328796 - 0.4710837i +// +//Matlab Output +//k1=0.3329 - 0.4711i +//k2= 0.3329 + 0.4711i +//b= -0.6154 + 0.7884i diff --git a/DSP functions/tf2cl/tf2cl.sci b/DSP functions/tf2cl/tf2cl.sci new file mode 100644 index 0000000..6b85d57 --- /dev/null +++ b/DSP functions/tf2cl/tf2cl.sci @@ -0,0 +1,59 @@ +function [k1,k2,c]= tf2cl(b,a) +// Transfer function to coupled allpass lattice +// +//Calling Sequences +// +// [k1,k2] = tf2cl(b,a) where b is a real, symmetric vector of numerator coefficients and a is a real vector of denominator coefficients, corresponding to a stable digital filter, will perform the coupled allpass decomposition of a stable IIR filter H(z) and convert the allpass transfer functions H1(z) and H2(z) to a coupled lattice allpass structure with coefficients given in vectors k1 and k2. +// +// H(z)=B(z)A(z)=(1/2)[H1(z)+H2(z)] +// +//[k1,k2] = tf2cl(b,a) where b is a real, antisymmetric vector of numerator coefficients and a is a real vector of denominator coefficients, corresponding to a stable digital filter, performs the coupled allpass decomposition of a stable IIR filter H(z) and convert the allpass transfer functions H1(z) and H2(z) to a coupled lattice allpass structure with coefficients given in vectors k1 and k2. +// +// H(z)=B(z)A(z)=(1/2)[H1(z)−H2(z)] +// +// [k1,k2,be] = tf2cl(b,a) performs the generalized allpass decomposition of a stable IIR filter H(z) and converts the complex allpass transfer functions H1(z) and H2(z) to corresponding lattice allpass filters +// H(z)=B(z)A(z)=(1/2)[β'*H1(z)+β*H2(z)] +//Input Parameters: +// b: Vector of numerator coefficients of the digital filters +// a: Vector of denominator coefficients of the digital filters +// +//Output Parameters: +// k1 & k2: Coefficients of coupled lattice allpass structure given in vectors +// be: Complex Scalar +// +//Example: +// [b,a]=cheby1(9,.5,.4); +// [k1,k2]=tf2cl(b,a); +// [num1,den1]=latc2tf(k1,'allpass'); +// [num2,den2]=latc2tf(k2,'allpass'); +// num = 0.5*conv(num1,den2)+0.5*conv(num2,den1); +// den = conv(den1,den2); +// +// Author: Shrenik Nambiar +// +//References: S. K. Mitra, Digital Signal Processing, A Computer Based Approach, McGraw-Hill, N.Y., 1998 +// Input validation statements +// + if argn(2)~=2 then + error("Only 2 input arguments allowed"); + end + + if argn(1)<1 | argn(1)>3 then + error("The number of output arguments allowed are 1-3"); + end + + + [d1,d2,c]= tf2ca(b,a); + +// To obtain the coefficients of the coupesd all pass filters + k1= tf2latc(1,d1); + k2= tf2latc(1,d2); +endfunction + + + + + + + + diff --git a/DSP functions/zpkbpc2bpc/test_1.sce b/DSP functions/zpkbpc2bpc/test_1.sce new file mode 100644 index 0000000..72df19b --- /dev/null +++ b/DSP functions/zpkbpc2bpc/test_1.sce @@ -0,0 +1,7 @@ +// Test # 1 : No Input Arguments +exec('./zpkbpc2bpc.sci',-1); +[z,p,k,n,d]=zpkbpc2bpc(); +//!--error 10000 +//Number of input arguments should be 5 +//at line 37 of function zpkbpc2bpc called by : +//[z,p,k,n,d]=zpkbpc2bpc(); diff --git a/DSP functions/zpkbpc2bpc/test_10.sce b/DSP functions/zpkbpc2bpc/test_10.sce new file mode 100644 index 0000000..90ba8a6 --- /dev/null +++ b/DSP functions/zpkbpc2bpc/test_10.sce @@ -0,0 +1,26 @@ +// Test #10 : For valid input case #2 +exec('./zpkbpc2bpc.sci',-1); +[z,p,k,n,d]=zpkbpc2bpc([4*%i,2.5*%i],2.2*%i,8,[-0.2,0.6],[0.4,0.764]); +disp(d); +disp(n); +disp(k); +disp(p); +disp(z); +// +//Scilab Output +//d= 0.1080035 + 0.4099353i 1. +//n= 0.3622754 - 0.9320711i -0.3429618 - 0.2491764i +//k= 13.363367 - 5.3219712i +//p= -0.3975090 + 0.5718099i +//z= -0.8706421 + 1.5292315i +// -0.8396959 + 1.2542556i +// +//Matlab Output +//z= -0.8706 + 1.5292i +// -0.8397 + 1.2543i +//p = -0.3975 + 0.5718i +//k= 13.3634 - 5.3220i +//n= 0.3623 - 0.9321i +// -0.3430 - 0.2492i +//d= 0.1080 + 0.4099i +// 1.0000 + 0.0000i diff --git a/DSP functions/zpkbpc2bpc/test_2.sce b/DSP functions/zpkbpc2bpc/test_2.sce new file mode 100644 index 0000000..64aa3f6 --- /dev/null +++ b/DSP functions/zpkbpc2bpc/test_2.sce @@ -0,0 +1,5 @@ +// Test # 2 : Excess Input Arguments +exec('./zpkbpc2bpc.sci',-1); +[z,p,k,n,d]=zpkbpc2bpc(0.3,0.2,0.7,[0.5,0.6],[0.4,0.8],12); +//!--error 58 +//Wrong number of input arguments diff --git a/DSP functions/zpkbpc2bpc/test_3.sce b/DSP functions/zpkbpc2bpc/test_3.sce new file mode 100644 index 0000000..7fd4ce2 --- /dev/null +++ b/DSP functions/zpkbpc2bpc/test_3.sce @@ -0,0 +1,7 @@ +// Test # 3 : Checking the type for Input Argument #3 +exec('./zpkbpc2bpc.sci',-1); +[z,p,k,n,d]=zpkbpc2bpc(0.3,0.2,[0.5,0.6],[0.4,0.8],[0.1,0.4]); +// !--error 10000 +//K must be a scalar +//at line 59 of function zpkbpc2bpc called by : +//[z,p,k,n,d]=zpkbpc2bpc(0.3,0.2,[0.5.6],[0.4,0.8],[0.1,0.4]) diff --git a/DSP functions/zpkbpc2bpc/test_4.sce b/DSP functions/zpkbpc2bpc/test_4.sce new file mode 100644 index 0000000..9efd3b0 --- /dev/null +++ b/DSP functions/zpkbpc2bpc/test_4.sce @@ -0,0 +1,5 @@ +// Test #4 : Incorrect number of output Arguments +exec('./zpkbpc2bpc.sci',-1); +[z,p,k,n,d,e]=zpkbpc2bpc(0.3,0.2,0.7,[0.5,0.6],[0.4,0.8]); +//!--error 59 +//Wrong number of output arguments diff --git a/DSP functions/zpkbpc2bpc/test_5.sce b/DSP functions/zpkbpc2bpc/test_5.sce new file mode 100644 index 0000000..19bdf7a --- /dev/null +++ b/DSP functions/zpkbpc2bpc/test_5.sce @@ -0,0 +1,7 @@ +// Test # 5 : When either Input Argument #4 or Input Argument #5 is of complex type +exec('./zpkbpc2bpc.sci',-1); +[z,p,k,n,d]=zpkbpc2bpc(3,0.2,7,[0.5*%i,0.6],[0.4,0.8]); +//!--error 10000 +//Wo must be real and numeric and must contain only 2 elements +//at line 45 of function zpkbpc2bpc called by : +//[z,p,k,n,d]=zpkbpc2bpc(3,0.2,7,[0.5*%i,0.6],[0.4,0.8]) diff --git a/DSP functions/zpkbpc2bpc/test_6.sce b/DSP functions/zpkbpc2bpc/test_6.sce new file mode 100644 index 0000000..5192c1d --- /dev/null +++ b/DSP functions/zpkbpc2bpc/test_6.sce @@ -0,0 +1,7 @@ +// Test # 6 : Range test for Input Argument #4 or Input Argument #5 +exec('./zpkbpc2bpc.sci',-1); +[z,p,k,n,d]=zpkbpc2bpc(7.3,5.2,9.7,[-0.9,0.6],[4,0.8]); +//!--error 10000 +//Wt must lie between -1 and 1 +//at line 55 of function zpkbpc2bpc called by : +//[z,p,k,n,d]=zpkbpc2bpc(7.3,5.2,9.7,[-0.9,0.6],[4,0.8]); diff --git a/DSP functions/zpkbpc2bpc/test_7.sce b/DSP functions/zpkbpc2bpc/test_7.sce new file mode 100644 index 0000000..16c44c6 --- /dev/null +++ b/DSP functions/zpkbpc2bpc/test_7.sce @@ -0,0 +1,7 @@ +// Test #7 : Length test for Input Argument #4 or Input Argument #5 +exec('./zpkbpc2bpc.sci',-1); +[z,p,k,n,d]=zpkbpc2bpc(4,2.2,1,[0.5,0.6],[-0.8,0.34,0.28]); +//!--error 10000 +//Wt must be real and numeric and must contain only 2 elements +//at line 52 of function zpkbpc2bpc called by : +//[z,p,k,n,d]=zpkbpc2bpc(4,2.2,1,[0.5,0.6],[-0.8,0.34,0.28]) diff --git a/DSP functions/zpkbpc2bpc/test_8.sce b/DSP functions/zpkbpc2bpc/test_8.sce new file mode 100644 index 0000000..5654b8e --- /dev/null +++ b/DSP functions/zpkbpc2bpc/test_8.sce @@ -0,0 +1,16 @@ +// Test #8 : When output arguments are less than 5 +exec('./zpkbpc2bpc.sci',-1); +[z,p,k]=zpkbpc2bpc(4,2.2,1,[0.5,0.6],[-0.8,0.34]); +disp(k); +disp(p); +disp(z); +// +//Scilab Output +//k= 1.4967554 + 0.3078635i +//p= -0.7456261 + 0.5534776i +//z= -0.8709140 + 0.6869281i +// +//Matlab Output +//z=-0.8709 + 0.6869i +//p= -0.7456 + 0.5535i +//k = 1.4968 + 0.3079i diff --git a/DSP functions/zpkbpc2bpc/test_9.sce b/DSP functions/zpkbpc2bpc/test_9.sce new file mode 100644 index 0000000..1f80da0 --- /dev/null +++ b/DSP functions/zpkbpc2bpc/test_9.sce @@ -0,0 +1,28 @@ +// Test #9 : For valid input case #1 +exec('./zpkbpc2bpc.sci',-1); +[z,p,k,n,d]=zpkbpc2bpc([4,9],[4.3,7.6,9],0.5,[0.61,0.83],[-0.22,0.76]); +disp(d); +disp(n); +disp(k); +disp(p); +disp(z); +// +//Scilab Output +//d=0.4594618 - 0.5211571i 1. +//n=0.1564345 + 0.9876883i -0.4428651 + 0.535332i +//k=-0.0285881 - 0.0172055i +//p=-0.4546206 - 0.6294278i +// -0.4536544 - 0.5850685i +// -0.4539772 - 0.5755747i +//z= -0.7430941 - 1.0394167i + -0.8447950 - 1.0710728i +// +//Matlab Output +//z= -0.7431 - 1.0394i +// -0.8448 - 1.0711i +// p = -0.4546 - 0.6294i +// -0.4537 - 0.5851i +// -0.4540 - 0.5756i +//k=-0.0286 - 0.0172i +//n= 0.1564 + 0.9877i -0.4429 + 0.5353i +//d= 0.4595 - 0.5212i 1.0000 + 0.0000i diff --git a/DSP functions/zpkbpc2bpc/zpkbpc2bpc.sci b/DSP functions/zpkbpc2bpc/zpkbpc2bpc.sci new file mode 100644 index 0000000..950314a --- /dev/null +++ b/DSP functions/zpkbpc2bpc/zpkbpc2bpc.sci @@ -0,0 +1,99 @@ +function [Z2, P2, K2, AllpassNum,AllpassDen]= zpkbpc2bpc(Z, P ,K, Wo,Wt) +//Zero-pole-gain complex bandpass frequency transformation +// +//Calling Sequences +// +//[Z2,P2,K2,AllpassNum,AllpassDen] = zpkbpc2bpc(Z,P,K,Wo,Wt) returns zeros, Z2, poles, P2, and gain factor, K2, of the target filter transformed from the complex bandpass prototype by applying a first-order complex bandpass to complex bandpass frequency transformation.It also returns the numerator, AllpassNum, and the denominator, AllpassDen, of the allpass mapping filter. The original lowpass filter is given with zeros, Z, poles, P, and gain factor, K. +// +//Input Parameters: +// Z: Zeros of the prototype filter +// P: Poles of the prototype filter +// K: Gain of the prototype filter +// Wo: Frequency value of the prototype filter to be transformed +// Wt: Desired frquency of the target filter +// +//Output Parameters: +// Z2: Zeros of the target filter +// P2: Poles of the target filter +// K2:Gain factor of the target filter +// AllpassNum: Numerator of the mapping filter +// AllpassDen: Denominator of the mapping filter +//Example: Design a prototype real IIR halfband filter using a standard elliptic approach and create a complex passband from 0.2 to 0.45 +// +// [b, a] = ellip(3,0.1,30,0.409); +// [b, a] = iirlp2bpc(b,a,0.5,[0.2,0.45]); +// z = roots(b); +// p = roots(a); +// k = b(1); +// [z2,p2,k2] = zpkbpc2bpc(z,p,k,[0.2, 0.45],[-0.45, -0.2]); +// +//Author: Shrenik Nambiar +// +//References: 1. Constantinides, A.G., "Spectral transformations for digital filters," IEEE® Proceedings, vol. 117, no. 8, pp. 1585-1590, August 1970. +// +//Input Validaton Statement + + if argn(2) ~=5 then + error("Number of input arguments should be 5"); + end + + if argn(1)<1 | argn(1)>5 then + error("Number of output arguments should lie between 1 and 5"); + end + + if length(Wo)~=2 | ~isreal(Wo) then + error("Wo must be real and 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 and 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 + + if ~isscalar(K) then + error("K must be a scalar"); + 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); + +// To undo the conjugation performed earlier + AllpassNum=flipdim(conj(AllpassNum),2); + AllpassDen=flipdim(conj(AllpassDen),2); + + if or(AllpassNum~=1) | or(AllpassDen~=1) then + Z2=[]; + P2=[]; + K2=K*prod(AllpassNum(1)-Z*AllpassDen(1))/prod(AllpassNum(1)-P*AllpassDen(1)); + + for i=1:length(Z), + Z2 = [Z2, roots(AllpassNum - Z(i).*AllpassDen).']; + end + for i=1:length(P), + P2 = [P2, roots(AllpassNum - P(i).*AllpassDen).']; + end +// For stabilizing the target filter (if unstable after tranformation) + index = find(abs(P2)>1); + K2 = K2/prod(1-P2(index)); + P2(index) = 1 ./conj(P2(index)); + K2= K2*prod(1-P2(index)); + else + Z2=Z; + P2=P; + K2=K; + end + //Converting to Column vector + Z2=Z2(:); + P2=P2(:); + +endfunction diff --git a/DSP functions/zpklp2bp/test_1.sce b/DSP functions/zpklp2bp/test_1.sce new file mode 100644 index 0000000..62c2c5f --- /dev/null +++ b/DSP functions/zpklp2bp/test_1.sce @@ -0,0 +1,7 @@ +// Test # 1 : No Input Arguments +exec('./zpklp2bp.sci',-1); +[z,p,k,n,d]=zpklp2bp(); +//!--error 10000 +//Number of input arguments should be 5 +//at line 35 of function zpklp2bp called by : +//[z,p,k,n,d]=zpklp2bp(); diff --git a/DSP functions/zpklp2bp/test_10.sce b/DSP functions/zpklp2bp/test_10.sce new file mode 100644 index 0000000..fe7bb33 --- /dev/null +++ b/DSP functions/zpklp2bp/test_10.sce @@ -0,0 +1,30 @@ +// Test #10 : For valid input #2 +exec('./zpklp2bp.sci',-1); +[z,p,k,n,d]=zpklp2bp(3.2*%i,[2.2*%i,7],1,0.66,[0.52,0.74]); +disp(d); +disp(n); +disp(k); +disp(p); +disp(z); +// +//Scilab Output +//d=1. 0.6960120 0.6489181 +//n=- 0.6489181 - 0.6960120 - 1. +//k=0 +//p=-0.4944747 - 0.7288925i +// -0.2316771 + 0.8310738i +// -0.3639793 + 0.7694945i +// -0.3639793 - 0.7694945i +//z=-0.4533619 - 0.7174813i +// -0.2575236 + 0.7908268i +// +//Matlab Output +// z = -0.4534 - 0.7175i +// -0.2575 + 0.7908i +// p = -0.4945 - 0.7289i +// -0.2317 + 0.8311i +// -0.3640 + 0.7695i +// -0.3640 - 0.7695i +//k = 0 +//n =-0.6489 -0.6960 -1.0000 +//d= 1.0000 0.6960 0.6489 diff --git a/DSP functions/zpklp2bp/test_2.sce b/DSP functions/zpklp2bp/test_2.sce new file mode 100644 index 0000000..b74021d --- /dev/null +++ b/DSP functions/zpklp2bp/test_2.sce @@ -0,0 +1,5 @@ +// Test # 2 : Excess Input Arguments +exec('./zpklp2bp.sci',-1); +[z,p,k,n,d]=zpklp2bp(0.3,0.2,0.7,0.6,[0.4,0.8],12); +//!--error 58 +//Wrong number of input arguments diff --git a/DSP functions/zpklp2bp/test_3.sce b/DSP functions/zpklp2bp/test_3.sce new file mode 100644 index 0000000..97d8666 --- /dev/null +++ b/DSP functions/zpklp2bp/test_3.sce @@ -0,0 +1,7 @@ +// Test # 3 : Checking the type for Input Argument #3 +exec('./zpklp2bp.sci',-1); +[z,p,k,n,d]=zpklp2bp(0.3,0.2,[0.5,0.6],0.4,[0.1,0.4]); +// !--error 10000 +//K must be a scalar +//at line 57 of function zpklp2bp called by : +//[z,p,k,n,d]=zpklp2bp(0.3,0.2,[0.5.6],0.4,[0.1,0.4]) diff --git a/DSP functions/zpklp2bp/test_4.sce b/DSP functions/zpklp2bp/test_4.sce new file mode 100644 index 0000000..a38e9d0 --- /dev/null +++ b/DSP functions/zpklp2bp/test_4.sce @@ -0,0 +1,5 @@ +// Test #4 : Incorrect number of output Arguments +exec('./zpklp2bp.sci',-1); +[z,p,k,n,d,e]=zpklp2bp(0.3,0.2,0.7,0.5,[0.4,0.8]); +//!--error 59 +//Wrong number of output arguments diff --git a/DSP functions/zpklp2bp/test_5.sce b/DSP functions/zpklp2bp/test_5.sce new file mode 100644 index 0000000..11e230b --- /dev/null +++ b/DSP functions/zpklp2bp/test_5.sce @@ -0,0 +1,7 @@ +// Test # 5 : When either Input Argument #4 or Input Argument #5 is of complex type +exec('./zpklp2bp.sci',-1); +[z,p,k,n,d]=zpklp2bp(3,0.2,7,0.5*%i,[0.4,0.8]); +//!--error 10000 +//Wo must be real ,numeric and scalar +//at line 43 of function zpklp2bp called by : +//[z,p,k,n,d]=zpklp2bp(3,0.2,7,0.5*%i,[0.4,0.8]); diff --git a/DSP functions/zpklp2bp/test_6.sce b/DSP functions/zpklp2bp/test_6.sce new file mode 100644 index 0000000..8299627 --- /dev/null +++ b/DSP functions/zpklp2bp/test_6.sce @@ -0,0 +1,7 @@ +// Test # 6 : Range test for Input Argument #4 or Input Argument #5 +exec('./zpklp2bp.sci',-1); +[z,p,k,n,d]=zpklp2bp(7.3,5.2,9.7,0.6,[4,0.8]); +//!--error 10000 +//Wt must lie between 0 and 1 +//at line 53 of function zpklp2bp called by : +//[z,p,k,n,d]=zpklp2bp(7.3,5.2,9.7,0.6,[4,0.8]); diff --git a/DSP functions/zpklp2bp/test_7.sce b/DSP functions/zpklp2bp/test_7.sce new file mode 100644 index 0000000..8454826 --- /dev/null +++ b/DSP functions/zpklp2bp/test_7.sce @@ -0,0 +1,7 @@ +// Test #7 : Length test for Input Argument #4 or Input Argument #5 +exec('./zpklp2bp.sci',-1); +[z,p,k,n,d]=zpklp2bp(4,2.2,1,0.6,[-0.8,0.34,0.28]); +//!--error 10000 +//Wt must be real and numeric and must contain only 2 elements +//at line 50 of function zpkbpc2bpc called by : +//[z,p,k,n,d]=zpkbpc2bpc(4,2.2,1,0.6,[-0.8,0.34,0.28]) diff --git a/DSP functions/zpklp2bp/test_8.sce b/DSP functions/zpklp2bp/test_8.sce new file mode 100644 index 0000000..39f291c --- /dev/null +++ b/DSP functions/zpklp2bp/test_8.sce @@ -0,0 +1,20 @@ +// Test #8 : When output arguments are less than 5 +exec('./zpklp2bp.sci',-1); +[z,p,k]=zpklp2bp(4*%i,2.2,1,0.2,[0.12,0.34]); +disp(k); +disp(p); +disp(z); +// +//Scilab Output +//k=- 0.0238505 + 1.8615464i +//p=0.5632188 + 0.3093542i +// 0.5632188 - 0.3093542i +//z=0.8470602 + 0.0860862i +// -0.0932210 - 0.2848409i +// +//Matlab Output +//z= 0.8471 + 0.0861i +// -0.0932 - 0.2848i +//p = 0.5632 + 0.3094i +// 0.5632 - 0.3094i +//k = -0.0239 + 1.8615i diff --git a/DSP functions/zpklp2bp/test_9.sce b/DSP functions/zpklp2bp/test_9.sce new file mode 100644 index 0000000..9b9e4b9 --- /dev/null +++ b/DSP functions/zpklp2bp/test_9.sce @@ -0,0 +1,31 @@ +// Test #9 : For valid input #1 +exec('./zpklp2bp.sci',-1); +[z,p,k,n,d]=zpklp2bp([4*%i,8*%i],6.2*%i,9,0.9,[0.92,0.994]); +disp(d); +disp(n); +disp(k); +disp(p); +disp(z); +// +//Scilab Output +//d=1. 1.9590134 0.9636840 +//n=-0.9636840 - 1.9590134 - 1. +//k=-9.5455677 - 46.587214i +//p=-0.9822521 - 0.0601597i +// -0.9785028 + 0.0713638i +//z=-0.9841689 - 0.0580538i +// -0.9788944 + 0.0748640i +// -0.9815292 - 0.0611606i +// -0.9785402 + 0.0699264i +// +//Matlab Output +//z= -0.9842 - 0.0581i +// -0.9789 + 0.0749i +// -0.9815 - 0.0612i +// -0.9785 + 0.0699i +// p = -0.9823 - 0.0602i +// -0.9785 + 0.0714i +//k = -9.5456 -46.5872i +//n = -0.9637 -1.9590 -1.0000 +//d = 1.0000 1.9590 0.9637 + diff --git a/DSP functions/zpklp2bp/zpklp2bp.sci b/DSP functions/zpklp2bp/zpklp2bp.sci new file mode 100644 index 0000000..f7cbb56 --- /dev/null +++ b/DSP functions/zpklp2bp/zpklp2bp.sci @@ -0,0 +1,92 @@ +function [Z2, P2, K2, AllpassNum,AllpassDen]= zpklp2bp(Z, P ,K, Wo,Wt) +//Zero-pole-gain lowpass to real bandpass frequency transformation +// +//Calling Sequences +// +//[Z2,P2,K2,AllpassNum,AllpassDen] = zpklp2bp(Z,P,K,Wo,Wt) returns zeros, Z2, poles, P2, and gain factor, K2, of the target filter transformed from the real lowpass prototype by applying a second-order real lowpass to real bandpass frequency mapping.It also returns the numerator, AllpassNum, and the denominator AllpassDen, of the allpass mapping filter. The prototype lowpass filter is given with zeros, Z, poles, P, and gain factor, K. +// +//Input Parameters: +// Z: Zeros of the prototype filter +// P: Poles of the prototype filter +// K: Gain of the prototype filter +// Wo: Frequency value of the prototype filter to be transformed +// Wt: Desired frquency of the target filter +// +//Output Parameters: +// Z2: Zeros of the target filter +// P2: Poles of the target filter +// K2:Gain factor of the target filter +// AllpassNum: Numerator of the mapping filter +// AllpassDen: Denominator of the mapping filter +//Example: Design a prototype real IIR halfband filter using a standard elliptic approach +// +// [b, a] = ellip(3,0.1,30,0.409); +// z = roots(b); +// p = roots(a); +// k = b(1); +// [z2,p2,k2] = zpklp2bp(z,p,k,0.5,[0.25, 0.35]); +// +//Author: Shrenik Nambiar +// +//References: 1. Constantinides, A.G., "Spectral transformations for digital filters," IEEE® Proceedings, vol. 117, no. 8, pp. 1585-1590, August 1970. +// +//Input Validaton Statement + if argn(2) ~=5 then + error("Number of input arguments should be 5"); + end + + if argn(1)<1 | argn(1)>5 then + error("Number of output arguments should be between 1and 5"); + 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 + + if ~isscalar(K) then + error("K must be a scalar"); + 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); + + + if or(AllpassNum~=1) | or(AllpassDen~=1) then + Z2=[]; + P2=[]; + K2=K*prod(AllpassNum(1)-Z*AllpassDen(1))/prod(AllpassNum(1)-P*AllpassDen(1)); + + for i=1:length(Z), + Z2 = [Z2, roots(AllpassNum - Z(i).*AllpassDen).']; + end + for i=1:length(P), + P2 = [P2, roots(AllpassNum - P(i).*AllpassDen).']; + end +// For stabilizing the target filter (if unstable after tranformation) + index = find(abs(P2)>1); + K2 = K2/prod(1-P2(index)); + P2(index) = 1 ./conj(P2(index)); + K2= K2*prod(1-P2(index)); + else + Z2=Z; + P2=P; + K2=K; + end + //Converting to Column vector + Z2=Z2(:); + P2=P2(:); + +endfunction From 4d4533d9ce845d5d81cb170e0427b9bbe263c09f Mon Sep 17 00:00:00 2001 From: Shrenik Nambiar Date: Tue, 25 Jul 2017 23:50:53 +0530 Subject: [PATCH 13/15] Add files via upload --- DSP functions/zpklp2bpc/test_1.sce | 7 + DSP functions/zpklp2bpc/test_10.sce | 24 ++++ DSP functions/zpklp2bpc/test_2.sce | 5 + DSP functions/zpklp2bpc/test_3.sce | 7 + DSP functions/zpklp2bpc/test_4.sce | 5 + DSP functions/zpklp2bpc/test_5.sce | 7 + DSP functions/zpklp2bpc/test_6.sce | 7 + DSP functions/zpklp2bpc/test_7.sce | 7 + DSP functions/zpklp2bpc/test_8.sce | 18 +++ DSP functions/zpklp2bpc/test_9.sce | 24 ++++ DSP functions/zpklp2bpc/zpklp2bpc.sci | 92 +++++++++++++ DSP functions/zpklp2bs/test_1.sce | 7 + DSP functions/zpklp2bs/test_2.sce | 5 + DSP functions/zpklp2bs/test_3.sce | 7 + DSP functions/zpklp2bs/test_4.sce | 5 + DSP functions/zpklp2bs/test_5.sce | 7 + DSP functions/zpklp2bs/test_6.sce | 7 + DSP functions/zpklp2bs/test_7.sce | 7 + DSP functions/zpklp2bs/test_8.sce | 20 +++ DSP functions/zpklp2bs/test_9.sce | 34 +++++ DSP functions/zpklp2bs/zpklp2bs.sci | 92 +++++++++++++ DSP functions/zpklp2bsc/test_1.sce | 7 + DSP functions/zpklp2bsc/test_2.sce | 5 + DSP functions/zpklp2bsc/test_3.sce | 7 + DSP functions/zpklp2bsc/test_4.sce | 5 + DSP functions/zpklp2bsc/test_5.sce | 7 + DSP functions/zpklp2bsc/test_6.sce | 7 + DSP functions/zpklp2bsc/test_7.sce | 7 + DSP functions/zpklp2bsc/test_8.sce | 16 +++ DSP functions/zpklp2bsc/test_9.sce | 24 ++++ DSP functions/zpklp2bsc/zpklp2bsc.sci | 92 +++++++++++++ DSP functions/zpklp2hp/test_1.sce | 7 + DSP functions/zpklp2hp/test_10.sce | 26 ++++ DSP functions/zpklp2hp/test_2.sce | 5 + DSP functions/zpklp2hp/test_3.sce | 7 + DSP functions/zpklp2hp/test_4.sce | 5 + DSP functions/zpklp2hp/test_5.sce | 7 + DSP functions/zpklp2hp/test_6.sce | 7 + DSP functions/zpklp2hp/test_7.sce | 7 + DSP functions/zpklp2hp/test_8.sce | 16 +++ DSP functions/zpklp2hp/test_9.sce | 22 +++ DSP functions/zpklp2hp/zpklp2hp.sci | 91 +++++++++++++ DSP functions/zpklp2lp/test_1.sce | 7 + DSP functions/zpklp2lp/test_10.sce | 24 ++++ DSP functions/zpklp2lp/test_2.sce | 5 + DSP functions/zpklp2lp/test_3.sce | 5 + DSP functions/zpklp2lp/test_4.sce | 7 + DSP functions/zpklp2lp/test_5.sce | 7 + DSP functions/zpklp2lp/test_6.sce | 7 + DSP functions/zpklp2lp/test_7.sce | 7 + DSP functions/zpklp2lp/test_8.sce | 16 +++ DSP functions/zpklp2lp/test_9.sce | 22 +++ DSP functions/zpklp2lp/zpklp2lp.sci | 89 ++++++++++++ DSP functions/zpklp2mb/test_1.sce | 7 + DSP functions/zpklp2mb/test_10.sce | 42 ++++++ DSP functions/zpklp2mb/test_11.sce | 34 +++++ DSP functions/zpklp2mb/test_12.sce | 34 +++++ DSP functions/zpklp2mb/test_2.sce | 7 + DSP functions/zpklp2mb/test_3.sce | 5 + DSP functions/zpklp2mb/test_4.sce | 7 + DSP functions/zpklp2mb/test_5.sce | 7 + DSP functions/zpklp2mb/test_6.sce | 7 + DSP functions/zpklp2mb/test_7.sce | 7 + DSP functions/zpklp2mb/test_8.sce | 7 + DSP functions/zpklp2mb/test_9.sce | 20 +++ DSP functions/zpklp2mb/zpklp2mb.sci | 116 ++++++++++++++++ DSP functions/zpklp2xn/test_1.sce | 7 + DSP functions/zpklp2xn/test_10.sce | 30 ++++ DSP functions/zpklp2xn/test_2.sce | 7 + DSP functions/zpklp2xn/test_3.sce | 5 + DSP functions/zpklp2xn/test_4.sce | 7 + DSP functions/zpklp2xn/test_5.sce | 7 + DSP functions/zpklp2xn/test_6.sce | 7 + DSP functions/zpklp2xn/test_7.sce | 7 + DSP functions/zpklp2xn/test_8.sce | 19 +++ DSP functions/zpklp2xn/test_9.sce | 30 ++++ DSP functions/zpklp2xn/zpklp2xn.sci | 189 ++++++++++++++++++++++++++ DSP functions/zpkrateup/test_1.sce | 7 + DSP functions/zpkrateup/test_2.sce | 5 + DSP functions/zpkrateup/test_3.sce | 7 + DSP functions/zpkrateup/test_4.sce | 5 + DSP functions/zpkrateup/test_5.sce | 8 ++ DSP functions/zpkrateup/test_6.sce | 32 +++++ DSP functions/zpkrateup/test_7.sce | 6 + DSP functions/zpkrateup/test_8.sce | 47 +++++++ DSP functions/zpkrateup/zpkrateup.sci | 81 +++++++++++ DSP functions/zpkshift/test_1.sce | 7 + DSP functions/zpkshift/test_10.sce | 34 +++++ DSP functions/zpkshift/test_2.sce | 5 + DSP functions/zpkshift/test_3.sce | 7 + DSP functions/zpkshift/test_4.sce | 5 + DSP functions/zpkshift/test_5.sce | 8 ++ DSP functions/zpkshift/test_6.sce | 7 + DSP functions/zpkshift/test_7.sce | 7 + DSP functions/zpkshift/test_8.sce | 20 +++ DSP functions/zpkshift/test_9.sce | 34 +++++ DSP functions/zpkshift/zpkshift.sci | 96 +++++++++++++ 97 files changed, 2010 insertions(+) create mode 100644 DSP functions/zpklp2bpc/test_1.sce create mode 100644 DSP functions/zpklp2bpc/test_10.sce create mode 100644 DSP functions/zpklp2bpc/test_2.sce create mode 100644 DSP functions/zpklp2bpc/test_3.sce create mode 100644 DSP functions/zpklp2bpc/test_4.sce create mode 100644 DSP functions/zpklp2bpc/test_5.sce create mode 100644 DSP functions/zpklp2bpc/test_6.sce create mode 100644 DSP functions/zpklp2bpc/test_7.sce create mode 100644 DSP functions/zpklp2bpc/test_8.sce create mode 100644 DSP functions/zpklp2bpc/test_9.sce create mode 100644 DSP functions/zpklp2bpc/zpklp2bpc.sci create mode 100644 DSP functions/zpklp2bs/test_1.sce create mode 100644 DSP functions/zpklp2bs/test_2.sce create mode 100644 DSP functions/zpklp2bs/test_3.sce create mode 100644 DSP functions/zpklp2bs/test_4.sce create mode 100644 DSP functions/zpklp2bs/test_5.sce create mode 100644 DSP functions/zpklp2bs/test_6.sce create mode 100644 DSP functions/zpklp2bs/test_7.sce create mode 100644 DSP functions/zpklp2bs/test_8.sce create mode 100644 DSP functions/zpklp2bs/test_9.sce create mode 100644 DSP functions/zpklp2bs/zpklp2bs.sci create mode 100644 DSP functions/zpklp2bsc/test_1.sce create mode 100644 DSP functions/zpklp2bsc/test_2.sce create mode 100644 DSP functions/zpklp2bsc/test_3.sce create mode 100644 DSP functions/zpklp2bsc/test_4.sce create mode 100644 DSP functions/zpklp2bsc/test_5.sce create mode 100644 DSP functions/zpklp2bsc/test_6.sce create mode 100644 DSP functions/zpklp2bsc/test_7.sce create mode 100644 DSP functions/zpklp2bsc/test_8.sce create mode 100644 DSP functions/zpklp2bsc/test_9.sce create mode 100644 DSP functions/zpklp2bsc/zpklp2bsc.sci create mode 100644 DSP functions/zpklp2hp/test_1.sce create mode 100644 DSP functions/zpklp2hp/test_10.sce create mode 100644 DSP functions/zpklp2hp/test_2.sce create mode 100644 DSP functions/zpklp2hp/test_3.sce create mode 100644 DSP functions/zpklp2hp/test_4.sce create mode 100644 DSP functions/zpklp2hp/test_5.sce create mode 100644 DSP functions/zpklp2hp/test_6.sce create mode 100644 DSP functions/zpklp2hp/test_7.sce create mode 100644 DSP functions/zpklp2hp/test_8.sce create mode 100644 DSP functions/zpklp2hp/test_9.sce create mode 100644 DSP functions/zpklp2hp/zpklp2hp.sci create mode 100644 DSP functions/zpklp2lp/test_1.sce create mode 100644 DSP functions/zpklp2lp/test_10.sce create mode 100644 DSP functions/zpklp2lp/test_2.sce create mode 100644 DSP functions/zpklp2lp/test_3.sce create mode 100644 DSP functions/zpklp2lp/test_4.sce create mode 100644 DSP functions/zpklp2lp/test_5.sce create mode 100644 DSP functions/zpklp2lp/test_6.sce create mode 100644 DSP functions/zpklp2lp/test_7.sce create mode 100644 DSP functions/zpklp2lp/test_8.sce create mode 100644 DSP functions/zpklp2lp/test_9.sce create mode 100644 DSP functions/zpklp2lp/zpklp2lp.sci create mode 100644 DSP functions/zpklp2mb/test_1.sce create mode 100644 DSP functions/zpklp2mb/test_10.sce create mode 100644 DSP functions/zpklp2mb/test_11.sce create mode 100644 DSP functions/zpklp2mb/test_12.sce create mode 100644 DSP functions/zpklp2mb/test_2.sce create mode 100644 DSP functions/zpklp2mb/test_3.sce create mode 100644 DSP functions/zpklp2mb/test_4.sce create mode 100644 DSP functions/zpklp2mb/test_5.sce create mode 100644 DSP functions/zpklp2mb/test_6.sce create mode 100644 DSP functions/zpklp2mb/test_7.sce create mode 100644 DSP functions/zpklp2mb/test_8.sce create mode 100644 DSP functions/zpklp2mb/test_9.sce create mode 100644 DSP functions/zpklp2mb/zpklp2mb.sci create mode 100644 DSP functions/zpklp2xn/test_1.sce create mode 100644 DSP functions/zpklp2xn/test_10.sce create mode 100644 DSP functions/zpklp2xn/test_2.sce create mode 100644 DSP functions/zpklp2xn/test_3.sce create mode 100644 DSP functions/zpklp2xn/test_4.sce create mode 100644 DSP functions/zpklp2xn/test_5.sce create mode 100644 DSP functions/zpklp2xn/test_6.sce create mode 100644 DSP functions/zpklp2xn/test_7.sce create mode 100644 DSP functions/zpklp2xn/test_8.sce create mode 100644 DSP functions/zpklp2xn/test_9.sce create mode 100644 DSP functions/zpklp2xn/zpklp2xn.sci create mode 100644 DSP functions/zpkrateup/test_1.sce create mode 100644 DSP functions/zpkrateup/test_2.sce create mode 100644 DSP functions/zpkrateup/test_3.sce create mode 100644 DSP functions/zpkrateup/test_4.sce create mode 100644 DSP functions/zpkrateup/test_5.sce create mode 100644 DSP functions/zpkrateup/test_6.sce create mode 100644 DSP functions/zpkrateup/test_7.sce create mode 100644 DSP functions/zpkrateup/test_8.sce create mode 100644 DSP functions/zpkrateup/zpkrateup.sci create mode 100644 DSP functions/zpkshift/test_1.sce create mode 100644 DSP functions/zpkshift/test_10.sce create mode 100644 DSP functions/zpkshift/test_2.sce create mode 100644 DSP functions/zpkshift/test_3.sce create mode 100644 DSP functions/zpkshift/test_4.sce create mode 100644 DSP functions/zpkshift/test_5.sce create mode 100644 DSP functions/zpkshift/test_6.sce create mode 100644 DSP functions/zpkshift/test_7.sce create mode 100644 DSP functions/zpkshift/test_8.sce create mode 100644 DSP functions/zpkshift/test_9.sce create mode 100644 DSP functions/zpkshift/zpkshift.sci diff --git a/DSP functions/zpklp2bpc/test_1.sce b/DSP functions/zpklp2bpc/test_1.sce new file mode 100644 index 0000000..97c28c9 --- /dev/null +++ b/DSP functions/zpklp2bpc/test_1.sce @@ -0,0 +1,7 @@ +// Test # 1 : No Input Arguments +exec('./zpklp2bpc.sci',-1); +[z,p,k,n,d]=zpklp2bpc(); +//!--error 10000 +//Number of input arguments should be 5 +//at line 35 of function zpklp2bpc called by : +//[z,p,k,n,d]=zpklp2bpc(); diff --git a/DSP functions/zpklp2bpc/test_10.sce b/DSP functions/zpklp2bpc/test_10.sce new file mode 100644 index 0000000..18c309a --- /dev/null +++ b/DSP functions/zpklp2bpc/test_10.sce @@ -0,0 +1,24 @@ +// Test #10 : For valid input #2 +exec('./zpklp2bpc.sci',-1); +[z,p,k,n,d]=zpklp2bpc([4*%i,%i],6.2,9,0.45,[0.52,0.94]); +disp(d); +disp(n); +disp(k); +disp(p); +disp(z); +// +//Scilab Output +//d=1. 0.2828317 - 0.3208096i +//n=-0.4276828 -0.6613119 + 0.7501111i +//k=5.1833783 - 2.9038393i +//p=-0.3643609 + 0.4132863i +//z=-0.1456174 + 0.4705680i +// 0.0399378 + 0.9992022i +// +//Matlab Output +//z=-0.1456 + 0.4706i +// 0.0399 + 0.9992i +//p= -0.3644 + 0.4133i +//k= 5.1834 - 2.9038i +//n= -0.4277 + 0.0000i -0.6613 + 0.7501i +//d= 1.0000 + 0.0000i 0.2828 - 0.3208i diff --git a/DSP functions/zpklp2bpc/test_2.sce b/DSP functions/zpklp2bpc/test_2.sce new file mode 100644 index 0000000..2bd4de5 --- /dev/null +++ b/DSP functions/zpklp2bpc/test_2.sce @@ -0,0 +1,5 @@ +// Test # 2 : Excess Input Arguments +exec('./zpklp2bpc.sci',-1); +[z,p,k,n,d]=zpklp2bpc(0.3,0.2,0.7,0.6,[0.4,0.8],12); +//!--error 58 +//Wrong number of input arguments diff --git a/DSP functions/zpklp2bpc/test_3.sce b/DSP functions/zpklp2bpc/test_3.sce new file mode 100644 index 0000000..7fd0440 --- /dev/null +++ b/DSP functions/zpklp2bpc/test_3.sce @@ -0,0 +1,7 @@ +// Test # 3 : Checking the type for Input Argument #3 +exec('./zpklp2bpc.sci',-1); +[z,p,k,n,d]=zpklp2bpc(0.3,0.2,[0.5,0.6],0.4,[0.1,0.4]); +// !--error 10000 +//K must be a scalar +//at line 57 of function zpklp2bp called by : +//[z,p,k,n,d]=zpklp2bp(0.3,0.2,[0.5.6],0.4,[0.1,0.4]) diff --git a/DSP functions/zpklp2bpc/test_4.sce b/DSP functions/zpklp2bpc/test_4.sce new file mode 100644 index 0000000..9e7aa4b --- /dev/null +++ b/DSP functions/zpklp2bpc/test_4.sce @@ -0,0 +1,5 @@ +// Test #4 : Incorrect number of output Arguments +exec('./zpklp2bpc.sci',-1); +[z,p,k,n,d,e]=zpklp2bpc(0.3,0.2,0.7,0.5,[0.4,0.8]); +//!--error 59 +//Wrong number of output arguments diff --git a/DSP functions/zpklp2bpc/test_5.sce b/DSP functions/zpklp2bpc/test_5.sce new file mode 100644 index 0000000..f110b4d --- /dev/null +++ b/DSP functions/zpklp2bpc/test_5.sce @@ -0,0 +1,7 @@ +// Test # 5 : When either Input Argument #4 or Input Argument #5 is of complex type +exec('./zpklp2bpc.sci',-1); +[z,p,k,n,d]=zpklp2bpc(3,0.2,7,0.5*%i,[0.4,0.8]); +//!--error 10000 +//Wo must be real ,numeric and scalar +//at line 43 of function zpklp2bpc called by : +//[z,p,k,n,d]=zpklp2bpc(3,0.2,7,0.5*%i,[0.4,0.8]); diff --git a/DSP functions/zpklp2bpc/test_6.sce b/DSP functions/zpklp2bpc/test_6.sce new file mode 100644 index 0000000..34d95ff --- /dev/null +++ b/DSP functions/zpklp2bpc/test_6.sce @@ -0,0 +1,7 @@ +// Test # 6 : Range test for Input Argument #4 or Input Argument #5 +exec('./zpklp2bpc.sci',-1); +[z,p,k,n,d]=zpklp2bpc(7.3,5.2,7,0.62,[0.4,3.8]); +//!--error 10000 +//Wt must lie between 0 and 1 +//at line 53 of function zpklp2bpc called by : +//[z,p,k,n,d]=zpklp2bpc(7.3,5.2,7,0.62,[0.4,3.8]); diff --git a/DSP functions/zpklp2bpc/test_7.sce b/DSP functions/zpklp2bpc/test_7.sce new file mode 100644 index 0000000..89cea7e --- /dev/null +++ b/DSP functions/zpklp2bpc/test_7.sce @@ -0,0 +1,7 @@ +// Test #7 : Length test for Input Argument #4 or Input Argument #5 +exec('./zpklp2bpc.sci',-1); +[z,p,k,n,d]=zpklp2bpc(4,2.2,1,[0.6,0.7],[0.34,0.28]); +//!--error 10000 +//Wo must be real ,numeric and scalar +//at line 43 of function zpklp2bpc called by : +//[z,p,k,n,d]=zpklp2bpc(4,2.2,1,[0.6,0.7],[0.34,0.28]) diff --git a/DSP functions/zpklp2bpc/test_8.sce b/DSP functions/zpklp2bpc/test_8.sce new file mode 100644 index 0000000..e12fd6b --- /dev/null +++ b/DSP functions/zpklp2bpc/test_8.sce @@ -0,0 +1,18 @@ +// Test #8 : When output arguments are less than 5 +exec('./zpklp2bpc.sci',-1); +[z,p,k]=zpklp2bpc(2.3*%i,[4.2,%i],3,0.3,[0.12,0.34]); +disp(k); +disp(p); +disp(z); +// +//Scilab Output +//k=-1.310438 - 0.3284784i +//p=0.4889351 + 0.4310543i +// 0.9980440 + 0.0625157i +//z=0.6269358 + 0.1312146i +// +//Matlab Output +//z=0.6269 + 0.1312i +//p= 0.4889 + 0.4311i +// 0.9980 + 0.0625i +//k= -1.3104 - 0.3285i diff --git a/DSP functions/zpklp2bpc/test_9.sce b/DSP functions/zpklp2bpc/test_9.sce new file mode 100644 index 0000000..4a39c5d --- /dev/null +++ b/DSP functions/zpklp2bpc/test_9.sce @@ -0,0 +1,24 @@ +// Test #9 : For valid input #1 +exec('./zpklp2bpc.sci',-1); +[z,p,k,n,d]=zpklp2bpc([2.4*%i,1.8*%i],2*%i,1.2*%i,0.3,[0.2,0.4]); +disp(d); +disp(n); +disp(k); +disp(p); +disp(z); +// +//Scilab Output +//d=1. -0.3090170 - 0.4253254i +//n=-0.5257311 0.5877853 + 0.8090170i +//k=2.5951024 - 0.6426794i +//p=0.6350925 + 0.2983767i +//z=0.5788124 + 0.3072064i +// 0.6722714 + 0.2951302i +// +//Matlab Output +//z=0.5788 + 0.3072i +// 0.6723 + 0.2951i +//p= 0.6351 + 0.2984i +//k= 2.5951 - 0.6427i +//n= -0.5257 + 0.0000i 0.5878 + 0.8090i +//d= 1.0000 + 0.0000i -0.3090 - 0.4253i diff --git a/DSP functions/zpklp2bpc/zpklp2bpc.sci b/DSP functions/zpklp2bpc/zpklp2bpc.sci new file mode 100644 index 0000000..29bf6e5 --- /dev/null +++ b/DSP functions/zpklp2bpc/zpklp2bpc.sci @@ -0,0 +1,92 @@ +function [Z2, P2, K2, AllpassNum,AllpassDen]= zpklp2bpc(Z, P ,K, Wo,Wt) +//Zero-pole-gain lowpass to complex bandpass frequency transformation +// +//Calling Sequences +// +//[Z2,P2,K2,AllpassNum,AllpassDen] = zpklp2bpc(Z,P,K,Wo,Wt) returns zeros, Z2, poles, P2, and gain factor, K2, of the target filter transformed from the real lowpass prototype by applying a first-order real lowpass to complex bandpass frequency transformation.It also returns the numerator, AllpassNum, and the denominator, AllpassDen, of the allpass mapping filter. The prototype lowpass filter is given with zeros, Z, poles, P, and gain factor, K. +// +//Input Parameters: +// Z: Zeros of the prototype filter +// P: Poles of the prototype filter +// K: Gain of the prototype filter +// Wo: Frequency value of the prototype filter to be transformed +// Wt: Desired frquency of the target filter +// +//Output Parameters: +// Z2: Zeros of the target filter +// P2: Poles of the target filter +// K2:Gain factor of the target filter +// AllpassNum: Numerator of the mapping filter +// AllpassDen: Denominator of the mapping filter +//Example: Design a prototype real IIR halfband filter using a standard elliptic approach +// +// [b, a] = ellip(3,0.1,30,0.409); +// z = roots(b); +// p = roots(a); +// k = b(1); +// [z2,p2,k2] = zpklp2bpc(z,p,k,0.5,[0.25, 0.35]); +// +//Author: Shrenik Nambiar +// +//References: 1. Constantinides, A.G., "Spectral transformations for digital filters," IEEE® Proceedings, vol. 117, no. 8, pp. 1585-1590, August 1970. +// +//Input Validaton Statement + if argn(2) ~=5 then + error("Number of input arguments should be 5"); + end + + if argn(1)<1 | argn(1)>5 then + error("Number of output arguments should be between 1 and 5"); + 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 + + if ~isscalar(K) then + error("K must be a scalar"); + 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); + + if or(AllpassNum~=1) | or(AllpassDen~=1) then + Z2=[]; + P2=[]; + K2=K*prod(AllpassNum(1)-Z*AllpassDen(1))/prod(AllpassNum(1)-P*AllpassDen(1)); + + for i=1:length(Z), + Z2 = [Z2, roots(AllpassNum - Z(i).*AllpassDen).']; + end + for i=1:length(P), + P2 = [P2, roots(AllpassNum - P(i).*AllpassDen).']; + end +// For stabilizing the target filter (if unstable after tranformation) + index = find(abs(P2)>1); + K2 = K2/prod(1-P2(index)); + P2(index) = 1 ./conj(P2(index)); + K2= K2*prod(1-P2(index)); + else + Z2=Z; + P2=P; + K2=K; + end + //Converting to Column vector + Z2=Z2(:); + P2=P2(:); + +endfunction diff --git a/DSP functions/zpklp2bs/test_1.sce b/DSP functions/zpklp2bs/test_1.sce new file mode 100644 index 0000000..7de7b73 --- /dev/null +++ b/DSP functions/zpklp2bs/test_1.sce @@ -0,0 +1,7 @@ +// Test # 1 : No Input Arguments +exec('./zpklp2bs.sci',-1); +[z,p,k,n,d]=zpklp2bs(); +//!--error 10000 +//Number of input arguments should be 5 +//at line 35 of function zpklp2bs called by : +//[z,p,k,n,d]=zpklp2bs(); diff --git a/DSP functions/zpklp2bs/test_2.sce b/DSP functions/zpklp2bs/test_2.sce new file mode 100644 index 0000000..8a83204 --- /dev/null +++ b/DSP functions/zpklp2bs/test_2.sce @@ -0,0 +1,5 @@ +// Test # 2 : Excess Input Arguments +exec('./zpklp2bs.sci',-1); +[z,p,k,n,d]=zpklp2bs(0.1,0.2,0.7,0.6,[0.5,0.9],12); +//!--error 58 +//Wrong number of input arguments diff --git a/DSP functions/zpklp2bs/test_3.sce b/DSP functions/zpklp2bs/test_3.sce new file mode 100644 index 0000000..d3867c0 --- /dev/null +++ b/DSP functions/zpklp2bs/test_3.sce @@ -0,0 +1,7 @@ +// Test # 3 : Checking the type for Input Argument #3 +exec('./zpklp2bs.sci',-1); +[z,p,k,n,d]=zpklp2bs(0.3,7,[0.5,0.9],0.1,[0.1,0.4]); +// !--error 10000 +//K must be a scalar +//at line 57 of function zpklp2bs called by : +//[z,p,k,n,d]=zpklp2bs(0.3,0.2,[0.5.6],0.4,[0.1,0.4]) diff --git a/DSP functions/zpklp2bs/test_4.sce b/DSP functions/zpklp2bs/test_4.sce new file mode 100644 index 0000000..f8df7c3 --- /dev/null +++ b/DSP functions/zpklp2bs/test_4.sce @@ -0,0 +1,5 @@ +// Test #4 : Incorrect number of output Arguments +exec('./zpklp2bs.sci',-1); +[z,p,k,n,d,e]=zpklp2bs(0.3,0.2,0.7,0.5,[0.4,0.8]); +//!--error 59 +//Wrong number of output arguments diff --git a/DSP functions/zpklp2bs/test_5.sce b/DSP functions/zpklp2bs/test_5.sce new file mode 100644 index 0000000..c3cc427 --- /dev/null +++ b/DSP functions/zpklp2bs/test_5.sce @@ -0,0 +1,7 @@ +// Test # 5 : When either Input Argument #4 or Input Argument #5 is of complex type +exec('./zpklp2bs.sci',-1); +[z,p,k,n,d]=zpklp2bs(3,0.2,7,2*%i,[0.6,0.8]); +// !--error 10000 +//Wo must be real ,numeric and scalar +//at line 43 of function zpklp2bs called by : +//[z,p,k,n,d]=zpklp2bs(3,0.2,7,2*%i,[0.6,0.8]); diff --git a/DSP functions/zpklp2bs/test_6.sce b/DSP functions/zpklp2bs/test_6.sce new file mode 100644 index 0000000..a4c0889 --- /dev/null +++ b/DSP functions/zpklp2bs/test_6.sce @@ -0,0 +1,7 @@ +// Test # 6 : Range test for Input Argument #4 or Input Argument #5 +exec('./zpklp2bs.sci',-1); +[z,p,k,n,d]=zpklp2bs(7.3,5.2,9.7,2.9,[4,0.8]); +//!--error 10000 +//Wo must lie between 0 and 1 +//at line 46 of function zpklp2bs called by : +//[z,p,k,n,d]=zpklp2bs(7.3,5.2,9.7,2.9,[4,0.8]); diff --git a/DSP functions/zpklp2bs/test_7.sce b/DSP functions/zpklp2bs/test_7.sce new file mode 100644 index 0000000..97114ac --- /dev/null +++ b/DSP functions/zpklp2bs/test_7.sce @@ -0,0 +1,7 @@ +// Test #7 : Length test for Input Argument #4 or Input Argument #5 +exec('./zpklp2bs.sci',-1); +[z,p,k,n,d]=zpklp2bs(9,[2 4],1,0.6,[0.4,0.7,0.9]); +//!--error 10000 +//Wt must be real and numeric and must contain only 2 elements +//at line 50 of function zpklp2bs called by : +//[z,p,k,n,d]=zpklp2bs(9,[2 4],1,0.6,[0.4,0.7,0.9]); diff --git a/DSP functions/zpklp2bs/test_8.sce b/DSP functions/zpklp2bs/test_8.sce new file mode 100644 index 0000000..98988f8 --- /dev/null +++ b/DSP functions/zpklp2bs/test_8.sce @@ -0,0 +1,20 @@ +// Test #8 : When output arguments are less than 5 +exec('./zpklp2bs.sci',-1); +[z,p,k]=zpklp2bs(2*%i,5*%i,7*%i,0.45,[0.2,0.87]); +disp(k); +disp(p); +disp(z); +// +//Scilab Output +//k= 0.1670254 + 2.8066528i +//p= -0.5873267 + 0.1669898i +// 0.4116470 - 0.2094615i +//z=-0.7081146 + 0.3208781i +// 0.5412291 - 0.4261818i +// +//Matlab Output +//z=-0.7081 + 0.3209i +// 0.5412 - 0.4262i +//p=-0.5873 + 0.1670i +// 0.4116 - 0.2095i +//k= 0.1670 + 2.8067i diff --git a/DSP functions/zpklp2bs/test_9.sce b/DSP functions/zpklp2bs/test_9.sce new file mode 100644 index 0000000..88a9074 --- /dev/null +++ b/DSP functions/zpklp2bs/test_9.sce @@ -0,0 +1,34 @@ +// Test #9 : Valid case +exec('./zpklp2bs.sci',-1); +[z,p,k,n,d]=zpklp2bs([2 4],[8 11],7*%i,0.21,[0.54,0.8]); +disp(d); +disp(n); +disp(k); +disp(p); +disp(z); +// +//Scilab Output +//d = 1. 0.9661716 0.7419182 +//n = 0.7419182 0.9661716 1. +//k = 0.3853727i +//p = -0.4659083 + 0.6803740i +// -0.4659083 - 0.6803740i +// -0.4709319 + 0.6901569i +// -0.4709319 - 0.6901569i +//z= -0.3839860 + 0.4869675i +// -0.3839860 - 0.4869675i +// -0.4448192 + 0.6372376i +// - 0.4448192 - 0.6372376i +// +//Matlab Output +//z=-0.3840 + 0.4870i +// -0.3840 - 0.4870i +// -0.4448 + 0.6372i +// -0.4448 - 0.6372i +//p=-0.4659 + 0.6804i +// -0.4659 - 0.6804i +// -0.4709 + 0.6902i +// -0.4709 - 0.6902i +//k=0.0000 + 0.3854i +//n= 0.7419 0.9662 1.0000 +//d= 1.0000 0.9662 0.7419 diff --git a/DSP functions/zpklp2bs/zpklp2bs.sci b/DSP functions/zpklp2bs/zpklp2bs.sci new file mode 100644 index 0000000..a0b9827 --- /dev/null +++ b/DSP functions/zpklp2bs/zpklp2bs.sci @@ -0,0 +1,92 @@ +function [Z2, P2, K2, AllpassNum,AllpassDen]= zpklp2bs(Z, P ,K, Wo,Wt) +//Zero-pole-gain lowpass to bandstop frequency transformation +// +//Calling Sequences +// +//[Z2,P2,K2,AllpassNum,AllpassDen] = zpklp2bs(Z,P,K,Wo,Wt) returns zeros, Z2, poles, P2, and gain factor, K2, of the target filter transformed from the real lowpass prototype by applying a second-order real lowpass to real bandstop frequency mapping.It also returns the numerator, AllpassNum, and the denominator, AllpassDen, of the allpass mapping filter. The prototype lowpass filter is given with zeros, Z, poles, P, and gain factor, K. +// +//Input Parameters: +// Z: Zeros of the prototype filter +// P: Poles of the prototype filter +// K: Gain of the prototype filter +// Wo: Frequency value of the prototype filter to be transformed +// Wt: Desired frquency of the target filter +// +//Output Parameters: +// Z2: Zeros of the target filter +// P2: Poles of the target filter +// K2:Gain factor of the target filter +// AllpassNum: Numerator of the mapping filter +// AllpassDen: Denominator of the mapping filter +//Example: Design a prototype real IIR halfband filter using a standard elliptic approach +// +// [b, a] = ellip(3,0.1,30,0.409); +// z = roots(b); +// p = roots(a); +// k = b(1); +// [z2,p2,k2] = zpklp2bs(z,p,k,0.5,[0.25, 0.35]); +// +//Author: Shrenik Nambiar +// +//References: 1. Constantinides, A.G., "Spectral transformations for digital filters," IEEE® Proceedings, vol. 117, no. 8, pp. 1585-1590, August 1970. +// +//Input Validaton Statement + if argn(2) ~=5 then + error("Number of input arguments should be 5"); + end + + if argn(1)<1 | argn(1)>5 then + error("Number of output arguments should be between 1-5"); + 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 + + if ~isscalar(K) then + error("K must be a scalar"); + end +// Calculating the numerator and denominator for the mapping filter + Wc = sum(Wt) / 2; + bw = max(Wt) - min(Wt); + al = cos(%pi*(Wo+bw)/2) / cos(%pi*(Wo-bw)/2); + be = cos(%pi*Wc) / cos(%pi*bw/2); + AllpassDen = [1 -be*(1+al) al]; + AllpassNum = flipdim(AllpassDen,2); + + if or(AllpassNum~=1) | or(AllpassDen~=1) then + Z2=[]; + P2=[]; + K2=K*prod(AllpassNum(1)-Z*AllpassDen(1))/prod(AllpassNum(1)-P*AllpassDen(1)); + + for i=1:length(Z), + Z2 = [Z2, roots(AllpassNum - Z(i).*AllpassDen).']; + end + for i=1:length(P), + P2 = [P2, roots(AllpassNum - P(i).*AllpassDen).']; + end +// For stabilizing the target filter (if unstable after tranformation) + index = find(abs(P2)>1); + K2 = K2/prod(1-P2(index)); + P2(index) = 1 ./conj(P2(index)); + K2= K2*prod(1-P2(index)); + else + Z2=Z; + P2=P; + K2=K; + end + //Converting to Column vector + Z2=Z2(:); + P2=P2(:); + +endfunction diff --git a/DSP functions/zpklp2bsc/test_1.sce b/DSP functions/zpklp2bsc/test_1.sce new file mode 100644 index 0000000..cf1c451 --- /dev/null +++ b/DSP functions/zpklp2bsc/test_1.sce @@ -0,0 +1,7 @@ +// Test # 1 : No Input Arguments +exec('./zpklp2bsc.sci',-1); +[z,p,k,n,d]=zpklp2bsc(); +//!--error 10000 +//Number of input arguments should be 5 +//at line 35 of function zpklp2bsc called by : +//[z,p,k,n,d]=zpklp2bsc(); diff --git a/DSP functions/zpklp2bsc/test_2.sce b/DSP functions/zpklp2bsc/test_2.sce new file mode 100644 index 0000000..92b5241 --- /dev/null +++ b/DSP functions/zpklp2bsc/test_2.sce @@ -0,0 +1,5 @@ +// Test # 2 : Excess Input Arguments +exec('./zpklp2bsc.sci',-1); +[z,p,k,n,d]=zpklp2bsc(0.1,0.2,0.7,0.6,[0.5,0.9],12); +//!--error 58 +//Wrong number of input arguments diff --git a/DSP functions/zpklp2bsc/test_3.sce b/DSP functions/zpklp2bsc/test_3.sce new file mode 100644 index 0000000..cb70f22 --- /dev/null +++ b/DSP functions/zpklp2bsc/test_3.sce @@ -0,0 +1,7 @@ +// Test # 3 : Checking the type for Input Argument #3 +exec('./zpklp2bsc.sci',-1); +[z,p,k,n,d]=zpklp2bsc(0.3,7,[0.5,0.9],0.1,[0.1,0.4]); +// !--error 10000 +//K must be a scalar +//at line 57 of function zpklp2bsc called by : +//[z,p,k,n,d]=zpklp2bsc(0.3,0.2,[0.5.6],0.4,[0.1,0.4]) diff --git a/DSP functions/zpklp2bsc/test_4.sce b/DSP functions/zpklp2bsc/test_4.sce new file mode 100644 index 0000000..fef52b7 --- /dev/null +++ b/DSP functions/zpklp2bsc/test_4.sce @@ -0,0 +1,5 @@ +// Test #4 : Incorrect number of output Arguments +exec('./zpklp2bsc.sci',-1); +[z,p,k,n,d,e]=zpklp2bsc(0.3,0.2,0.7,0.5,[0.4,0.8]); +//!--error 59 +//Wrong number of output arguments diff --git a/DSP functions/zpklp2bsc/test_5.sce b/DSP functions/zpklp2bsc/test_5.sce new file mode 100644 index 0000000..d32806a --- /dev/null +++ b/DSP functions/zpklp2bsc/test_5.sce @@ -0,0 +1,7 @@ +// Test # 5 : When either Input Argument #4 or Input Argument #5 is of complex type +exec('./zpklp2bsc.sci',-1); +[z,p,k,n,d]=zpklp2bsc(3,0.2,7,2*%i,[0.6,0.8]); +// !--error 10000 +//Wo must be real ,numeric and scalar +//at line 43 of function zpklp2bsc called by : +//[z,p,k,n,d]=zpklp2bsc(3,0.2,7,2*%i,[0.6,0.8]); diff --git a/DSP functions/zpklp2bsc/test_6.sce b/DSP functions/zpklp2bsc/test_6.sce new file mode 100644 index 0000000..05e1443 --- /dev/null +++ b/DSP functions/zpklp2bsc/test_6.sce @@ -0,0 +1,7 @@ +// Test # 6 : Range test for Input Argument #4 or Input Argument #5 +exec('./zpklp2bsc.sci',-1); +[z,p,k,n,d]=zpklp2bsc(7.3,5.2,9.7,2.9,[4,0.8]); +//!--error 10000 +//Wo must lie between 0 and 1 +//at line 46 of function zpklp2bsc called by : +//[z,p,k,n,d]=zpklp2bsc(7.3,5.2,9.7,2.9,[4,0.8]); diff --git a/DSP functions/zpklp2bsc/test_7.sce b/DSP functions/zpklp2bsc/test_7.sce new file mode 100644 index 0000000..2ecdd4f --- /dev/null +++ b/DSP functions/zpklp2bsc/test_7.sce @@ -0,0 +1,7 @@ +// Test #7 : Length test for Input Argument #4 or Input Argument #5 +exec('./zpklp2bsc.sci',-1); +[z,p,k,n,d]=zpklp2bsc(9,[2 4],1,0.6,[0.4,0.7,0.9]); +//!--error 10000 +//Wt must be real and numeric and must contain only 2 elements +//at line 50 of function zpklp2bsc called by : +//[z,p,k,n,d]=zpklp2bsc(9,[2 4],1,0.6,[0.4,0.7,0.9]); diff --git a/DSP functions/zpklp2bsc/test_8.sce b/DSP functions/zpklp2bsc/test_8.sce new file mode 100644 index 0000000..2aab3fb --- /dev/null +++ b/DSP functions/zpklp2bsc/test_8.sce @@ -0,0 +1,16 @@ +// Test #8 : When output arguments are less than 5 +exec('./zpklp2bsc.sci',-1); +[z,p,k]=zpklp2bsc(2,8,5.4,0.5,[0.12,0.7]); +disp(k); +disp(p); +disp(z); +// +//Scilab Output +//k= 1.1689223 +//p= 0.0633576 + 0.2180784i +//z= -0.0530585 - 0.1826287i +// +//Matlab Output +//z-0.0531 - 0.1826i +//p=0.0634 + 0.2181i +//k=1.1689 diff --git a/DSP functions/zpklp2bsc/test_9.sce b/DSP functions/zpklp2bsc/test_9.sce new file mode 100644 index 0000000..e22cc31 --- /dev/null +++ b/DSP functions/zpklp2bsc/test_9.sce @@ -0,0 +1,24 @@ +// Test #9 : Valid case +exec('./zpklp2bsc.sci',-1); +[z,p,k,n,d]=zpklp2bsc(2*%i,[8.2 9],2.3*%i,0.3,[0.4,0.93]); +disp(d); +disp(n); +disp(k); +disp(p); +disp(z); +// +//Scilab Output +//d = 1. 0.3132826-0.5492428i +//n =0.6323082 0.4954587-0.8686315i +//k= 0.0726422 + 0.0229661i +//p =-0.2739882 + 0.4803525i +// -0.2777450 + 0.4869388i +//z=-0.5930011 + 0.4889932i +// +//Matlab Output +//z=-0.5930 + 0.4890i +//p= -0.2740 + 0.4804i +// -0.2777 + 0.4869i +//k=0.0726 + 0.0230i +//n=0.6323 + 0.0000i 0.4955 - 0.8686i +//d=1.0000 + 0.0000i 0.3133 - 0.5492i diff --git a/DSP functions/zpklp2bsc/zpklp2bsc.sci b/DSP functions/zpklp2bsc/zpklp2bsc.sci new file mode 100644 index 0000000..d7183cc --- /dev/null +++ b/DSP functions/zpklp2bsc/zpklp2bsc.sci @@ -0,0 +1,92 @@ +function [Z2, P2, K2, AllpassNum,AllpassDen]= zpklp2bsc(Z, P ,K, Wo,Wt) +//Zero-pole-gain lowpass to complex bandstop frequency transformation +// +//Calling Sequences +// +//[Z2,P2,K2,AllpassNum,AllpassDen] = zpklp2bsc(Z,P,K,Wo,Wt) returns zeros, Z2, poles, P2, and gain factor, K2, of the target filter transformed from the real lowpass prototype by applying a first-order real lowpass to complex bandstop frequency transformation.It also returns the numerator, AllpassNum, and the denominator, AllpassDen, of the allpass mapping filter. The prototype lowpass filter is given with zeros, Z, poles, P, and gain factor, K. +// +//Input Parameters: +// Z: Zeros of the prototype filter +// P: Poles of the prototype filter +// K: Gain of the prototype filter +// Wo: Frequency value of the prototype filter to be transformed +// Wt: Desired frquency of the target filter +// +//Output Parameters: +// Z2: Zeros of the target filter +// P2: Poles of the target filter +// K2:Gain factor of the target filter +// AllpassNum: Numerator of the mapping filter +// AllpassDen: Denominator of the mapping filter +//Example: Design a prototype real IIR halfband filter using a standard elliptic approach +// +// [b, a] = ellip(3,0.1,30,0.409); +// z = roots(b); +// p = roots(a); +// k = b(1); +// [z2,p2,k2] = zpklp2bsc(z,p,k,0.5,[0.25, 0.35]); +// +//Author: Shrenik Nambiar +// +//References: 1. Constantinides, A.G., "Spectral transformations for digital filters," IEEE® Proceedings, vol. 117, no. 8, pp. 1585-1590, August 1970. +// +//Input Validaton Statement + if argn(2) ~=5 then + error("Number of input arguments should be 5"); + end + + if argn(1)<1 | argn(1)>5 then + error("Number of output arguments should be between 1-5"); + 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 + + if ~isscalar(K) then + error("K must be a scalar"); + end +// Calculating the numerator and denominator for the mapping filter + Wc = sum(Wt) / 2; + bw = max(Wt) - min(Wt); + al = cos(%pi*(Wo+bw/2)/2) / cos(%pi*(Wo-bw/2)/2); + be = exp(-%pi*%i*Wc); + AllpassNum = flipdim((conj([-be +al])),2); + AllpassDen = flipdim((conj([-al*be 1])),2); + + if or(AllpassNum~=1) | or(AllpassDen~=1) then + Z2=[]; + P2=[]; + K2=K*prod(AllpassNum(1)-Z*AllpassDen(1))/prod(AllpassNum(1)-P*AllpassDen(1)); + + for i=1:length(Z), + Z2 = [Z2, roots(AllpassNum - Z(i).*AllpassDen).']; + end + for i=1:length(P), + P2 = [P2, roots(AllpassNum - P(i).*AllpassDen).']; + end +// For stabilizing the target filter (if unstable after tranformation) + index = find(abs(P2)>1); + K2 = K2/prod(1-P2(index)); + P2(index) = 1. /conj(P2(index)); + K2= K2*prod(1-P2(index)); + else + Z2=Z; + P2=P; + K2=K; + end + //Converting to Column vector + Z2=Z2(:); + P2=P2(:); + +endfunction diff --git a/DSP functions/zpklp2hp/test_1.sce b/DSP functions/zpklp2hp/test_1.sce new file mode 100644 index 0000000..808d762 --- /dev/null +++ b/DSP functions/zpklp2hp/test_1.sce @@ -0,0 +1,7 @@ +// Test # 1 : No Input Arguments +exec('./zpklp2hp.sci',-1); +[z,p,k,n,d]=zpklp2hp(); +//!--error 10000 +//Number of input arguments should be 5 +//at line 35 of function zpklp2hp called by : +//[z,p,k,n,d]=zpklp2hp(); diff --git a/DSP functions/zpklp2hp/test_10.sce b/DSP functions/zpklp2hp/test_10.sce new file mode 100644 index 0000000..ad9aaee --- /dev/null +++ b/DSP functions/zpklp2hp/test_10.sce @@ -0,0 +1,26 @@ +// Test #10 : For complex vector inputs +exec('./zpklp2hp.sci',-1); +[z,p,k,n,d]=zpklp2hp([2*%i,0.4*%i],[%i,3*%i],1,0.2,0.7); +disp(d); +disp(n); +disp(k); +disp(p); +disp(z); +// +//Scilab Output +//d=1. - 0.2212317 +//n=0.2212317 - 1. +//k=0.2830084 + 0.0950556i +//p=0.4218182 + 0.9066804i +// 0.2444835 + 0.3153042i + //z=0.2731969 + 0.4697801i +// 1.2282212 + 1.8206962i +// +//Matlab Output +//z = 0.2732 + 0.4698i +// 1.2282 + 1.8207i +//p = 0.4218 + 0.9067i +// 0.2445 + 0.3153i +//k = 0.2830 + 0.0951i +//n = 0.2212 -1.0000 +//d = 1.0000 -0.2212 diff --git a/DSP functions/zpklp2hp/test_2.sce b/DSP functions/zpklp2hp/test_2.sce new file mode 100644 index 0000000..973f769 --- /dev/null +++ b/DSP functions/zpklp2hp/test_2.sce @@ -0,0 +1,5 @@ +// Test # 2 : Excess Input Arguments +exec('./zpklp2hp.sci',-1); +[z,p,k,n,d]=zpklp2hp(0.3,0.2,0.7,0.5,0.6,4); +//!--error 58 +//Wrong number of input arguments diff --git a/DSP functions/zpklp2hp/test_3.sce b/DSP functions/zpklp2hp/test_3.sce new file mode 100644 index 0000000..5e6c786 --- /dev/null +++ b/DSP functions/zpklp2hp/test_3.sce @@ -0,0 +1,7 @@ +// Test # 3 : Checking the type for Input Argument #3 +exec('./zpklp2hp.sci',-1); +[z,p,k,n,d]=zpklp2hp(0.3,0.2,[0.4 0.8],0.5,0.6); +// !--error 10000 +//K must be a scalar +//at line 57 of function zpklp2hp called by : +//[z,p,k,n,d]=zpklp2hp(0.3,0.2,[0.7,0.9],0.5,0.6) diff --git a/DSP functions/zpklp2hp/test_4.sce b/DSP functions/zpklp2hp/test_4.sce new file mode 100644 index 0000000..0061868 --- /dev/null +++ b/DSP functions/zpklp2hp/test_4.sce @@ -0,0 +1,5 @@ +// Test #4 : Incorrect number of output Arguments +exec('./zpklp2hp.sci',-1); +[z,p,k,n,d,e]=zpklp2hp(0.3,2,8,0.8,0.2); +//!--error 59 +//Wrong number of output arguments diff --git a/DSP functions/zpklp2hp/test_5.sce b/DSP functions/zpklp2hp/test_5.sce new file mode 100644 index 0000000..7ca5e9e --- /dev/null +++ b/DSP functions/zpklp2hp/test_5.sce @@ -0,0 +1,7 @@ +// Test # 5 : When either Input Argument #4 or Input Argument #5 is of complex type +exec('./zpklp2hp.sci',-1); +[z,p,k,n,d]=zpklp2hp(2,3,4,%i,0.7); +//!--error 10000 +//Wo must be real ,numeric and scalar +//at line 43 of function zpklp2hp called by : +//[z,p,k,n,d]=zpklp2hp(2,3,4,%i,0.7); diff --git a/DSP functions/zpklp2hp/test_6.sce b/DSP functions/zpklp2hp/test_6.sce new file mode 100644 index 0000000..8c1d63a --- /dev/null +++ b/DSP functions/zpklp2hp/test_6.sce @@ -0,0 +1,7 @@ +// Test # 6 : Range test for Input Argument #4 or Input Argument #5 +exec('./zpklp2hp.sci',-1); +[z,p,k,n,d]=zpklp2hp(2,3,4,0.4,7); +//!--error 10000 +//Wt must lie between 0 and 1 +//at line 53 of function zpklp2hp called by : +//[z,p,k,n,d]=zpklp2hp(2,3,4,0.4,7); diff --git a/DSP functions/zpklp2hp/test_7.sce b/DSP functions/zpklp2hp/test_7.sce new file mode 100644 index 0000000..5d6fa52 --- /dev/null +++ b/DSP functions/zpklp2hp/test_7.sce @@ -0,0 +1,7 @@ +// Test #7 : Length test for Input Argument #4 or Input Argument #5 +exec('./zpklp2hp.sci',-1); +[z,p,k,n,d]=zpklp2hp(2,3,4,[0.4,7],0.9); +//!--error 10000 +//Wo must be real ,numeric and scalar +//at line 43 of function zpklp2hp called by : +//[z,p,k,n,d]=zpklp2hp(2,3,4,[0.4,7],0.9); diff --git a/DSP functions/zpklp2hp/test_8.sce b/DSP functions/zpklp2hp/test_8.sce new file mode 100644 index 0000000..3c95645 --- /dev/null +++ b/DSP functions/zpklp2hp/test_8.sce @@ -0,0 +1,16 @@ +// Test #8 : When output arguments are less than 5 +exec('./zpklp2hp.sci',-1); +[z,p,k]=zpklp2hp(2,3,4,0.4,0.9); +disp(k); +disp(p); +disp(z); +// +//Scilab Output +//k=2.9017143 +//p=- 0.8034286 +//z=- 0.8645136 +// +//Matlab Output +//z = -0.8645 +//p = -0.8034 +//k = 2.9017 diff --git a/DSP functions/zpklp2hp/test_9.sce b/DSP functions/zpklp2hp/test_9.sce new file mode 100644 index 0000000..e8f8d83 --- /dev/null +++ b/DSP functions/zpklp2hp/test_9.sce @@ -0,0 +1,22 @@ +// Test #9 : For vector inputs +exec('./zpklp2hp.sci',-1); +[z,p,k,n,d]=zpklp2hp([2,4],[1,7.2],8,0.32,0.67); +disp(d); +disp(n); +disp(k); +disp(p); +disp(z); +// +//Scilab Output +//d=1. -0.0184220 +//n=0.0184220 -1. +//k=8.9538886 +//p=- 1. - 0.1207759 +//z=- 0.4860551 - 0.2326495 +// +//Matlab Output +//z = -0.4861 -0.2326 +//p = -1.0000 -0.1208 +//k = 8.9539 +//n = 0.0184 -1.0000 +//d = 1.0000 -0.0184 diff --git a/DSP functions/zpklp2hp/zpklp2hp.sci b/DSP functions/zpklp2hp/zpklp2hp.sci new file mode 100644 index 0000000..e66a0d7 --- /dev/null +++ b/DSP functions/zpklp2hp/zpklp2hp.sci @@ -0,0 +1,91 @@ +function [Z2, P2, K2, AllpassNum,AllpassDen]= zpklp2hp(Z, P ,K, Wo,Wt) +//Zero-pole-gain lowpass to highpass frequency transformation +// +//Calling Sequences +// +//[Z2,P2,K2,AllpassNum,AllpassDen] = zpklp2hp(Z,P,K,Wo,Wt) returns zeros, Z2, poles, P2, and gain factor, K2, of the target filter transformed from the real lowpass prototype by applying a first-order real lowpass to real highpass frequency mapping. This transformation effectively places one feature of an original filter, located at frequency Wo, at the required target frequency location, Wt, at the same time rotating the whole frequency response by half of the sampling frequency. Result is that the DC and Nyquist features swap places.It also returns the numerator, AllpassNum, and the denominator, AllpassDen, of the allpass mapping filter. The prototype lowpass filter is given with zeros, Z, poles, P, and the gain factor, K. +// +//Input Parameters: +// Z: Zeros of the prototype filter +// P: Poles of the prototype filter +// K: Gain of the prototype filter +// Wo: Frequency value of the prototype filter to be transformed +// Wt: Desired frquency of the target filter +// +//Output Parameters: +// Z2: Zeros of the target filter +// P2: Poles of the target filter +// K2:Gain factor of the target filter +// AllpassNum: Numerator of the mapping filter +// AllpassDen: Denominator of the mapping filter +//Example: Design a prototype real IIR halfband filter using a standard elliptic approach +// +// [b, a] = ellip(3,0.1,30,0.409); +// z = roots(b); +// p = roots(a); +// k = b(1); +// [z2,p2,k2] = zpklp2hp(z,p,k,0.5,0.35); +// +//Author: Shrenik Nambiar +// +//References: 1. Constantinides, A.G., "Spectral transformations for digital filters," IEEE® Proceedings, vol. 117, no. 8, pp. 1585-1590, August 1970. +// +//Input Validaton Statement + if argn(2) ~=5 then + error("Number of input arguments should be 5"); + end + + if argn(1) <1 | argn(1)>5 then + error("Number of output arguments should be between 1 to 5"); + 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 ~isscalar(Wt) | ~isreal(Wt) then + error("Wt must be real,numeric and scalar"); + end + if Wt<=0 | Wt>=1 then + error("Wt must lie between 0 and 1"); + end + + if ~isscalar(K) then + error("K must be a scalar"); + end +// Calculating the numerator and denominator for the mapping filter + al = -cos(%pi*(Wo+Wt)/2) / cos(%pi*(Wo-Wt)/2); + AllpassNum = [-al -1]; + AllpassDen = flipdim(-AllpassNum,2); + + if or(AllpassNum~=1) | or(AllpassDen~=1) then + Z2=[]; + P2=[]; + K2=K*prod(AllpassNum(1)-Z*AllpassDen(1))/prod(AllpassNum(1)-P*AllpassDen(1)); + + for i=1:length(Z), + Z2 = [Z2, roots(AllpassNum - Z(i).*AllpassDen).']; + end + for i=1:length(P), + P2 = [P2, roots(AllpassNum - P(i).*AllpassDen).']; + end +// For stabilizing the target filter (if unstable after tranformation) + //Z2 = Z2; + //P2 = P2; + index = find(abs(P2)>1); + K2 = K2/prod(1-P2(index)); + P2(index) = 1 ./conj(P2(index)); + K2= K2*prod(1-P2(index)); + else + Z2=Z; + P2=P; + K2=K; + end + //Converting to Column vector + Z2=Z2(:); + P2=P2(:); + +endfunction diff --git a/DSP functions/zpklp2lp/test_1.sce b/DSP functions/zpklp2lp/test_1.sce new file mode 100644 index 0000000..8d75003 --- /dev/null +++ b/DSP functions/zpklp2lp/test_1.sce @@ -0,0 +1,7 @@ +// Test # 1 : No Input Arguments +exec('./zpklp2lp.sci',-1); +[z,p,k,n,d]=zpklp2lp(); +//!--error 10000 +//Number of input arguments should be 5 +//at line 35 of function zpklp2lp called by : +//[z,p,k,n,d]=zpklp2lp(); diff --git a/DSP functions/zpklp2lp/test_10.sce b/DSP functions/zpklp2lp/test_10.sce new file mode 100644 index 0000000..4a5b232 --- /dev/null +++ b/DSP functions/zpklp2lp/test_10.sce @@ -0,0 +1,24 @@ +// Test #10 : Valid Input case #2 +exec('./zpklp2lp.sci',-1); +[z,p,k,n,d]=zpklp2lp([4*%i,3],2*%i,0.23,0.1,0.5); +disp(d); +disp(n); +disp(k); +disp(p); +disp(z); +// +//Scilab Output +//d=1. 0.7265425 +//n=0.7265425 1. +//k=-0.9848307 + 0.1678079i +//p=-0.8023016 - 0.2085469i +//z=-0.7472970 - 0.1142642i +// -0.5188694 +// +//Matlab Output +//z=-0.7473 - 0.1143i +// -0.5189 + 0.0000i +//p= -0.8023 - 0.2085i +//k= -0.9848 + 0.1678i +//n= 0.7265 1.0000 +//d= 1.0000 0.7265 diff --git a/DSP functions/zpklp2lp/test_2.sce b/DSP functions/zpklp2lp/test_2.sce new file mode 100644 index 0000000..996323b --- /dev/null +++ b/DSP functions/zpklp2lp/test_2.sce @@ -0,0 +1,5 @@ +// Test # 2 : Excess Input Arguments +exec('./zpklp2lp.sci',-1); +[z,p,k,n,d]=zpklp2lp(0.3,0.2,0.7,0.5,0.6,4); +//!--error 58 +//Wrong number of input arguments diff --git a/DSP functions/zpklp2lp/test_3.sce b/DSP functions/zpklp2lp/test_3.sce new file mode 100644 index 0000000..00351a5 --- /dev/null +++ b/DSP functions/zpklp2lp/test_3.sce @@ -0,0 +1,5 @@ +// Test # 3 : Incorrect number of output Arguments +exec('./zpklp2lp.sci',-1); +[z,p,k,n,d,e]=zpklp2lp(0.3,2,8,0.8,0.2); +//!--error 59 +//Wrong number of output arguments diff --git a/DSP functions/zpklp2lp/test_4.sce b/DSP functions/zpklp2lp/test_4.sce new file mode 100644 index 0000000..c162f8a --- /dev/null +++ b/DSP functions/zpklp2lp/test_4.sce @@ -0,0 +1,7 @@ +// Test # 4 : Checking the type for Input Argument #3 +exec('./zpklp2lp.sci',-1); +[z,p,k,n,d]=zpklp2lp(0.43,0.2,[0.2 0.4],0.1,0.6); +// !--error 10000 +//K must be a scalar +//at line 57 of function zpklp2lp called by : +//[z,p,k,n,d]=zpklp2hp(0.43,0.2,[0.2,0.4],0.1,0.6) diff --git a/DSP functions/zpklp2lp/test_5.sce b/DSP functions/zpklp2lp/test_5.sce new file mode 100644 index 0000000..9f027a5 --- /dev/null +++ b/DSP functions/zpklp2lp/test_5.sce @@ -0,0 +1,7 @@ +// Test # 5 : When either Input Argument #4 or Input Argument #5 is of complex type +exec('./zpklp2lp.sci',-1); +[z,p,k,n,d]=zpklp2lp(2,3,4,%i,0.7); +//!--error 10000 +//Wo must be real ,numeric and scalar +//at line 43 of function zpklp2hp called by : +//[z,p,k,n,d]=zpklp2lp(2,3,4,%i,0.7); diff --git a/DSP functions/zpklp2lp/test_6.sce b/DSP functions/zpklp2lp/test_6.sce new file mode 100644 index 0000000..f239d86 --- /dev/null +++ b/DSP functions/zpklp2lp/test_6.sce @@ -0,0 +1,7 @@ +// Test # 6 : Range test for Input Argument #4 or Input Argument #5 +exec('./zpklp2hp.sci',-1); +[z,p,k,n,d]=zpklp2hp(2,3,4,0.4,7); +//!--error 10000 +//Wt must lie between 0 and 1 +//at line 53 of function zpklp2lp called by : +//[z,p,k,n,d]=zpklp2lp(2,3,4,0.4,7); diff --git a/DSP functions/zpklp2lp/test_7.sce b/DSP functions/zpklp2lp/test_7.sce new file mode 100644 index 0000000..7db5166 --- /dev/null +++ b/DSP functions/zpklp2lp/test_7.sce @@ -0,0 +1,7 @@ +// Test #7 : Length test for Input Argument #4 or Input Argument #5 +exec('./zpklp2lp.sci',-1); +[z,p,k,n,d]=zpklp2lp(2,3,4,[0.4,7],0.9); +//!--error 10000 +//Wo must be real ,numeric and scalar +//at line 43 of function zpklp2lp called by : +//[z,p,k,n,d]=zpklp2lp(2,3,4,[0.4,7],0.9); diff --git a/DSP functions/zpklp2lp/test_8.sce b/DSP functions/zpklp2lp/test_8.sce new file mode 100644 index 0000000..7312872 --- /dev/null +++ b/DSP functions/zpklp2lp/test_8.sce @@ -0,0 +1,16 @@ +// Test #8 : When output arguments are less than 5 +exec('./zpklp2lp.sci',-1); +[z,p,k]=zpklp2lp(4,0.9,8,0.1,0.5); +disp(k); +disp(p); +disp(z); +// +//Scilab Output +//k=- 75.662446 +//p=0.5011603 +//z=-0.5823109 +// +//Matlab Output +//z= -0.5823 +//p= 0.5012 +//k= -75.6624 diff --git a/DSP functions/zpklp2lp/test_9.sce b/DSP functions/zpklp2lp/test_9.sce new file mode 100644 index 0000000..7771b5e --- /dev/null +++ b/DSP functions/zpklp2lp/test_9.sce @@ -0,0 +1,22 @@ +// Test #9 : Valid Input case #1 +exec('./zpklp2lp.sci',-1); +[z,p,k,n,d]=zpklp2lp(1,9,2,0.4,0.8); +disp(d); +disp(n); +disp(k); +disp(p); +disp(z); +// +//Scilab Output +//d=1. 0.6180340 +//n=0.6180340 1. +//k=0.0911400 +//p=-0.5443002 +//z=1. +// +//Matlab Output +//d=1.0000 0.6180 +//n=0.6180 1.0000 +//k=0.0911 +//p=-0.5443 +//z=1.0000 diff --git a/DSP functions/zpklp2lp/zpklp2lp.sci b/DSP functions/zpklp2lp/zpklp2lp.sci new file mode 100644 index 0000000..9e12db3 --- /dev/null +++ b/DSP functions/zpklp2lp/zpklp2lp.sci @@ -0,0 +1,89 @@ +function [Z2, P2, K2, AllpassNum,AllpassDen]= zpklp2lp(Z, P ,K, Wo,Wt) +//Zero-pole-gain lowpass to lowpass frequency transformation +// +//Calling Sequences +// +//[Z2,P2,K2,AllpassNum,AllpassDen] = zpklp2lp(Z,P,K,Wo,Wt) returns zeros, Z2, poles, P2, and gain factor, K2, of the target filter transformed from the real lowpass prototype by applying a first-order real lowpass to real lowpass frequency mapping. This transformation effectively places one feature of an original filter, located at frequency Wo, at the required target frequency location, Wt.It also returns the numerator, AllpassNum, and the denominator, AllpassDen, of the allpass mapping filter. The prototype lowpass filter is given with zeros, Z, poles, P, and gain factor, K. +// +//Input Parameters: +// Z: Zeros of the prototype filter +// P: Poles of the prototype filter +// K: Gain of the prototype filter +// Wo: Frequency value of the prototype filter to be transformed +// Wt: Desired frquency of the target filter +// +//Output Parameters: +// Z2: Zeros of the target filter +// P2: Poles of the target filter +// K2:Gain factor of the target filter +// AllpassNum: Numerator of the mapping filter +// AllpassDen: Denominator of the mapping filter +//Example: Design a prototype real IIR halfband filter using a standard elliptic approach +// +// [b, a] = ellip(3,0.1,30,0.409); +// z = roots(b); +// p = roots(a); +// k = b(1); +// [z2,p2,k2] = zpklp2lp(z,p,k,0.5,0.35); +// +//Author: Shrenik Nambiar +// +//References: 1. Constantinides, A.G., "Spectral transformations for digital filters," IEEE® Proceedings, vol. 117, no. 8, pp. 1585-1590, August 1970. +// +//Input Validaton Statement + if argn(2) ~=5 then + error("Number of input arguments should be 5"); + end + + if argn(1) <1 |argn(1)>5 then + error("Number of output arguments should lie between 1 and 5"); + 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 ~isscalar(Wt) | ~isreal(Wt) then + error("Wt must be real,numeric and scalar"); + end + if Wt<=0 | Wt>=1 then + error("Wt must lie between 0 and 1"); + end + + if ~isscalar(K) then + error("K must be a scalar"); + end +// Calculating the numerator and denominator for the mapping filter + al = sin(%pi*(Wo-Wt)/2) / sin(%pi*(Wo+Wt)/2); + AllpassNum = [-al 1]; + AllpassDen = [1 -al]; + + if or(AllpassNum~=1) | or(AllpassDen~=1) then + Z2=[]; + P2=[]; + K2=K*prod(AllpassNum(1)-Z*AllpassDen(1))/prod(AllpassNum(1)-P*AllpassDen(1)); + + for i=1:length(Z), + Z2 = [Z2, roots(AllpassNum - Z(i).*AllpassDen).']; + end + for i=1:length(P), + P2 = [P2, roots(AllpassNum - P(i).*AllpassDen).']; + end +// For stabilizing the target filter (if unstable after tranformation) + index = find(abs(P2)>1); + K2 = K2/prod(1-P2(index)); + P2(index) = 1. /conj(P2(index)); + K2= K2*prod(1-P2(index)); + else + Z2=Z; + P2=P; + K2=K; + end + //Converting to Column vector + Z2=Z2(:); + P2=P2(:); + +endfunction diff --git a/DSP functions/zpklp2mb/test_1.sce b/DSP functions/zpklp2mb/test_1.sce new file mode 100644 index 0000000..3461e55 --- /dev/null +++ b/DSP functions/zpklp2mb/test_1.sce @@ -0,0 +1,7 @@ +// Test # 1 : No Input Arguments +exec('./zpklp2mb.sci',-1); +[z,p,k,n,d]=zpklp2mb(); +//!--error 10000 +//Number of input arguments should either be 5 or 6 +//at line 37 of function zpklp2mb called by : +//[z,p,k,n,d]=zpklp2mb(); diff --git a/DSP functions/zpklp2mb/test_10.sce b/DSP functions/zpklp2mb/test_10.sce new file mode 100644 index 0000000..ffc821e --- /dev/null +++ b/DSP functions/zpklp2mb/test_10.sce @@ -0,0 +1,42 @@ +// Test #10 : For vector inputs +exec('./zpklp2mb.sci',-1); +[z,p,k,n,d]=zpklp2mb([1,7],[8,10],6,0.6,[0.3,0.4,0.5]); +disp(d); +disp(n); +disp(k); +disp(p); +disp(z); +// +//Scilab Output +//d=1. - 0.8968022 1.093096 -0.3090170 +//n=0.3090170 - 1.093096 0.8968022 -1. +//k=0.3721850 +//p=0.2886874 + 0.9021628i +// 0.2886874 - 0.9021628i +// 0.2133332 +// 0.2862009 + 0.9033321i +// 0.2862009 - 0.9033321i +// 0.2402018 +//z =-1. +// 0.3579605 + 0.9337367i +// 0.3579605 - 0.9337367i +// 0.2905218 + 0.9014069i +// 0.2905218 - 0.9014069i +// 0.1938082 +// +//Matlab Output +//z = -1.0000 + 0.0000i +// 0.3580 + 0.9337i +// 0.3580 - 0.9337i +// 0.2905 + 0.9014i +// 0.2905 - 0.9014i +// 0.1938 + 0.0000i +//p = 0.2887 + 0.9022i +// 0.2887 - 0.9022i +// 0.2133 + 0.0000i +// 0.2862 + 0.9033i +// 0.2862 - 0.9033i +// 0.2402 + 0.0000i +//k = 0.3722 +//n = 0.3090 -1.0931 0.8968 -1.0000 +//d = 1.0000 -0.8968 1.0931 -0.3090 diff --git a/DSP functions/zpklp2mb/test_11.sce b/DSP functions/zpklp2mb/test_11.sce new file mode 100644 index 0000000..7b58fa4 --- /dev/null +++ b/DSP functions/zpklp2mb/test_11.sce @@ -0,0 +1,34 @@ +// Test #11 : For complex vector inputs +exec('./zpklp2mb.sci',-1); +[z,p,k,n,d]=zpklp2mb([2*%i,4*%i],[4*%i,7.6*%i],1,0.2,[0.3 0.4]); +disp(d); +disp(n); +disp(k); +disp(p); +disp(z); +// +//Scilab Output +//d=1. - 0.8743054 0.9021130 +//n=-0.9021130 0.8743054 - 1. +//k=0.2733954 - 0.0862473i +//p=0.4602843 + 0.8380684i +// 0.4186129 - 0.8584286i +// 0.4492345 + 0.8391150i +// 0.4263890 - 0.8502195i +//z=0.4809243 + 0.8426991i +// 0.4094194 - 0.8782564i +// 0.4602843 + 0.8380684i +// 0.4186129 - 0.8584286i +// +//Matlab Output +//z = 0.4809 + 0.8427i +// 0.4094 - 0.8783i +// 0.4603 + 0.8381i +// 0.4186 - 0.8584i +//p = 0.4603 + 0.8381i +// 0.4186 - 0.8584i +// 0.4492 + 0.8391i +// 0.4264 - 0.8502i +//k = 0.2734 - 0.0862i +//n = -0.9021 0.8743 -1.0000 +//d = 1.0000 -0.8743 0.9021 diff --git a/DSP functions/zpklp2mb/test_12.sce b/DSP functions/zpklp2mb/test_12.sce new file mode 100644 index 0000000..1293c47 --- /dev/null +++ b/DSP functions/zpklp2mb/test_12.sce @@ -0,0 +1,34 @@ +// Test #12 : For complex vector inputs including flag +exec('./zpklp2mb.sci',-1); +[z,p,k,n,d]=zpklp2mb([%i,4*%i],[3*%i,7*%i],4,0.6,[0.1 0.6],'stop'); +disp(d); +disp(n); +disp(k); +disp(p); +disp(z); +// +//Scilab Output +//d=1. - 0.5403505 - 0.1583844 +//n=- 0.1583844 - 0.5403505 1. +//k=0.7650736 - 0.0932510i +//p=0.8086215 - 0.1432355i +// -0.2792558 + 0.3513001i +// 0.7646324 - 0.0715126i +// -0.2263041 + 0.1608860i +//z=0.9710158 - 0.2390153i +// - 0.5273774 + 0.8496311i +// 0.7874479 - 0.1156085i +// - 0.2532839 + 0.2718469i +// +//Matlab Output +//z = 0.9710 - 0.2390i +// -0.5274 + 0.8496i +// 0.7874 - 0.1156i +// -0.2533 + 0.2718i +//p = 0.8086 - 0.1432i +// -0.2793 + 0.3513i +// 0.7646 - 0.0715i +// -0.2263 + 0.1609i +//k = 0.7651 - 0.0933i +//n = -0.1584 -0.5404 1.0000 +//d = 1.0000 -0.5404 -0.1584 diff --git a/DSP functions/zpklp2mb/test_2.sce b/DSP functions/zpklp2mb/test_2.sce new file mode 100644 index 0000000..25a0cf0 --- /dev/null +++ b/DSP functions/zpklp2mb/test_2.sce @@ -0,0 +1,7 @@ +// Test # 2 : Excess Input Arguments +exec('./zpklp2mb.sci',-1); +[z,p,k,n,d]=zpklp2mb(0.3,0.2,0.7,0.5,0.6,'pass',3); +// !--error 10000 +//Number of input arguments should either be 5 or 6 +//at line 37 of function zpklp2mb called by : +//zpklp2mb(0.2,0.7,0.5,0.6,'pass',3); diff --git a/DSP functions/zpklp2mb/test_3.sce b/DSP functions/zpklp2mb/test_3.sce new file mode 100644 index 0000000..d54c9e5 --- /dev/null +++ b/DSP functions/zpklp2mb/test_3.sce @@ -0,0 +1,5 @@ +// Test # 3 : Incorrect number of output Arguments +exec('./zpklp2mb.sci',-1); +[z,p,k,n,d,e]=zpklp2mb(0.3,2,8,0.8,0.2); +//!--error 59 +//Wrong number of output arguments diff --git a/DSP functions/zpklp2mb/test_4.sce b/DSP functions/zpklp2mb/test_4.sce new file mode 100644 index 0000000..7372cb6 --- /dev/null +++ b/DSP functions/zpklp2mb/test_4.sce @@ -0,0 +1,7 @@ +// Test # 4 : Checking the type for Input Argument #3 +exec('./zpklp2mb.sci',-1); +[z,p,k,n,d]=zpklp2mb(0.1,2,[3 0.4],0.1,0.6); +// !--error 10000 +//K must be a scalar +//at line 63 of function zpklp2mb called by : +//[z,p,k,n,d]=zpklp2mb(0.1,2,[3 0.4],0.1,0.6); diff --git a/DSP functions/zpklp2mb/test_5.sce b/DSP functions/zpklp2mb/test_5.sce new file mode 100644 index 0000000..6c04740 --- /dev/null +++ b/DSP functions/zpklp2mb/test_5.sce @@ -0,0 +1,7 @@ +// Test # 5 : When either Input Argument #4 or Input Argument #5 is of complex type +exec('./zpklp2mb.sci',-1); +[z,p,k,n,d]=zpklp2mb(2,3,1,8.22*%i,0.2); +//!--error 10000 +//Wo must be real ,numeric and scalar +//at line 45 of function zpklp2mb called by : +//[z,p,k,n,d]=zpklp2mb(2,3,1,8.22*%i,0.2); diff --git a/DSP functions/zpklp2mb/test_6.sce b/DSP functions/zpklp2mb/test_6.sce new file mode 100644 index 0000000..d290e88 --- /dev/null +++ b/DSP functions/zpklp2mb/test_6.sce @@ -0,0 +1,7 @@ +// Test # 6 : Range test for Input Argument #4 or Input Argument #5 +exec('./zpklp2mb.sci',-1); +[z,p,k,n,d]=zpklp2mb(0.2,1,4,4,0.7); +//!--error 10000 +//Wo must lie between 0 and 1 +//at line 48 of function zpklp2mb called by : +//[z,p,k,n,d]=zpklp2mb(0.2,1,4,4,0.7); diff --git a/DSP functions/zpklp2mb/test_7.sce b/DSP functions/zpklp2mb/test_7.sce new file mode 100644 index 0000000..6dc88ac --- /dev/null +++ b/DSP functions/zpklp2mb/test_7.sce @@ -0,0 +1,7 @@ +// Test #7 : Length test for Input Argument #4 +exec('./zpklp2mb.sci',-1); +[z,p,k,n,d]=zpklp2mb(2,3.3,9.8,[0.4,0.9],0.8); +//!--error 10000 +//Wo must be real ,numeric and scalar +//at line 45 of function zpklp2mb called by : +//[z,p,k,n,d]=zpklp2mb(2,3.3,9.8,[0.4,0.9],0.8); diff --git a/DSP functions/zpklp2mb/test_8.sce b/DSP functions/zpklp2mb/test_8.sce new file mode 100644 index 0000000..c90b8ef --- /dev/null +++ b/DSP functions/zpklp2mb/test_8.sce @@ -0,0 +1,7 @@ +//Test #8 : Wrong flag input +exec('./zpklp2mb.sci',-1); +//[z,p,k]=zpklp2mb(4,0.9,8,0.1,[0.5 0.6],'oi'); +//!--error 10000 +//Invalid option,input should be either pass or stop +//at line 80 of function zpklp2mb called by : +//[z,p,k]=zpklp2mb(4,0.9,8,0.1,[0.5 0.6],'oi'); diff --git a/DSP functions/zpklp2mb/test_9.sce b/DSP functions/zpklp2mb/test_9.sce new file mode 100644 index 0000000..0105d6b --- /dev/null +++ b/DSP functions/zpklp2mb/test_9.sce @@ -0,0 +1,20 @@ +// Test #9 : When output arguments are less than 5 +exec('./zpklp2mb.sci',-1); +[z,p,k]=zpklp2mb(4,9,3.5,0.1,[0.5,0.8]); +disp(k); +disp(p); +disp(z); +// +//Scilab Output +//k=1.7234676 +//p= -0.4786251 + 0.8059946i +// - 0.4786251 - 0.8059946i +//z= -0.4859934 + 0.8194156i +// - 0.4859934 - 0.8194156i +// +//Matlab Output +//z = -0.4860 + 0.8194i +// -0.4860 - 0.8194i +//p = -0.4786 + 0.8060i +// -0.4786 - 0.8060i +//k = 1.7235 diff --git a/DSP functions/zpklp2mb/zpklp2mb.sci b/DSP functions/zpklp2mb/zpklp2mb.sci new file mode 100644 index 0000000..dd77aaf --- /dev/null +++ b/DSP functions/zpklp2mb/zpklp2mb.sci @@ -0,0 +1,116 @@ +function [Z2, P2, K2, AllpassNum,AllpassDen]= zpklp2mb(Z, P ,K, Wo,Wt,varargin) +//Zero-pole-gain lowpass to M-band frequency transformation +// +//Calling Sequences +// +//[Z2,P2,K2,AllpassNum,AllpassDen] = zpklp2mb(Z,P,K,Wo,Wt) returns zeros, Z2, poles, P2, and gain factor, K2, of the target filter transformed from the real lowpass prototype by applying an Mth-order real lowpass to real multibandpass frequency mapping. By default the DC feature is kept at its original location. +// +//[Z2,P2,K2,AllpassNum,AllpassDen] = zpklp2mb(Z,P,K,Wo,Wt,Pass) allows you to specify an additional parameter, Pass, which chooses between using the "DC Mobility" and the "Nyquist Mobility". In the first case the Nyquist feature stays at its original location and the DC feature is free to move. In the second case the DC feature is kept at an original frequency and the Nyquist feature is allowed to move.It also returns the numerator, AllpassNum, and the denominator, AllpassDen, of the allpass mapping filter. The prototype lowpass filter is given with zeros, Z, poles, P, and gain factor, K. +// +//Input Parameters: +// Z: Zeros of the prototype filter +// P: Poles of the prototype filter +// K: Gain of the prototype filter +// Wo: Frequency value of the prototype filter to be transformed +// Wt: Desired frquency of the target filter +// Pass: Choice ('pass'/'stop') of passband/stopband at DC, 'pass' being the default +//Output Parameters: +// Z2: Zeros of the target filter +// P2: Poles of the target filter +// K2:Gain factor of the target filter +// AllpassNum: Numerator of the mapping filter +// AllpassDen: Denominator of the mapping filter +//Example: Design a prototype real IIR halfband filter using a standard elliptic approach +// +// [b, a] = ellip(3,0.1,30,0.409); +// z = roots(b); +// p = roots(a); +// k = b(1); +// [z1,p1,k1] = zpklp2mb(z, p, k, 0.5, [2 4 6 8]/10, 'pass'); +// +//Author: Shrenik Nambiar +// +//References: 1. Franchitti, J.C., "All-pass filter interpolation and frequency transformation problems," MSc Thesis, Dept. of Electrical and Computer Engineering, University of Colorado, 1985 +// +//Input Validaton Statement + if argn(2)<5 | argn(2) >6 then + error("Number of input arguments should either be 5 or 6"); + end + + if argn(1)<1 | argn(1)>5 then + error("Number of output arguments should lie between 1 and 5"); + 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 ~isreal(Wt) then + error("Wt must real"); + end + + + for i= 1:length(Wt) + if Wt(i) <=0 | Wt(i) >=1 then + error("Wt must be in normalised form"); + end + end + + if ~isscalar(K) then + error("K must be a scalar"); + end +// Flag checking + if (length(varargin)==1) & (type(varargin(1))~=10) then + error("Input argument #6 must be of type char"); + end + + if length(varargin)==0 then + pass= -1; //pass being the default option + else + Pa=varargin(1); + select Pa + case 'pass' then + pass=-1; + case 'stop' then + pass=1; + else + error("Invalid option,input should be either pass or stop"); + end + end + l=length(Wt) +// Calculating the numerator and denominator for the mapping filter + Wold =%pi * Wo * (-1).^(0:l-1); + Wnew =%pi * Wt(:).'; + al=sin(Wnew.'/2*(l-2:-2:-l)-Wold.'/2*ones(1,l)); + AllpassDen =[1 -sin(l*Wnew/2-Wold/2)/al']; + AllpassNum = (flipdim((AllpassDen),2))*pass; + + if or(AllpassNum~=1) | or(AllpassDen~=1) then + Z2=[]; + P2=[]; + K2=K*prod(AllpassNum(1)-Z*AllpassDen(1))/prod(AllpassNum(1)-P*AllpassDen(1)); + + for i=1:length(Z), + Z2 = [Z2, roots(AllpassNum - Z(i).*AllpassDen).']; + end + for i=1:length(P), + P2 = [P2, roots(AllpassNum - P(i).*AllpassDen).']; + end +// For stabilizing the target filter (if unstable after tranformation) + index = find(abs(P2)>1); + K2 = K2/prod(1-P2(index)); + P2(index) = 1 ./conj(P2(index)); + K2= K2*prod(1-P2(index)); + else + Z2=Z; + P2=P; + K2=K; + end + //Converting to Column vector + Z2=Z2(:); + P2=P2(:); + +endfunction diff --git a/DSP functions/zpklp2xn/test_1.sce b/DSP functions/zpklp2xn/test_1.sce new file mode 100644 index 0000000..243726e --- /dev/null +++ b/DSP functions/zpklp2xn/test_1.sce @@ -0,0 +1,7 @@ +// Test # 1 : No Input Arguments +exec('./zpklp2xn.sci',-1); +[z,p,k,n,d]=zpklp2xn(); +// !--error 10000 +//Number of input arguments should either be 5 or 6 +//at line 37 of function zpklp2xn called by : +//[z,p,k,n,d]=zpklp2xn(); diff --git a/DSP functions/zpklp2xn/test_10.sce b/DSP functions/zpklp2xn/test_10.sce new file mode 100644 index 0000000..d9ba894 --- /dev/null +++ b/DSP functions/zpklp2xn/test_10.sce @@ -0,0 +1,30 @@ +// Test #10 : Valid case #2 +exec('./zpklp2xn.sci',-1); +[z,p,k,n,d]=zpklp2xn([3 6],5*%i,2,[0.6 0.9],[0.3,0.5],'stop'); +disp(d); +disp(n); +disp(k); +disp(p); +disp(z); +// +//Scilab Output +//d=1. 0.1830462 - 0.1557084 +//n= - 0.1557084 0.1830462 1. +//k=-0.2417442 + 7.7627201i +//p=-0.5518990 + 0.1861402i +// 0.3701691 - 0.2284088i +//z=-0.7423118 +// 0.6263022 +// -0.6398019 +// 0.4911218 +// +//Matlab Output +//z= -0.7423 +// 0.6263 +// -0.6398 +// 0.4911 +//p = -0.5519 + 0.1861i +// 0.3702 - 0.2284i +//k = -0.2417 + 7.7627i +//n = -0.1557 0.1830 1.0000 +//d = 1.0000 0.1830 -0.1557 diff --git a/DSP functions/zpklp2xn/test_2.sce b/DSP functions/zpklp2xn/test_2.sce new file mode 100644 index 0000000..ac70553 --- /dev/null +++ b/DSP functions/zpklp2xn/test_2.sce @@ -0,0 +1,7 @@ +// Test # 2 : Excess Input Arguments +exec('./zpklp2xn.sci',-1); +[z,p,k,n,d]=zpklp2xn(3,1,7,[0.5 0.9],[0.4 0.5],'pass',3); +// !--error 10000 +//Number of input arguments should either be 5 or 6 +//at line 37 of function zpklp2xn called by : +//[z,p,k,n,d]=zpklp2xn(3,1,7,[0.5 0.9],[0.4 0.5],'pass',3) diff --git a/DSP functions/zpklp2xn/test_3.sce b/DSP functions/zpklp2xn/test_3.sce new file mode 100644 index 0000000..ef61d69 --- /dev/null +++ b/DSP functions/zpklp2xn/test_3.sce @@ -0,0 +1,5 @@ +// Test # 3 : Incorrect number of output Arguments +exec('./zpklp2xn.sci',-1); +[z,p,k,n,d,e]=zpklp2xn(0.3,2,8,[0.8,0.9],[0.2 0.5]); +//!--error 59 +//Wrong number of output arguments diff --git a/DSP functions/zpklp2xn/test_4.sce b/DSP functions/zpklp2xn/test_4.sce new file mode 100644 index 0000000..c5800a1 --- /dev/null +++ b/DSP functions/zpklp2xn/test_4.sce @@ -0,0 +1,7 @@ +// Test # 4 : Checking the type for Input Argument #3 +exec('./zpklp2xn.sci',-1); +[z,p,k,n,d]=zpklp2xn(0.1,2,[2 9],[3 0.4],[0.1,0.6]); +// !--error 10000 +//K must be a scalar +//at line 45 of function zpklp2xn called by : +//[z,p,k,n,d]=zpklp2xn(0.1,[2 9],[3 0.4],[0.1,0.6]) diff --git a/DSP functions/zpklp2xn/test_5.sce b/DSP functions/zpklp2xn/test_5.sce new file mode 100644 index 0000000..9f3e343 --- /dev/null +++ b/DSP functions/zpklp2xn/test_5.sce @@ -0,0 +1,7 @@ +// Test # 5 : When either Input Argument #4 or Input Argument #5 is of complex type +exec('./zpklp2xn.sci',-1); +[z,p,k,n,d]=zpklp2xn(2,3,1,8.22*%i,[0.05 0.2]); +//!--error 10000 +//Wo must be real ,numeric and scalar +//at line 49 of function zpklp2xn called by : +//[z,p,k,n,d]=zpklp2xn(2,3,1,8.22*%i,[0.05 0.2]); diff --git a/DSP functions/zpklp2xn/test_6.sce b/DSP functions/zpklp2xn/test_6.sce new file mode 100644 index 0000000..9b2caa3 --- /dev/null +++ b/DSP functions/zpklp2xn/test_6.sce @@ -0,0 +1,7 @@ +// Test # 6 : Range test for Input Argument #4 or Input Argument #5 +exec('./zpklp2xn.sci',-1); +[z,p,k,n,d]=zpklp2xn(0.2,1,4,[2 0.9],[4,0.7]); +//!--error 10000 +//Wo must be in normalised and ascending form +//at line 56 of function zpklp2xn called by : +//[z,p,k,n,d]=zpklp2xn(0.2,1,4,[5 0.9],[0.4,0.7]); diff --git a/DSP functions/zpklp2xn/test_7.sce b/DSP functions/zpklp2xn/test_7.sce new file mode 100644 index 0000000..cdd0808 --- /dev/null +++ b/DSP functions/zpklp2xn/test_7.sce @@ -0,0 +1,7 @@ +//Test #7 : Wrong flag input +exec('./zpklp2xn.sci',-1); +//[z,p,k,n,d]=zpklp2xn(4,0.9,8,[0.1 0.3],[0.5 0.6],'w'); +//!--error 10000 +//Invalid option,input should be either pass or stop +//at line 97 of function zpklp2xn called by : +//[z,p,k,n,d]=zpklp2xn(4,0.9,8,[0.1 0.3],[0.5 0.6],'w') diff --git a/DSP functions/zpklp2xn/test_8.sce b/DSP functions/zpklp2xn/test_8.sce new file mode 100644 index 0000000..6637e87 --- /dev/null +++ b/DSP functions/zpklp2xn/test_8.sce @@ -0,0 +1,19 @@ +// Test #8 : When output arguments are less than 5 +exec('./zpklp2xn.sci',-1); +[z,p,k]=zpklp2xn(8,2,0.5,[0.1 0.5],[0.5,0.75]); +disp(k); +disp(p); +disp(z); +// +//Scilab Output +//k =2.1009558 +//p = 0.1427731 + 0.6153536i +// 0.1427731 - 0.6153536i +//z= 0.2093027 +// -0.0054340 +// +//Matlab Output +//z = 0.2093 -0.0054 +//p = 0.1428 + 0.6154i +// 0.1428 - 0.6154i +//k = 2.1010 diff --git a/DSP functions/zpklp2xn/test_9.sce b/DSP functions/zpklp2xn/test_9.sce new file mode 100644 index 0000000..19df10b --- /dev/null +++ b/DSP functions/zpklp2xn/test_9.sce @@ -0,0 +1,30 @@ +// Test #9 : Valid case #1 +exec('./zpklp2xn.sci',-1); +[z,p,k,n,d]=zpklp2xn([8 9],2,5,[0.1 0.5],[0.5,0.75],'pass'); +disp(d); +disp(n); +disp(k); +disp(p); +disp(z); +// +//Scilab Output +//d=1. -0.1783598 -0.1261194 +//n=0.1261194 0.1783598 -1. +//k=- 186.43631 +//p= 0.1427731 + 0.6153536i +// 0.1427731 - 0.6153536i +//z=0.2093027 +// -0.0054340 +// 0.2596237 +// -0.0586295 +// +//Matlab Output +//z = 0.2093 +// -0.0054 +// 0.2596 +// -0.0586 +// p = 0.1428 + 0.6154i +// 0.1428 - 0.6154i +//k = -186.4363 +//n = 0.1261 0.1784 -1.0000 +//d = 1.0000 -0.1784 -0.1261 diff --git a/DSP functions/zpklp2xn/zpklp2xn.sci b/DSP functions/zpklp2xn/zpklp2xn.sci new file mode 100644 index 0000000..cb44815 --- /dev/null +++ b/DSP functions/zpklp2xn/zpklp2xn.sci @@ -0,0 +1,189 @@ +function [Z2, P2, K2, AllpassNum,AllpassDen]= zpklp2xn(Z, P ,K, Wo,Wt,varargin) +//Zero-pole-gain lowpass to M-band frequency transformation +// +//Calling Sequences +// +//[Z2,P2,K2,AllpassNum,AllpassDen] = zpklp2xn(Z,P,K,Wo,Wt) returns zeros, Z2, poles, P2, and gain factor, K2, of the target filter transformed from the real lowpass prototype by applying an Nth-order real lowpass to real multipoint frequency transformation, where N is the number of features being mapped. By default the DC feature is kept at its original location. +// +//[Z2,P2,K2,AllpassNum,AllpassDen] = zpklp2xn(Z,P,K,Wo,Wt,Pass) allows you to specify an additional parameter, Pass, which chooses between using the "DC Mobility" and the "Nyquist Mobility". In the first case the Nyquist feature stays at its original location and the DC feature is free to move. In the second case the DC feature is kept at an original frequency and the Nyquist feature is allowed to move.It also returns the numerator, AllpassNum, and the denominator, AllpassDen, of the allpass mapping filter. The prototype lowpass filter is given with zeros, Z, poles, P, and gain factor, K. +// +//Input Parameters: +// Z: Zeros of the prototype filter +// P: Poles of the prototype filter +// K: Gain of the prototype filter +// Wo: Frequency value of the prototype filter to be transformed +// Wt: Desired frquency of the target filter +// Pass: Choice ('pass'/'stop') of passband/stopband at DC, 'pass' being the default +//Output Parameters: +// Z2: Zeros of the target filter +// P2: Poles of the target filter +// K2:Gain factor of the target filter +// AllpassNum: Numerator of the mapping filter +// AllpassDen: Denominator of the mapping filter +//Example: Design a prototype real IIR halfband filter using a standard elliptic approach +// +// [b, a] = ellip(3,0.1,30,0.409); +// z = roots(b); +// p = roots(a); +// k = b(1); +// [z2,p2,k2] = zpklp2xn(z, p, k, [-0.5 0.5], [0 0.25], 'pass'); +// +//Author: Shrenik Nambiar +// +//References: Cain, G.D., A. Krukowski and I. Kale, "High Order Transformations for Flexible IIR Filter Design," VII European Signal Processing Conference (EUSIPCO'94), vol. 3, pp. 1582-1585, Edinburgh, United Kingdom, September 1994. +// +//Input Validaton Statement + if argn(2)<5 | argn(2)>6 then + error("Number of input arguments should either be 5 or 6"); + end + + if argn(1)<1 | argn(1)>5 then + error("Number of output arguments should be between 1 and 5"); + end + + if ~isscalar(K) then + error("K must be a scalar"); + end + + if ~isvector(Wo) | ~isreal(Wo) then + error("Wo must be vector and real"); + end + + m=length(Wo); + + for i= 1:m + if Wo(i) <=-1 | Wo(i) >=1 then + error("Wo must be in normalised"); + end + end + + sortedWo=gsort(Wo,'r','i'); + if Wo~=sortedWo then + error("Wo must in ascending order"); + end + + if ~isvector(Wt) | ~isreal(Wt) then + error("Wt must be vector and real"); + end + + n=length(Wt); + + for i= 1:n + if Wt(i) <=-1 | Wt(i) >=1 then + error("Wt must be in normalised and ascending form"); + end + end + + sortedWt=gsort(Wt,'r','i'); + if Wt~=sortedWt then + error("Wt must in ascending order"); + end + +//Flag checking + if (length(varargin)==1) & (type(varargin(1))~=10) then + error("Input argument #6 must be of type char"); + end + + if length(varargin)==0 then + pass= -1; //pass being the default option + else + Pa=varargin(1); + select Pa + case 'pass' then + pass=-1; + case 'stop' then + pass=1; + else + error("Invalid option,input should be either pass or stop"); + end + end + + + zo = exp(%i*%pi*Wo); + zn = exp(-%i*%pi*Wt); + + for k=1:m + a(k,:) = zo(k) * (zn(k).^(m-1:-1:0)) - pass*(zn(k).^(1:m)); + end + + b = pass - zo.' .*(zn.' .^m); + AllpassNum = real([1; a\b]); + + in= find(isnan(AllpassNum)); + if ~isempty(in) then + AllpassNum= real([1 linsolve(a,b)]) + end + + AllpassDen = flipdim(AllpassNum(:).',2); + AllpassNum = pass*AllpassNum(:).'; + + if isstable(AllpassDen) then + AllpassNum = flipdim(AllpassNum,2); + AllpassDen = flipdim(AllpassDen,2); + end + + z1= roots(AllpassNum); //computing zeros + p1= roots(AllpassDen); //computing poles + k1= frmag(AllpassNum,AllpassDen,1); //gain computation + + lp1= length(p1); + z2=[]; + +// for cancelling overlapping poles and zeros + p1index=zeros(1,lp1); + for j=1:length(z1), + fnd1 = find(abs(z1(j)-p1)<10^-6); + fnd2 = find(p1index(fnd1)<%eps); + fnd = fnd1(fnd2); + if isempty(fnd), + z2 = [z2, z1(j)]; + else + p1index(fnd(1)) = 1; + end + end + + p2= p1(p1index==0); + p2=p2(:).'; + k2=k1; +//the case in which all poles and zeros are cancelled + if isempty(z2) then + z2=0; + end +// Calculating the numerator and denominator for the mapping filter + if length(z2) ~= m then + AllpassNum =poly(z2,'s'); + AllpassDen = k2.*poly(p2,'s'); + s = sign(AllpassDen($)); + AllpassNum = AllpassNum./ s; + AllpassDen = AllpassDen./AllpassDen($); + + [AllpassNum,AllpassDen] = eqtflength(flipdim((AllpassNum),2), flipdim((allpassden),2)); + + end + + if or(AllpassNum~=1) | or(AllpassDen~=1) then + Z2=[]; + P2=[]; + K2=K*prod(AllpassNum(1)-Z*AllpassDen(1))/prod(AllpassNum(1)-P*AllpassDen(1)); + + for i=1:length(Z), + Z2 = [Z2, roots(AllpassNum - Z(i).*AllpassDen).']; + end + for i=1:length(P), + P2 = [P2, roots(AllpassNum - P(i).*AllpassDen).']; + end +// For stabilizing the target filter (if unstable after tranformation) + index = find(abs(P2)>1); + K2 = K2/prod(1-P2(index)); + P2(index) = 1 ./conj(P2(index)); + K2= K2*prod(1-P2(index)); + else + Z2=Z; + P2=P; + K2=K; + end + //Converting to Column vector + Z2=Z2(:); + P2=P2(:); + +endfunction diff --git a/DSP functions/zpkrateup/test_1.sce b/DSP functions/zpkrateup/test_1.sce new file mode 100644 index 0000000..3756812 --- /dev/null +++ b/DSP functions/zpkrateup/test_1.sce @@ -0,0 +1,7 @@ +// Test # 1 : No Input Arguments +exec('./zpkrateup.sci',-1); +[z,p,k,n,d]=zpkrateup(); +//!--error 10000 +//Number of input arguments should be 4 +//at line 33 of function zpkrateup called by : +//[z,p,k,n,d]=zpkrateup(); diff --git a/DSP functions/zpkrateup/test_2.sce b/DSP functions/zpkrateup/test_2.sce new file mode 100644 index 0000000..174e8d7 --- /dev/null +++ b/DSP functions/zpkrateup/test_2.sce @@ -0,0 +1,5 @@ +// Test # 2 : Excess Input Arguments +exec('./zpkrateup.sci',-1); +[z,p,k,n,d]=zpkrateup(3,7.2,8.7,5,6); +//!--error 58 +//Wrong number of input arguments diff --git a/DSP functions/zpkrateup/test_3.sce b/DSP functions/zpkrateup/test_3.sce new file mode 100644 index 0000000..d3af8ae --- /dev/null +++ b/DSP functions/zpkrateup/test_3.sce @@ -0,0 +1,7 @@ +// Test # 3 : Checking the type for Input Argument #3 +exec('./zpkrateup.sci',-1); +[z,p,k,n,d]=zpkrateup(0.4,0.8,[5,0.4],6); +// !--error 10000 +//K must be a scalar +//at line 49 of function zpkrateup called by : +//[z,p,k,n,d]=zpkrateup(0.4,0.8,[5,0.4],6); diff --git a/DSP functions/zpkrateup/test_4.sce b/DSP functions/zpkrateup/test_4.sce new file mode 100644 index 0000000..3ad9a2a --- /dev/null +++ b/DSP functions/zpkrateup/test_4.sce @@ -0,0 +1,5 @@ +// Test # 4 : Incorrect number of output Arguments +exec('./zpkrateup.sci',-1); +[z,p,k,n,d,e]=zpkrateup(3,2,8,2); +//!--error 59 +//Wrong number of output arguments diff --git a/DSP functions/zpkrateup/test_5.sce b/DSP functions/zpkrateup/test_5.sce new file mode 100644 index 0000000..f47d692 --- /dev/null +++ b/DSP functions/zpkrateup/test_5.sce @@ -0,0 +1,8 @@ +// Test # 5 : When either Input Argument #4 is of complex type +exec('./zpkrateup.sci',-1); +[z,p,k,n,d]=zpkrateup(5,8,1,3*%i); +//!--error 10000 +//N must be real and positive scalar +//at line 41 of function zpkrateup called by : +//[z,p,k,n,d]=zpkrateup(5,8,1,3*%i); + diff --git a/DSP functions/zpkrateup/test_6.sce b/DSP functions/zpkrateup/test_6.sce new file mode 100644 index 0000000..dca870d --- /dev/null +++ b/DSP functions/zpkrateup/test_6.sce @@ -0,0 +1,32 @@ +// Test #8 : When output arguments are less than 5 +exec('./zpkrateup.sci',-1); +[z,p,k]=zpkrateup(2.1,3.1,1,5); +disp(k); +disp(p); +disp(z); +// +//Scilab Output +//k=0.6774194 +//p=-0.6451866 + 0.4687555i +// -0.6451866 - 0.4687555i +// 0.2464393 + 0.7584623i +// 0.2464393 - 0.7584623i +// 0.7974944 +//z=-0.6974511 + 0.5067279i +// -0.6974511 - 0.5067279i +// 0.2664026 + 0.8199030i +// 0 2664026 - 0.8199030i +// 0.8620970 +// +//Matlab Output +//z=-0.6975 + 0.5067i +// -0.6975 - 0.5067i +// 0.2664 + 0.8199i +// 0.2664 - 0.8199i +// 0.8621 + 0.0000i +//p = -0.6452 + 0.4688i +// -0.6452 - 0.4688i +// 0.2464 + 0.7585i +// 0.2464 - 0.7585i +// 0.7975 + 0.0000i +//k = 0.6774 diff --git a/DSP functions/zpkrateup/test_7.sce b/DSP functions/zpkrateup/test_7.sce new file mode 100644 index 0000000..af6d971 --- /dev/null +++ b/DSP functions/zpkrateup/test_7.sce @@ -0,0 +1,6 @@ +// Test #5 :For Input Argument #4 of type double +exec('./allpassrateup.sci',-1); +[z,p,k,n,d]=allpassrateup(9,4,5,6.4); +//N must be an integer +//at line 45 of function zpkrateup called by : +//[z,p,k,n,d]=zpkrateup(9,4,5,6.4); diff --git a/DSP functions/zpkrateup/test_8.sce b/DSP functions/zpkrateup/test_8.sce new file mode 100644 index 0000000..e0826b6 --- /dev/null +++ b/DSP functions/zpkrateup/test_8.sce @@ -0,0 +1,47 @@ +// Test #9 : Valid vector inputs +exec('./zpkrateup.sci',-1); +[z,p,k,n,d]=zpkrateup([6.3,7.5],[1.4,4.2],9.8,3); +disp(d); +disp(n); +disp(k); +disp(p); +disp(z); +// +//Scilab Output +//d=1. 0. 0. 0. +//n=0. 0. 0. 1. +//k= 78.75 +//p= -0.4469518 + 0.7741432i +// -0.4469518 - 0.7741432i +// 0.8939035 +// -0.3098990 + 0.5367609i +// -0.3098990 - 0.5367609i +// 0.6197981 +//z= -0.2707218 + 0.4689038i +// -0.2707218 - 0.4689038i +// 0.5414435 +// -0.2554365 + 0.4424290i +// -0.2554365 - 0.4424290i +// 0.5108730 +// +//Matlab Output +//z= -0.2707 + 0.4689i +// -0.2707 - 0.4689i +// 0.5414 + 0.0000i +// -0.2554 + 0.4424i +// -0.2554 - 0.4424i +// 0.5109 + 0.0000i +//p= -0.4470 + 0.7741i +// -0.4470 - 0.7741i +// 0.8939 + 0.0000i +// -0.3099 + 0.5368i +// -0.3099 - 0.5368i +// 0.6198 + 0.0000i +//k = 78.7500 +//n = 0 0 0 1 +//d = 1 0 0 0 + + + + + diff --git a/DSP functions/zpkrateup/zpkrateup.sci b/DSP functions/zpkrateup/zpkrateup.sci new file mode 100644 index 0000000..b505278 --- /dev/null +++ b/DSP functions/zpkrateup/zpkrateup.sci @@ -0,0 +1,81 @@ +function [Z2, P2, K2, AllpassNum,AllpassDen]= zpkrateup(Z, P ,K, N) +//Zero-pole-gain complex bandpass frequency transformation +// +//Calling Sequence: +// +//[Z2,P2,K2,AllpassNum,AllpassDen] = zpkrateup(Z,P,K,N) returns zeros, Z2, poles, P2, and gain factor, K2, of the target filter being transformed from any prototype by applying an Nth-order rateup frequency transformation, where N is the upsample ratio. Transformation creates N equal replicas of the prototype filter frequency response.It also returns the numerator, AllpassNum, and the denominator, AllpassDen, of the allpass mapping filter. The original lowpass filter is given with zeros, Z, poles, P, and gain factor, K. +// +//Input Parameters: +// Z: Zeros of the prototype filter +// P: Poles of the prototype filter +// K: Gain of the prototype filter +// N: Upsampling Ratio +//Output Parameters: +// Z2: Zeros of the target filter +// P2: Poles of the target filter +// K2:Gain factor of the target filter +// AllpassNum: Numerator of the mapping filter +// AllpassDen: Denominator of the mapping filter +//Example: Design a prototype real IIR halfband filter using a standard elliptic approach +// +// [b, a] = ellip(3,0.1,30,0.409); +// z = roots(b); +// p = roots(a); +// k = b(1); +// [z2,p2,k2] = zpkrateup(z, p, k, 4); +// +//Author: Shrenik Nambiar + +//References: 1. Constantinides, A.G., "Spectral transformations for digital filters," IEEE® Proceedings, vol. 117, no. 8, pp. 1585-1590, August 1970. +// +// Input Validation Statements + if argn(2) ~=4 then + error("Number of input arguments should be 4"); + end + + if argn(1)<1 |argn(1)>5 then + error("Number of output arguments should be 5"); + end + + if ~isscalar(N) | ~isreal(N) | N<0 then + error("N must be real and positive scalar"); + end + + if round(N)~=N & type(N) ~=8 then + error("N must be an integer"); + end + + if ~isscalar(K) then + error("K must be a scalar"); + end +// Calculating the numerator and denominator for the mapping filter + AllpassDen = [1 zeros(1,N)]; + AllpassNum = [zeros(1,N) 1]; + + + if or(AllpassNum~=1) | or(AllpassDen~=1) then + Z2=[]; + P2=[]; + K2=K*prod(AllpassNum(1)-Z*AllpassDen(1))/prod(AllpassNum(1)-P*AllpassDen(1)); + + for i=1:length(Z), + Z2 = [Z2, roots(AllpassNum - Z(i).*AllpassDen).']; + end + for i=1:length(P), + P2 = [P2, roots(AllpassNum - P(i).*AllpassDen).']; + end +// For stabilizing the target filter (if unstable after tranformation) + index = find(abs(P2)>1); + K2 = K2/prod(1-P2(index)); + P2(index) = 1. /conj(P2(index)); + K2= K2*prod(1-P2(index)); + else + Z2=Z; + P2=P; + K2=K; + end + //Converting to Column vector + Z2=Z2(:); + P2=P2(:); + +endfunction diff --git a/DSP functions/zpkshift/test_1.sce b/DSP functions/zpkshift/test_1.sce new file mode 100644 index 0000000..7cb209a --- /dev/null +++ b/DSP functions/zpkshift/test_1.sce @@ -0,0 +1,7 @@ +// Test # 1 : No Input Arguments +exec('./zpkshift.sci',-1); +[z,p,k,n,d]=zpkshift(); +//!--error 10000 +//Number of input arguments should be 5 +//at line 36 of function zpkshift called by : +//[z,p,k,n,d]=zpkshift(); diff --git a/DSP functions/zpkshift/test_10.sce b/DSP functions/zpkshift/test_10.sce new file mode 100644 index 0000000..7c3a3eb --- /dev/null +++ b/DSP functions/zpkshift/test_10.sce @@ -0,0 +1,34 @@ +// Test #10 : For complex vector inputs +exec('./zpkshift.sci',-1); +[z,p,k,n,d]=zpkshift([6*%i,4*%i],[3.2*%i,9*%i],6,0.7,0.9); +disp(d); +disp(n); +disp(k); +disp(p); +disp(z); +// +//Scilab Output +//d=1. 0.3445765 0. +//n=0. - 0.3445765 - 1. +//k=5. +//p=-0.5735053 - 0.3124803i +// 0.2289288 + 0.4201605i +// - 0.4348387 - 0.1798945i +// 0.0902622 + 0.2181807i +//z=-0.4790985 - 0.2267726i +// 0.1345219 + 0.2842021i +// - 0.5360377 - 0.2801702i +// 0.1914611 + 0.3663144i +// +//Matlab Output +//z= -0.4791 - 0.2268i +// 0.1345 + 0.2842i +// -0.5360 - 0.2802i +// 0.1915 + 0.3663i +//p= -0.5735 - 0.3125i +// 0.2289 + 0.4202i +// -0.4348 - 0.1799i +// 0.0903 + 0.2182i +//k=5 +//n= 0 -0.3446 -1.0000 +//d= 1.0000 0.3446 0 diff --git a/DSP functions/zpkshift/test_2.sce b/DSP functions/zpkshift/test_2.sce new file mode 100644 index 0000000..6022e0c --- /dev/null +++ b/DSP functions/zpkshift/test_2.sce @@ -0,0 +1,5 @@ +// Test # 2 : Excess Input Arguments +exec('./zpkshift.sci',-1); +[z,p,k,n,d]=zpkshift(0.3,0.2,0.7,0.5,0.6,4); +//!--error 58 +//Wrong number of input arguments diff --git a/DSP functions/zpkshift/test_3.sce b/DSP functions/zpkshift/test_3.sce new file mode 100644 index 0000000..3d45db5 --- /dev/null +++ b/DSP functions/zpkshift/test_3.sce @@ -0,0 +1,7 @@ +// Test # 3 : Checking the type for Input Argument #3 +exec('./zpkshift.sci',-1); +[z,p,k,n,d]=zpkshift(0.3,0.2,[0.4 0.8],0.5,0.6); +// !--error 10000 +//K must be a scalar +//at line 58 of function zpkshift called by : +//[z,p,k,n,d]=zpkshift(0.3,0.2,[0.4 0.8],0.5,0.6); diff --git a/DSP functions/zpkshift/test_4.sce b/DSP functions/zpkshift/test_4.sce new file mode 100644 index 0000000..29407f5 --- /dev/null +++ b/DSP functions/zpkshift/test_4.sce @@ -0,0 +1,5 @@ +// Test # 4 : Incorrect number of output Arguments +exec('./zpkshift.sci',-1); +[z,p,k,n,d,e]=zpkshift(0.3,2,8,0.8,0.2); +//!--error 59 +//Wrong number of output arguments diff --git a/DSP functions/zpkshift/test_5.sce b/DSP functions/zpkshift/test_5.sce new file mode 100644 index 0000000..7138699 --- /dev/null +++ b/DSP functions/zpkshift/test_5.sce @@ -0,0 +1,8 @@ +// Test # 5 : When either Input Argument #4 or Input Argument #5 is of complex type +exec('./zpkshift.sci',-1); +[z,p,k,n,d]=zpkshift(5,8,1,3*%i,0.2); +//!--error 10000 +//Wo must be real ,numeric and scalar +//at line 44 of function zpkshift called by : +//[z,p,k,n,d]=zpkshift(5,8,1,3*%i,0.2); + diff --git a/DSP functions/zpkshift/test_6.sce b/DSP functions/zpkshift/test_6.sce new file mode 100644 index 0000000..ab10fbb --- /dev/null +++ b/DSP functions/zpkshift/test_6.sce @@ -0,0 +1,7 @@ +// Test # 6 : Range test for Input Argument #4 or Input Argument #5 +exec('./zpkshift.sci',-1); +[z,p,k,n,d]=zpkshift(9,1,4,4,0.4); +//!--error 10000 +//Wo must lie between 0 and 1 +//at line 47 of function zpkshift called by : +//[z,p,k,n,d]=zpkshift(9,1,4,4,0.4); diff --git a/DSP functions/zpkshift/test_7.sce b/DSP functions/zpkshift/test_7.sce new file mode 100644 index 0000000..a03b99d --- /dev/null +++ b/DSP functions/zpkshift/test_7.sce @@ -0,0 +1,7 @@ +// Test #7 : Length test for Input Argument #4 or Input Argument #5 +exec('./zpkshift.sci',-1); +[z,p,k,n,d]=zpkshift(5,3,1,0.7,[0.9 0.5]); +//!--error 10000 +//Wt must be real, numeric and scalar +//at line 51 of function zpkshift called by : +//[z,p,k,n,d]=zpkshift(5,3,1,0.7,[0.9 0.5]); diff --git a/DSP functions/zpkshift/test_8.sce b/DSP functions/zpkshift/test_8.sce new file mode 100644 index 0000000..a38d7b6 --- /dev/null +++ b/DSP functions/zpkshift/test_8.sce @@ -0,0 +1,20 @@ +// Test #8 : When output arguments are less than 5 +exec('./zpkshift.sci',-1); +[z,p,k]=zpkshift(4.1,9.1,1,0.1,0.5); +disp(k); +disp(p); +disp(z); +// +//Scilab Output +//k=0.4505495 +//p=0.0878947 + 0.3196320i +// 0.0878947 - 0.3196320i +//z=0.0985074 + 0.4839408i +// 0.0985074 - 0.4839408i +// +//Matlab Output +//z = 0.0985 + 0.4839i +// 0.0985 - 0.4839i +//p = 0.0879 + 0.3196i +// 0.0879 - 0.3196i +//k = 0.4505 diff --git a/DSP functions/zpkshift/test_9.sce b/DSP functions/zpkshift/test_9.sce new file mode 100644 index 0000000..4e6a21c --- /dev/null +++ b/DSP functions/zpkshift/test_9.sce @@ -0,0 +1,34 @@ +// Test #9 : For vector inputs +exec('./zpkshift.sci',-1); +[z,p,k,n,d]=zpkshift([6.3,7.5],[1.4,4.2],3,0.2,0.8); +disp(d); +disp(n); +disp(k); +disp(p); +disp(z); +// +//Scilab Output +//d=1. 0.6180340 0. +//n=0. - 0.6180340 - 1. +//k=24.107143 +//p=- 0.5297434 + 0.6585269i +// - 0.5297434 - 0.6585269i +// - 0.3825925 + 0.3028502i +// - 0.3825925 - 0.3028502i +//z =- 0.3580673 + 0.1746939i +// - 0.3580673 - 0.1746939i +// - 0.3502193 + 0.1033431i +// - 0.3502193 - 0.1033431i +// +//Matlab Output +//z= -0.3581 + 0.1747i +// -0.3581 - 0.1747i +// -0.3502 + 0.1033i +// -0.3502 - 0.1033i +//p= -0.5297 + 0.6585i +// -0.5297 - 0.6585i +// -0.3826 + 0.3029i +// -0.3826 - 0.3029i +//k=24.1071 +//n= 0 -0.6180 -1.0000 +//d= 1.0000 0.6180 0 diff --git a/DSP functions/zpkshift/zpkshift.sci b/DSP functions/zpkshift/zpkshift.sci new file mode 100644 index 0000000..e997ef2 --- /dev/null +++ b/DSP functions/zpkshift/zpkshift.sci @@ -0,0 +1,96 @@ +function [Z2, P2, K2, AllpassNum,AllpassDen]= zpkshift(Z, P ,K, Wo,Wt) +//Zero-pole-gain real shift frequency transformation +// +//Calling Sequences +// +//[Z2,P2,K2,AllpassNum,AllpassDen] = zpkshift(Z,P,K,Wo,Wt) returns the zeros,Z2 , poles, P2, and gain factor, K2, of the target filter transformed from the zeros, poles, and gain factor of real lowpass prototype by applying a second-order real shift frequency mapping. It also returns the numerator, AllpassNum, and the denominator, AllpassDen of the allpass mapping filter. +// +//Input Parameters: +// Z: Zeros of the prototype filter +// P: Poles of the prototype filter +// K: Gain of the prototype filter +// Wo: Frequency value of the prototype filter to be transformed +// Wt: Desired frquency of the target filter +// +//Output Parameters: +// Z2: Zeros of the target filter +// P2: Poles of the target filter +// K2:Gain factor of the target filter +// AllpassNum: Numerator of the mapping filter +// AllpassDen: Denominator of the mapping filter +//Example: Rotate frequency response by π/2 radians/sample: +// +// [b, a] = ellip(10,0.1,40,0.27); +// z = roots(b); +// p = roots(a); +// k = b(1); +// [z2,p2,k2] = zpkshift(z,p,k,0.25,0.75); +// Num = poly(Z2); +// Den = poly(P2); +//Author: Shrenik Nambiar +// +//References: Oppenheim, A.V., R.W. Schafer and J.R. Buck, Discrete-Time Signal Processing, Prentice-Hall International Inc., 1989. +// +//Input Validaton Statement + if argn(2) ~=5 then + error("Number of input arguments should be 5"); + end + + if argn(1)<1 | argn(1)>5 then + error("Number of output arguments should be 5"); + 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 ~isscalar(Wt) | ~isreal(Wt) then + error("Wt must be real, numeric and scalar"); + end + if Wt<=0 | Wt>=1 then + error("Wt must lie between 0 and 1"); + end + + if ~isscalar(K) then + error("K must be a scalar"); + end +// Calculating the numerator and denominator for the mapping filter + be = cos(%pi*(Wo/2-Wt)); + if abs(be) < 1.0, + be = be/ cos(%pi*Wo/2); + else + be = sin(%pi*(Wo/2-Wt)) / sin(%pi*Wo/2); + end + + AllpassDen = [1 -be 0]; + AllpassNum = [0 be -1]; + + if or(AllpassNum~=1) | or(AllpassDen~=1) then + Z2=[]; + P2=[]; + K2=K*prod(AllpassNum(1)-Z*AllpassDen(1))/prod(AllpassNum(1)-P*AllpassDen(1)); + + for i=1:length(Z), + Z2 = [Z2, roots(AllpassNum - Z(i).*AllpassDen).']; + end + for i=1:length(P), + P2 = [P2, roots(AllpassNum - P(i).*AllpassDen).']; + end +// For stabilizing the target filter (if unstable after tranformation) + index = find(abs(P2)>1); + K2 = K2/prod(1-P2(index)); + P2(index) = 1. /conj(P2(index)); + K2= K2*prod(1-P2(index)); + else + Z2=Z; + P2=P; + K2=K; + end + //Converting to Column vector + Z2=Z2(:); + P2=P2(:); + +endfunction From 886f2573c8bafb00765dff86c16814c5103b9559 Mon Sep 17 00:00:00 2001 From: Shrenik Nambiar Date: Tue, 25 Jul 2017 23:53:25 +0530 Subject: [PATCH 14/15] Add files via upload --- DSP functions/zpkshiftc/test_1.sce | 7 +++ DSP functions/zpkshiftc/test_10.sce | 34 ++++++++++ DSP functions/zpkshiftc/test_2.sce | 5 ++ DSP functions/zpkshiftc/test_3.sce | 7 +++ DSP functions/zpkshiftc/test_4.sce | 5 ++ DSP functions/zpkshiftc/test_5.sce | 8 +++ DSP functions/zpkshiftc/test_6.sce | 7 +++ DSP functions/zpkshiftc/test_7.sce | 7 +++ DSP functions/zpkshiftc/test_8.sce | 16 +++++ DSP functions/zpkshiftc/test_9.sce | 34 ++++++++++ DSP functions/zpkshiftc/zpkshiftc.sci | 90 +++++++++++++++++++++++++++ 11 files changed, 220 insertions(+) create mode 100644 DSP functions/zpkshiftc/test_1.sce create mode 100644 DSP functions/zpkshiftc/test_10.sce create mode 100644 DSP functions/zpkshiftc/test_2.sce create mode 100644 DSP functions/zpkshiftc/test_3.sce create mode 100644 DSP functions/zpkshiftc/test_4.sce create mode 100644 DSP functions/zpkshiftc/test_5.sce create mode 100644 DSP functions/zpkshiftc/test_6.sce create mode 100644 DSP functions/zpkshiftc/test_7.sce create mode 100644 DSP functions/zpkshiftc/test_8.sce create mode 100644 DSP functions/zpkshiftc/test_9.sce create mode 100644 DSP functions/zpkshiftc/zpkshiftc.sci diff --git a/DSP functions/zpkshiftc/test_1.sce b/DSP functions/zpkshiftc/test_1.sce new file mode 100644 index 0000000..bcf3aab --- /dev/null +++ b/DSP functions/zpkshiftc/test_1.sce @@ -0,0 +1,7 @@ +// Test # 1 : No Input Arguments +exec('./zpkshiftc.sci',-1); +[z,p,k,n,d]=zpkshiftc(); +//!--error 10000 +//Number of input arguments should be 5 +//at line 34 of function zpkshiftc called by : +//[z,p,k,n,d]=zpkshiftc(); diff --git a/DSP functions/zpkshiftc/test_10.sce b/DSP functions/zpkshiftc/test_10.sce new file mode 100644 index 0000000..645b76b --- /dev/null +++ b/DSP functions/zpkshiftc/test_10.sce @@ -0,0 +1,34 @@ +// Test #10 : For complex vector inputs +exec('./zpkshift.sci',-1); +[z,p,k,n,d]=zpkshift([2*%i,4.4*%i],[32*%i,2.8*%i],6.6,0.23,0.79); +disp(d); +disp(n); +disp(k); +disp(p); +disp(z); +// +//Scilab Output +//d=1. 0.5585567 0. +//n=0. - 0.5585567 - 1. +//k=0.6482143 +//p=- 0.5622831 - 0.0378711i +// 0.0037263 + 0.0553260i +// - 0.7134814 - 0.2473663i +// 0.1549246 + 0.4468508i +//z=- 0.7714856 - 0.2890457i +// 0.2129289 + 0.5683240i +// - 0.6531465 - 0.1930617i +// 0.0945898 + 0.3200064i +// +//Matlab Output +//z = -0.7715 - 0.2890i +// 0.2129 + 0.5683i +// -0.6531 - 0.1931i +// 0.0946 + 0.3200i +//p = -0.5623 - 0.0379i +// 0.0037 + 0.0553i +// -0.7135 - 0.2474i +// 0.1549 + 0.4469i +//k = 0.6482 +//n = 0 -0.5586 -1.0000 +//d = 1.0000 0.5586 0 diff --git a/DSP functions/zpkshiftc/test_2.sce b/DSP functions/zpkshiftc/test_2.sce new file mode 100644 index 0000000..4fc5214 --- /dev/null +++ b/DSP functions/zpkshiftc/test_2.sce @@ -0,0 +1,5 @@ +// Test # 2 : Excess Input Arguments +exec('./zpkshiftc.sci',-1); +[z,p,k,n,d]=zpkshiftc(0.3,0.2,0.7,0.5,0.6,4); +//!--error 58 +//Wrong number of input arguments diff --git a/DSP functions/zpkshiftc/test_3.sce b/DSP functions/zpkshiftc/test_3.sce new file mode 100644 index 0000000..b8b510f --- /dev/null +++ b/DSP functions/zpkshiftc/test_3.sce @@ -0,0 +1,7 @@ +// Test # 3 : Checking the type for Input Argument #3 +exec('./zpkshiftc.sci',-1); +[z,p,k,n,d]=zpkshiftc(0.3,0.2,[0.4 0.8],0.5,0.6); +// !--error 10000 +//K must be a scalar +//at line 56 of function zpkshiftc called by : +//[z,p,k,n,d]=zpkshiftc(0.3,0.2,[0.4 0.8],0.5,0.6); diff --git a/DSP functions/zpkshiftc/test_4.sce b/DSP functions/zpkshiftc/test_4.sce new file mode 100644 index 0000000..a426d9f --- /dev/null +++ b/DSP functions/zpkshiftc/test_4.sce @@ -0,0 +1,5 @@ +// Test # 4 : Incorrect number of output Arguments +exec('./zpkshiftc.sci',-1); +[z,p,k,n,d,e]=zpkshiftc(0.3,2,8,0.8,0.2); +//!--error 59 +//Wrong number of output arguments diff --git a/DSP functions/zpkshiftc/test_5.sce b/DSP functions/zpkshiftc/test_5.sce new file mode 100644 index 0000000..e87c134 --- /dev/null +++ b/DSP functions/zpkshiftc/test_5.sce @@ -0,0 +1,8 @@ +// Test # 5 : When either Input Argument #4 or Input Argument #5 is of complex type +exec('./zpkshiftc.sci',-1); +[z,p,k,n,d]=zpkshiftc(2,4.8,1,5*%i,0.6); +//!--error 10000 +//Wo must be real ,numeric and scalar +//at line 42 of function zpkshiftc called by : +//[z,p,k,n,d]=zpkshiftc(2,4.8,1,5*%i,0.6); + diff --git a/DSP functions/zpkshiftc/test_6.sce b/DSP functions/zpkshiftc/test_6.sce new file mode 100644 index 0000000..85b8786 --- /dev/null +++ b/DSP functions/zpkshiftc/test_6.sce @@ -0,0 +1,7 @@ +// Test # 6 : Range test for Input Argument #4 or Input Argument #5 +exec('./zpkshiftc.sci',-1); +[z,p,k,n,d]=zpkshiftc(2,5,7,0.5,4); +//!--error 10000 +//Wt must lie between 0 and 1 +//at line 52 of function zpkshiftc called by : +//[z,p,k,n,d]=zpkshift(2,5,7,0.5,4); diff --git a/DSP functions/zpkshiftc/test_7.sce b/DSP functions/zpkshiftc/test_7.sce new file mode 100644 index 0000000..260f7d9 --- /dev/null +++ b/DSP functions/zpkshiftc/test_7.sce @@ -0,0 +1,7 @@ +// Test #7 : Length test for Input Argument #4 or Input Argument #5 +exec('./zpkshiftc.sci',-1); +[z,p,k,n,d]=zpkshiftc(1,3,1,0.7,[0.2 0.6]); +//!--error 10000 +//Wt must be real, numeric and scalar +//at line 49 of function zpkshiftc called by : +//[z,p,k,n,d]=zpkshiftc(1,3,1,0.7,[0.2 0.6]); diff --git a/DSP functions/zpkshiftc/test_8.sce b/DSP functions/zpkshiftc/test_8.sce new file mode 100644 index 0000000..b5c4b7a --- /dev/null +++ b/DSP functions/zpkshiftc/test_8.sce @@ -0,0 +1,16 @@ +// Test #8 : When output arguments are less than 5 +exec('./zpkshiftc.sci',-1); +[z,p,k]=zpkshiftc(1,5.1,7,-0.5,0.79); +disp(k); +disp(p); +disp(z); +// +//Scilab Output +//k=1.104035 - 0.8154739i +//p=- 0.1201779 - 0.1549324i +//z=- 0.6129071 - 0.7901550i +// +//Matlab Output +//z=-0.6129 - 0.7902i +//p=-0.1202 - 0.1549i +//k=1.1040 - 0.8155i diff --git a/DSP functions/zpkshiftc/test_9.sce b/DSP functions/zpkshiftc/test_9.sce new file mode 100644 index 0000000..f91a538 --- /dev/null +++ b/DSP functions/zpkshiftc/test_9.sce @@ -0,0 +1,34 @@ +// Test #9 : For vector inputs +exec('./zpkshift.sci',-1); +[z,p,k,n,d]=zpkshift([3,8.5],[4,9.2],1,0.7,0.8); +disp(d); +disp(n); +disp(k); +disp(p); +disp(z); +// +//Scilab Output +//d=1. - 0.3445765 0. +//n=0. 0.3445765 - 1. +//k=0.6929348 +//p=0.2153603 + 0.4512427i +// 0.2153603 - 0.4512427i +// 0.1910152 + 0.2687170i +// 0.1910152 - 0.2687170i +//z =0.2297177 + 0.5296821i +// 0.2297177 - 0.5296821i +// 0.1925575 + 0.2838462i +// 0.1925575 - 0.2838462i +// +//Matlab Output +//z = 0.2297 + 0.5297i +// 0.2297 - 0.5297i +// 0.1926 + 0.2838i +// 0.1926 - 0.2838i +//p = 0.2154 + 0.4512i +// 0.2154 - 0.4512i +// 0.1910 + 0.2687i +// 0.1910 - 0.2687i +//k= 0.6929 +//n= 0 0.3446 -1.0000 +//d= 1.0000 -0.3446 0 diff --git a/DSP functions/zpkshiftc/zpkshiftc.sci b/DSP functions/zpkshiftc/zpkshiftc.sci new file mode 100644 index 0000000..e32ab0c --- /dev/null +++ b/DSP functions/zpkshiftc/zpkshiftc.sci @@ -0,0 +1,90 @@ +function [Z2, P2, K2, AllpassNum,AllpassDen]= zpkshiftc(Z, P ,K, Wo,Wt) +//Zero-pole-gain complexl shift frequency transformation +// +//Calling Sequences +// +//[Z2,P2,K2,AllpassNum,AllpassDen] = zpkshift(Z,P,K,Wo,Wt) returns the zeros,Z2 , poles, P2, and gain factor, K2, of the target filter transformed from the zeros, poles, and gain factor of real lowpass prototype by applying a second-order real shift frequency mapping. It also returns the numerator, AllpassNum, and the denominator, AllpassDen of the allpass mapping filter. +// +//Input Parameters: +// Z: Zeros of the prototype filter +// P: Poles of the prototype filter +// K: Gain of the prototype filter +// Wo: Frequency value of the prototype filter to be transformed +// Wt: Desired frquency of the target filter +// +//Output Parameters: +// Z2: Zeros of the target filter +// P2: Poles of the target filter +// K2:Gain factor of the target filter +// AllpassNum: Numerator of the mapping filter +// AllpassDen: Denominator of the mapping filter +//Example: Rotate frequency response by π/2 radians/sample: +// +// [b, a] = ellip(3,0.1,30,0.409); +// z = roots(b); +// p = roots(a); +// k = b(1); +// [z2,p2,k2] = zpkshiftc(z,p,k,0.5,0.25); +//Author: Shrenik Nambiar +// +//References: Oppenheim, A.V., R.W. Schafer and J.R. Buck, Discrete-Time Signal Processing, Prentice-Hall International Inc., 1989. +// +//Input Validaton Statement + if argn(2) ~=5 then + error("Number of input arguments should be 5"); + end + + if argn(1)<1 | argn(1)>5 then + error("Number of output arguments should be 5"); + end + + if ~isscalar(Wo) | ~isreal(Wo) then + error("Wo must be real ,numeric and scalar"); + end + if Wo<=-1 | Wo>=1 then + error("Wo must lie between -1 and 1"); + end + + if ~isscalar(Wt) | ~isreal(Wt) then + error("Wt must be real and numeric and must contain only 2 elements"); + end + if Wt<=-1 | Wt>=1 then + error("Wt must lie between -1 and 1"); + end + + if ~isscalar(K) then + error("K must be a scalar"); + end +// Calculating the numerator and denominator for the mapping filter + AllpassNum = [0 1]*exp(%pi*%i*(Wt-Wo)); + AllpassDen = [1 0]; + + AllpassNum = flipdim((conj(AllpassNum)),2); + AllpassDen= flipdim((conj(AllpassDen)),2); + + if or(AllpassNum~=1) | or(AllpassDen~=1) then + Z2=[]; + P2=[]; + K2=K*prod(AllpassNum(1)-Z*AllpassDen(1))/prod(AllpassNum(1)-P*AllpassDen(1)); + + for i=1:length(Z), + Z2 = [Z2, roots(AllpassNum - Z(i).*AllpassDen).']; + end + for i=1:length(P), + P2 = [P2, roots(AllpassNum - P(i).*AllpassDen).']; + end +// For stabilizing the target filter (if unstable after tranformation) + index = find(abs(P2)>1); + K2 = K2/prod(1-P2(index)); + P2(index) = 1. /conj(P2(index)); + K2= K2*prod(1-P2(index)); + else + Z2=Z; + P2=P; + K2=K; + end + //Converting to Column vector + Z2=Z2(:); + P2=P2(:); + +endfunction From 143cf61eff31240870dc0c4f61e32818a4482365 Mon Sep 17 00:00:00 2001 From: Shrenik Nambiar Date: Tue, 25 Jul 2017 23:53:47 +0530 Subject: [PATCH 15/15] Delete Filter conversions.sce --- DSP functions/Filter conversions.sce | 38 ---------------------------- 1 file changed, 38 deletions(-) delete mode 100644 DSP functions/Filter conversions.sce diff --git a/DSP functions/Filter conversions.sce b/DSP functions/Filter conversions.sce deleted file mode 100644 index 46b10fc..0000000 --- a/DSP functions/Filter conversions.sce +++ /dev/null @@ -1,38 +0,0 @@ -// Zero,pole, gain frequency transformation - -b = [0.1969,0.4449,0.4449,0.1969]; //[b,a]=ellip(3,0.1,30,0.409) (taken from matlab) -a = [1.0000,-0.1737,0.5160,-0.0588]; -z = roots(b); -p = roots(a); -k = b(1); -[z1,p1,k1] = zpklp2mb(z, p, k, 0.5, [2 4 6 8]/10, 'pass'); -[xm,fr]=frmag(b,a,256); -[xm1,fr1]=frmag(real(k1)*real(poly(z1,'s')), real(poly(p1,'s')),256); -scf(0); -plot(fr*2,20*log(abs(xm))/log(10),'b',fr1*2,20*log(abs(xm1))/log(10),'r'); -xlabel('Normaliized Frequency'); -ylabel('Magnituse(dB)'); -title('Low pass to multi band pass'); -[z2,p2,k2] = zpklp2hp(z, p, k, 0.5, 0.8); -[xm2,fr2]=frmag(real(k2)*real(poly(z2,'s')), real(poly(p2,'s')),256); -scf(1); -plot(fr*2,20*log(abs(xm))/log(10),'b',fr2*2,20*log(abs(xm2))/log(10),'r'); -xlabel('Normaliized Frequency'); -ylabel('Magnituse(dB)'); -title('Low pass to high pass'); -// -[z3,p3,k3] = zpklp2bp(z, p, k, 0.5, [0.45,0.75]); -[xm3,fr3]=frmag(real(k3)*real(poly(z3,'s')), real(poly(p3,'s')),256); -scf(2); -plot(fr*2,20*log(abs(xm))/log(10),'b',fr3*2,20*log(abs(xm3))/log(10),'r'); -xlabel('Normaliized Frequency'); -ylabel('Magnituse(dB)'); -title('Low pass to band pass'); -// -[z4,p4,k4] = zpklp2bs(z, p, k, 0.5, [0.4,0.7]); -[xm4,fr4]=frmag(real(k4)*real(poly(z4,'s')), real(poly(p4,'s')),256); -scf(3); -plot(fr*2,20*log(abs(xm))/log(10),'b',fr4*2,20*log(abs(xm4))/log(10),'r'); -xlabel('Normaliized Frequency'); -ylabel('Magnituse(dB)'); -title('Low pass to band stop');