EC-553 Advanced Signal Processing Laboratory 2014
1 Department of Elect. and Comm. Engg. , Dr. B R Ambedkar National Institute of Technology, Jalandhar
Experiment No:-[1] EXPERIMENT: - Generate basic signals using matlab.
SOFTWARE REQUIRED: - Matlab 7.12.0. THEORY:-1) The sine wave or sinusoid is a mathematical curve that describes a smooth repetitive oscillation. L=sin(2*pi*f*t) 2) A square wave is a non-sinusoidal periodic waveform (which can be represented as an infinite summation of sinusoidal waves), in which the amplitude alternates at a steady frequency between fixed minimum and maximum values, with the same duration at minimum and maximum. 3) In mathematics, a function on the real numbers is called a step function (or staircase function) if it can be written as a finite linear combination of indicator functions of intervals. Informally speaking, a step function is a piecewise constant function having only finitely many pieces.
4) The ramp function is a unary real function, easily computable as the mean of the independent variable and its absolute value.
5) In mathematics, the Dirac delta function, or function, is a generalized function, or distribution, on the real number line that is zero everywhere except at zero, with an integral of one over the entire real line.
6) The sawtooth wave (or saw wave) is a kind of non-sinusoidal waveform. It is so named based on its resemblance to the teeth of a saw.
MATLAB CODE:-clear all;close all; clc; t1=-2:0.01:2; f=1;%SINE FUNCTIONL=sin(2*pi*f*t1);subplot(3,2,1);plot(t1,L);xlabel('Time'); ylabel('Amplitude'); title('Sine Funcion'); %STEP FUNCTION
EC-553 Advanced Signal Processing Laboratory 2014
2 Department of Elect. and Comm. Engg. , Dr. B R Ambedkar National Institute of Technology, Jalandhar
t2=-4:0.5:4;M=[0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1];subplot(3,2,2);stem(t2,M);xlabel('Time');ylabel('Amplitude'); title('Step Function'); %RAMP FUNCTION t3=0:0.01:5;a=4;N=a*t3;subplot(3,2,3);plot(t3,N);title('Ramp Funcion');xlabel('Time'); ylabel('Amplitude'); %SQUARE FUNCTIONfor t= 1:1:401 if L(t)>0 O(t)=1; else O(t)=0; end end subplot(3,2,4);plot(O);xlabel('Time'); ylabel('Amplitude'); title('Square Function'); %IMPULSE FUNCTIONt4=-4:1:4;P=[0 0 0 0 1 0 0 0 0]; subplot(3,2,5)stem(t4,P); xlabel('Time'); ylabel('Amplitude'); title('Impulse Function'); %SAWTOOTH FUNCTION x=0:1:5; for i=1:length(x) y(i)=x(i); end Q=repmat(y,1,3);subplot(3,2,6)stem(Q); xlabel('Time'); ylabel('Amplitude'); title('Sawtooth Function'); RESULTS: - We have successfully generated basic signals using matlab.
EC-553 Advanced Signal Processing Laboratory 2014
3 Department of Elect. and Comm. Engg. , Dr. B R Ambedkar National Institute of Technology, Jalandhar
CONCLUSION: - The entire basic function performed successfully using MATLAB. Basic of signals are revised and also the command sine, repmat familiarized.
EC-553 Advanced Signal Processing Laboratory 2014
4 Department of Elect. and Comm. Engg. , Dr. B R Ambedkar National Institute of Technology, Jalandhar
Experiment No:-[2] EXPERIMENT:-Perform linear convolution of two sequences. SOFTWARE REQUIRED: - Matlab 7.12.0.
THEORY:-
The convolution of f and g is written f g, using a star. It is defined as the integral of the product of the two functions after one is reversed and shifted. As such, it is a particular kind of integraltransform.
MATLAB CODE:-% Convolution clear all;close all; clc; a=input('enter a sequence'); b=input('enter b sequence');La=length(a); Lb=length(b); y=zeros(1,La+Lb-1);a=[a,zeros(1,Lb-1)];b=[b,zeros(1,La-1)];for n=1:La+Lb-1; y(n)=0; for i=1:n; y(n)=y(n)+a(i)*b(n-i+1); endend subplot(3,1,1);stem(a);xlabel('time');ylabel('amplitude'); title('first signal');subplot(3,1,2);stem(b); xlabel('time');ylabel('amplitude'); title('second signal'); subplot(3,1,3);stem(y); xlabel('time');ylabel('amplitude'); title('convolution of 1st and 2nd signal');
EC-553 Advanced Signal Processing Laboratory 2014
5 Department of Elect. and Comm. Engg. , Dr. B R Ambedkar National Institute of Technology, Jalandhar
enter a sequence [1 1 0 1 1]
enter b sequence [1 0 1 0 1]
a = 1 1 0 1 1 0 0 0 0
b = 1 0 1 0 1 0 0 0 0
y = 1 1 1 2 2 2 1 1 1
RESULTS: - We have successfully performed linear convolution of two sequence using matlab.
CONCLUSION: - The convolution of two sequences is done using matlab and result can be shown in the above figure.
EC-553 Advanced Signal Processing Laboratory 2014
6 Department of Elect. and Comm. Engg. , Dr. B R Ambedkar National Institute of Technology, Jalandhar
Experiment No:-[3] EXPERIMENT: - To perform cross correlation of two sequences using matlab. SOFTWARE REQUIRED: - Matlab 7.12.0.
THEORY:-The autocorrelation function of a random signal describes the general dependence of the values of the samples at one time on the values of the samples at another time. Consider a random process x(t) (i.e. continuous-time), its autocorrelation function is written as:
Where T is the period of observation.
always real-valued and an even function with a maximum value at 0. The cross correlation function however measures the dependence of the values of one signal onanother signal. For two WSS (Wide Sense Stationary) processes x(t) and y(t) it is described by:
MATLAB CODE:-% Cross-correlation clc; clear all;close all; x=input('Enter the first Sequence : ');subplot(3,1,1);stem(x); xlabel('Sample');ylabel('Amplitude'); title('First Sequence');h=input('Enter the second sequence : ');subplot(3,1,2);stem(h); xlabel('Sample');ylabel('Amplitude'); title('Second Sequence'); n=length(x);m=length(h);k=n+m-1;x=[x zeros(1,k-n)]'; h=wrev(h); h=[h zeros(1,k-m)]'; for i=1:kc(:,i)=circshift(x,i-1); end y=c*h; subplot(3,1,3);stem(y);
EC-553 Advanced Signal Processing Laboratory 2014
7 Department of Elect. and Comm. Engg. , Dr. B R Ambedkar National Institute of Technology, Jalandhar
xlabel('Sample');ylabel('Amplitude'); title('Cross-correlation Sequence'); Enter the first Sequence: [1 0 1 0 0 1]Enter the second sequence: [0 1 1 0 1 0]
RESULTS: - We have successfully performed cross correlation of two sequences using matlab.
CONCLUSION: - The cross correlation of two sequences is done using matlab and result can be shown in the above figure.
EC-553 Advanced Signal Processing Laboratory 2014
8 Department of Elect. and Comm. Engg. , Dr. B R Ambedkar National Institute of Technology, Jalandhar
Experiment No:-[4] EXPERIMENT: - To perform fast fourier transform (FFT) and inverse fast fourier transform using matlab. SOFTWARE REQUIRED: - Matlab 7.12.0.
THEORY:-
An FFT computes the DFT and produces exactly the same result as evaluating the DFT definition directly; the most important difference is that an FFT is much faster. (In the presence of round-off error, many FFT algorithms are also much more accurate than evaluating the DFT definition directly, as discussed below.)
Let x0, ...., xN-1 be complex numbers. The DFT is defined by the formula
= e k=0, 1., N-1
The IDFT is defined by the formula
= e n=0, 1., N-1 MATLAB CODE:-% FFT and IFFT clear all;close all; clc; x=input('enter sequence'); y=fft(x);subplot(2,1,1);stem(abs(y));xlabel('Time'); ylabel('Amplitude'); title('FFT');z=ifft(y);subplot(2,1,2)stem(z);xlabel('Time'); ylabel('Amplitude'); title('IFFT'); enter sequence [1 1 0 1 1 0 1 1]
EC-553 Advanced Signal Processing Laboratory 2014
9 Department of Elect. and Comm. Engg. , Dr. B R Ambedkar National Institute of Technology, Jalandhar
RESULTS: - We have successfully performed fast fourier transform (FFT) and inverse fast fourier transform using matlab.
CONCLUSION: - The fast fourier transform and inverse fast fourier transform is done using matlab and result can be shown in the above figure.
EC-553 Advanced Signal Processing Laboratory 2014
10 Department of Elect. and Comm. Engg. , Dr. B R Ambedkar National Institute of Technology, Jalandhar
Experiment No:-[5] EXPERIMENT: - To perform fast Z-transform and inverse Z-transform using matlab. SOFTWARE REQUIRED: - Matlab 7.12.0.
THEORY:-
The bilateral or two-sided Z-transform of a discrete-time signal x[n] is the formal power seriesX(z) defined as
X(z) = { [ ]} = [ ]
where n is an integer and z is, in general, a complex number
= = A(cos + jsin ) where A is the magnitude of z, j is the imaginary unit, and is the complex argument (also referred to as angle or phase) in radians.
The inverse Z-transform is
x[n] = {X(z)} = X(z)zn 1dz
MATLAB CODE:-% Z-transform and inverse Z-transform close all; clear all;clc; syms n ; f=input('enter the function: '); sprintf(' ztransformation\n') L=ztrans(f); disp(L);sprintf('inverse ztransformation\n') M=iztrans(L);disp(M); enter the function: sin(n) ztransformation: (z*sin(1))/(z^2 - 2*cos(1)*z + 1) inverse ztransformation: sin(n)
RESULTS: - We have successfully performed Z-transform and inverse Z-transform using matlab.
CONCLUSION: - The Z-transform and inverse Z-transform is done using matlab and result can be shown in the above figure.
EC-553 Advanced Signal Processing Laboratory 2014
11 Department of Elect. and Comm. Engg. , Dr. B R Ambedkar National Institute of Technology, Jalandhar
Experiment No:-[6] EXPERIMENT: - To perform IIR Butterworth filter using matlab.
SOFTWARE REQUIRED: - Matlab 7.12.0.
THEORY:-Butterworth filters are causal in nature and of various orders, the lowest order being the best(shortest) in the time domain, and the higher orders being better in the frequency domain.Butterworth or maximally flat filters have a monotonic amplitude frequency response which ismaximally flat at zero frequency response and the amplitude frequency response decreases logarithmically with increasing frequency. The Butterworth filter has minimal phase shift over the filter's band pass when comparied to other conventional filters.
( ) ( ) =1
1 +
MATLAB CODE:-% IIR Butterworth close all; clear all;clc; display(sprintf('for LPF a=1\nfor HPF a=2\nfor BPF a=3\nfor BSF a=4'));a=input('enter a value of a='); Nq = input('Enter the value of sampling frequency\n'); wp=input('enter pass band corner frequency = ');ws=input('enter stop band corner frequency = '); Rp=input('enter pass band ripple in db = ');Rs=input('enter stop band attenuation in db = '); Wp = wp/Nq; Ws = ws/Nq; [n,Wn] = buttord(Wp,Ws,Rp,Rs); if (a==1) [b,a] = butter(n,Wn,'low');end if(a==2) [b,a] = butter(n,Wn,'high'); end if(a==3) [b,a] = butter(n,Wn,'bandpass'); endif(a==4) [b,a] = butter(n,Wn,'stop'); end [n,Wn] = buttord(Wp,Ws,Rp,Rs); fprintf('Order of filter =%i\n', n);[h w]=freqz(b,a);plot(w/pi,20*log10(abs(h)));phase_h=angle(h); figure;plot(w/pi,phase_h);
EC-553 Advanced Signal Processing Laboratory 2014
12 Department of Elect. and Comm. Engg. , Dr. B R Ambedkar National Institute of Technology, Jalandhar
COMMAND WIDOW:-
for low pass filter
for LPF a=1
for HPF a=2
for BPF a=3
for BSF a=4
enter a value of a=1
Enter the value of sampling frequency 4000
enter pass band corner frequency = 1500
enter stop band corner frequency = 2000
enter pass band ripple in db = 1
enter stop band attenuation in db = 5
Order of filter =3
EC-553 Advanced Signal Processing Laboratory 2014
13 Department of Elect. and Comm. Engg. , Dr. B R Ambedkar National Institute of Technology, Jalandhar
for high pass filter
for LPF a=1
for HPF a=2
for BPF a=3
for BSF a=4
enter a value of a=2
Enter the value of sampling frequency
4000
enter pass band corner frequency = 2000
enter stop band corner frequency = 1500
enter pass band ripple in db = 1
enter stop band attenuation in db = 5
Order of filter =3
EC-553 Advanced Signal Processing Laboratory 2014
14 Department of Elect. and Comm. Engg. , Dr. B R Ambedkar National Institute of Technology, Jalandhar
EC-553 Advanced Signal Processing Laboratory 2014
15 Department of Elect. and Comm. Engg. , Dr. B R Ambedkar National Institute of Technology, Jalandhar
for band pass filter
for LPF a=1
for HPF a=2
for BPF a=3
for BSF a=4
enter a value of a=3
Enter the value of sampling frequency
4000
enter pass band corner frequency = [1000 3000]
enter stop band corner frequency = [500 3500]
enter pass band ripple in db = 1
enter stop band attenuation in db = 5
Order of filter =2
EC-553 Advanced Signal Processing Laboratory 2014
16 Department of Elect. and Comm. Engg. , Dr. B R Ambedkar National Institute of Technology, Jalandhar
for band stop filter
for LPF a=1
for HPF a=2
for BPF a=3
for BSF a=4
enter a value of a=4
Enter the value of sampling frequency
4000
enter pass band corner frequency = [500 3500]
enter stop band corner frequency = [1000 3000]
enter pass band ripple in db = 1
enter stop band attenuation in db = 5
Order of filter =2
EC-553 Advanced Signal Processing Laboratory 2014
17 Department of Elect. and Comm. Engg. , Dr. B R Ambedkar National Institute of Technology, Jalandhar
RESULTS: - We have successfully performed IIR Butterworth filter using matlabCONCLUSION: - The IIR Butterworth filter is done using matlab and result can be shown in the above figure.
EC-553 Advanced Signal Processing Laboratory 2014
18 Department of Elect. and Comm. Engg. , Dr. B R Ambedkar National Institute of Technology, Jalandhar
Experiment No:-[7] EXPERIMENT: - To perform IIR Chebyshev Type I filter using matlab.
SOFTWARE REQUIRED: - Matlab 7.12.0.
THEORY:-Chebyshev filters are of two types: Chebyshev I filters are all pole filters which are equiripple in the passband and are montonic in the stopband.The frequency response of the filter is given by
| ( )| =1
1 + ( )(( ) )
where is a parameter related to the ripple present in the passband Tn = cos(ncos-1x) |x| 1
cos(ncosh-1x) |x| 1
MATLAB CODE:-% IIR Chebyshev Type I filter designclose all; clear all;clc; display(sprintf('for LPF a=1\nfor HPF a=2\nfor BPF a=3\nfor BSF a=4'));a=input('enter a value of a='); Nq = input('Enter the value of sampling frequency\n'); wp = input('Enter the value of passband corner frequency\n'); ws = input('Enter the value of stopband corner frequency\n');wpn = wp/Nq; wsn = ws/Nq; Rp = input('Enter the value of passband ripple in db\n'); Rs = input('Enter the value of stopband attenuation in db\n');if (a==1) ftype = 'low'; end if(a==2) ftype = 'high';end if(a==3) ftype = 'bandpass'; end if(a==4) ftype = 'stop';end [n,Wn] = cheb1ord(wpn,wsn,Rp,Rs);fprintf('Order of filter =%i\n', n);[b,a] = cheby1(n,Rp,wpn,ftype); h1=dfilt.df2(b,a); [z, p, k] = cheby1(n,Rp,wpn,ftype); [sos,g]=zp2sos(z,p,k); h2=dfilt.df2sos(sos,g);
EC-553 Advanced Signal Processing Laboratory 2014
19 Department of Elect. and Comm. Engg. , Dr. B R Ambedkar National Institute of Technology, Jalandhar
hfvt=fvtool(h1,h2,'FrequencyScale','log');legend(hfvt,'TF Design');
COMMAND WIDOW:-
for low pass filter
for LPF a=1
for HPF a=2
for BPF a=3
for BSF a=4
enter a value of a=1
Enter the value of sampling frequency 4000
Enter the value of passband corner frequency 2000
Enter the value of stopband corner frequency 1500
Enter the value of passband ripple in dbn 1
Enter the value of stopband attenuation in db 5
Order of filter =2
EC-553 Advanced Signal Processing Laboratory 2014
20 Department of Elect. and Comm. Engg. , Dr. B R Ambedkar National Institute of Technology, Jalandhar
for high pass filter
for LPF a=1 for HPF a=2for BPF a=3 for BSF a=4 enter a value of a=2Enter the value of sampling frequency 4000Enter the value of passband corner frequency1000Enter the value of stopband corner frequency900Enter the value of passband ripple in db1Enter the value of stopband attenuation in db10Order of filter =6
EC-553 Advanced Signal Processing Laboratory 2014
21 Department of Elect. and Comm. Engg. , Dr. B R Ambedkar National Institute of Technology, Jalandhar
for band pass filter
for LPF a=1
for HPF a=2
for BPF a=3
for BSF a=4
enter a value of a=3
Enter the value of sampling frequency 4000
Enter the value of passband corner frequency [500 3500]
Enter the value of stopband corner frequency [400 3600]
Enter the value of passband ripple in db 1
Enter the value of stopband attenuation in db 5
Order of filter =3
EC-553 Advanced Signal Processing Laboratory 2014
22 Department of Elect. and Comm. Engg. , Dr. B R Ambedkar National Institute of Technology, Jalandhar
for band stop filter
for LPF a=1
for HPF a=2
for BPF a=3
for BSF a=4
enter a value of a=4
Enter the value of sampling frequency 4000
Enter the value of passband corner frequency [400 3600]
Enter the value of stopband corner frequency [500 3500]
Enter the value of passband ripple in db 1
Enter the value of stopband attenuation in db 5
Order of filter =3
RESULTS: - We have successfully performed IIR Chebyshev Type I filter using matlab.
CONCLUSION: - The IIR Chebyshev Type I filter is done using matlab and result can be shown in the above figure.
EC-553 Advanced Signal Processing Laboratory 2014
23 Department of Elect. and Comm. Engg. , Dr. B R Ambedkar National Institute of Technology, Jalandhar
Experiment No:-[8] EXPERIMENT: - To perform IIR Chebyshev Type II filter using matlab.
SOFTWARE REQUIRED: - Matlab 7.12.0.
THEORY:-Chebyshev II filters contain both poles and zeros exhibiting a montonic behavior in the passband and equi-ripple in the stopband.The frequency response of the filter is given by
| ( )| =1
1 + ( )(( ) )
where is a parameter related to the ripple present in the passband TN = cos(Ncos-1x) |x| 1
cos(Ncosh-1x) |x| 1
MATLAB CODE:-% IIR Chebyshev Type II filter designclose all; clear all;clc; display(sprintf('for LPF a=1\nfor HPF a=2\nfor BPF a=3\nfor BSF a=4'));a=input('enter a value of a='); Nq = input('Enter the value of sampling frequency\n'); wp = input('Enter the value of passband corner frequency\n'); ws = input('Enter the value of stopband corner frequency\n');wpn = wp/Nq; wsn = ws/Nq; Rp = input('Enter the value of passband ripple in db\n'); Rs = input('Enter the value of stopband attenuation in db\n');if (a==1) ftype = 'low'; end if(a==2) ftype = 'high';end if(a==3) ftype = 'bandpass';end if(a==4) ftype = 'stop'; end [n,Wn] = cheb2ord(wpn,wsn,Rp,Rs);fprintf('Order of filter =%i\n', n);[b,a] = cheby2(n,Rp,wpn,ftype); h1=dfilt.df2(b,a); [z, p, k] = cheby2(n,Rp,wpn,ftype); [sos,g]=zp2sos(z,p,k);
EC-553 Advanced Signal Processing Laboratory 2014
24 Department of Elect. and Comm. Engg. , Dr. B R Ambedkar National Institute of Technology, Jalandhar
h2=dfilt.df2sos(sos,g);hfvt=fvtool(h1,h2,'FrequencyScale','log');legend(hfvt,'TF Design','ZPK Design');
COMMAND WIDOW:-
For Low Pass Filter
for LPF a=1
for HPF a=2
for BPF a=3
for BSF a=4
enter a value of a=1
Enter the value of sampling frequency 4000
Enter the value of passband corner frequency 2000
Enter the value of stopband corner frequency 1500
Enter the value of passband ripple in db 1
Enter the value of stopband attenuation in db 5
Order of filter =2
EC-553 Advanced Signal Processing Laboratory 2014
25 Department of Elect. and Comm. Engg. , Dr. B R Ambedkar National Institute of Technology, Jalandhar
for high pass filter
for LPF a=1
for HPF a=2
for BPF a=3
for BSF a=4
enter a value of a=2
Enter the value of sampling frequency 4000
Enter the value of passband corner frequency 200
Enter the value of stopband corner frequency 100
Enter the value of passband ripple in db 1
Enter the value of stopband attenuation in db 5
Order of filter =2
EC-553 Advanced Signal Processing Laboratory 2014
26 Department of Elect. and Comm. Engg. , Dr. B R Ambedkar National Institute of Technology, Jalandhar
for band pass filter
for LPF a=1
for HPF a=2
for BPF a=3
for BSF a=4
enter a value of a=3
Enter the value of sampling frequency 4000
Enter the value of passband corner frequency [200 3800]
Enter the value of stopband corner frequency [150 3850]
Enter the value of passband ripple in db 1
Enter the value of stopband attenuation in db 5
Order of filter =3
EC-553 Advanced Signal Processing Laboratory 2014
27 Department of Elect. and Comm. Engg. , Dr. B R Ambedkar National Institute of Technology, Jalandhar
for band stop filter
for LPF a=1
for HPF a=2
for BPF a=3
for BSF a=4
enter a value of a=4
Enter the value of sampling frequency 4000
Enter the value of passband corner frequency [500 3500]
Enter the value of stopband corner frequency [1000 3000]
Enter the value of passband ripple in db 1
Enter the value of stopband attenuation in db 5
Order of filter =2
RESULTS: - We have successfully performed IIR Chebyshev Type II filter using matlab. CONCLUSION: - The IIR Chebyshev Type II filter is done using matlab and result can be shown in the above figure.
EC-553 Advanced Signal Processing Laboratory 2014
28 Department of Elect. and Comm. Engg. , Dr. B R Ambedkar National Institute of Technology, Jalandhar
Experiment No:-[9] EXPERIMENT: - To perform Low Pass Filtering of Noise Signal using matlab. SOFTWARE REQUIRED: - Matlab 7.12.0.
THEORY:-
The Low Pass Filter removes higher frequency components above cut off frequency. We take sine wave signal and for adding noise another sine wave signal add in first signal. To remove the noise means high frequency use Low Pass Filter which removes higher frequency components above cut off frequency.
MATLAB CODE:-% Low Pass Filtering of Noise Signalclose all; clear all;clc; t=0:0.001:1;fs=200;wc=6; wc=2*wc/fs;x=sin(2*pi*10*t); y=x+sin(2*pi*50*t);b=fir1(48,wc); freqz(b,1,512);a=filter(b,1,y); subplot(3,1,1);plot(x);subplot(3,1,2);plot(y);subplot(3,1,3);plot(a);
EC-553 Advanced Signal Processing Laboratory 2014
29 Department of Elect. and Comm. Engg. , Dr. B R Ambedkar National Institute of Technology, Jalandhar
RESULTS: - We have successfully performed Low Pass Filtering of Noise Signal using matlab.
CONCLUSION: - The done Low Pass Filtering of Noise Signal using matlab and result can be shown in the above figure.