Académique Documents
Professionnel Documents
Culture Documents
PROCESSING
LAB
Name:Akashdeep Singh
Roll No.:2K11/EC/011
ECE C-1 batch
3rd year
Index
EXPERIMENT NO-1
OBJECTIVE: To determine frequency response of discrete LTI systems:
a) FIR
b) IIR
HARDWARE/SOFTWARE REQUIRED: MATLAB
THEORY: [h,w] = freqz(b,a,w) returns the frequency response vector h and the corresponding
angular frequency vector w for the digital filter whose transfer function is determined by the
(real or complex) numerator and denominator polynomials represented in the vectors b and a,
respectively.
b=[1 2 3 2 1]
a=[1 ]
eg. For IIR filter
H(z) =
The vectors h and w are both of length l. The angular frequency vector w has values ranging
from 0 to p radians per sample. When you don't specify the integer l, or you specify it as the
empty vector [ ], the frequency response is calculated using the default value of 512 samples.
freqz(b,a,...) plots the magnitude and unwrapped phase of the frequency response of the filter.
The plot is displayed in the current figure window.
PROGRAM:
FOR FIR FILTER
b=[1 2 3 4];
a=[1 ];
w=-pi:pi;
[h,w]=freqz(b,a,w);
freqz(b,a,w);
RESULT/OBSERVATIONS:
Freq. response of FIR filter
Magnitude
50
0
-50
-100
-150
Phase
(degrees)
-4
-3
-2
-1
Normalized Frequencyrad/sample)(
-2000
-1000
0
-1000
-2000
-4
-3
-2
-1
Normalized Frequencyrad/sample)(
Magnitude
-10
-20
(degrees)
-4
-3
-2
-1 0
Normalized Frequencyrad/sample)(
4000
2000
0
Phase
-2000
-4000
-4
-3
-2
-1 0
Normalized Frequencyrad/sample)(
EXPERIMENT NO-2
OBJECTIVE: To determine and implement n-point DFT algorithms.
HARDWARE/SOFTWARE REQUIREMENT: MATLAB
THEORY: Spectral analysis is the process of identifying component frequencies in data. For
discrete data, the computationa l basis of spectral analysis is the discrete Fourier transform
(DFT). The DFT transforms tim e- or space-based data into frequency-based data .
The DFT of a vector x of length n is another vector X of length n:
PROGRAM/CODE:
close all;
clear all;
N=input('How many point DFT do you want?');
x2=input('Enter the sequence='); n2=length(x2);
c= zeros(N);
x2=[x2 zeros(1,Nn2)]; for k=1:N
for n=1:N w=exp((-2*pi*i*(k1)*(n-1 ))/N);
%prev.step=>evaluating w matrix x(n)=w;
end
c(k,:)=x;
end
r=[c]*[x2']
%plotting magnitude and
angle subplot(211)
stem(abs(r)); title('DFTabsolute value');
subplot(212)
stem(angle(r));
title('DFT-angle');
RESULT:
How many point DFT do you want?4
Enter the sequence=[1 2 3 4]
r=
10.0000
-2.0000 + 2.0000i
-2.0000 - 0.0000i
-2.0000 - 2.0000i
DFT-absolute value
10
0 1
1.5
2.5
3.5
3.5
DFT-angle
4
2
0
- 2
- 4
1
1.5
2.5
EXPERIMENT NO-3
OBJECTIVE: To determine circular convolution of two
given sequences
HARDWARE/SOFTWARE REQUIRED: MATLAB
THEORY: Circular convolution is used to convolve two
discrete Fourier transform (DFT) sequences. For very long
sequences, circular convolution may be faster than linear
convolution.
The following exercises focus on the circular convolution
property of the DFT. An N point circular convolution is
defined as follows
j=mod(n-i,N);
y(n+1)=y(n+1)+x(i+1)*h(j+1); %shifting and adding end
end
%to display and plot circular convolution n=1:N;
disp('output sequence of circular convolution');
disp(y);%to view output in command window pause;
stem(n,y);%plotting circular convolution grid minor;
xlabel('time index'); ylabel('amplitude')
title('circular convolution sequence of x and h');
RESULT :
enter the first sequence[1 2 3 4] enter the
second sequence[1 2 3 4]
output sequence of circular
convolution: 26 28 26 20
EXPERIMENT NO: 4
OBJECTIVE: To determine and implement the Fast Fourier Transform algorithms
HARDWARE/SOFTWRE REQUIRED: MATLAB
THEORY:
PROGRAM/CODE:
Fs = 1000;
% Sampling frequency
T = 1/Fs;
% Sample time
L = 1000;
% Length of signal
t = (0:L-1)*T;
% Time vector
% Plot
single-sided
amplitude
spectrum. plot(f,2*abs(Y(1:NFFT/2)))
title('Single-Sided Amplitude Spectrum of
y(t)') xlabel('Frequency (Hz)')
ylabel('|Y(f)|')
WITHOUT FUNCTION
function y=mditfft(x)
x=input('Enter the Sequences')
m=nextpow2(x); n=2^m;
if length(x)<n
x=[x,zeros(1,n-length(x))];
end
nxd=bin2dec(fliplr(dec2bin([1:n]-1,m)))+1; y=x(nxd);
for mm=1:m le=2^mm;u=1; w=exp(-i*2*pi/le);
for j=1:le/2 for k=j:le:n kp=k+le/2; t=y(kp)*u; y(kp)=y(k)-t; y(k)=y(k)+t; end
u=u*w; end
end
RESULT/OBSRERVATION:
Single-Sided Amplitude Spectru
1
0.9
0.8
0.7
|Y(f)|
0.6
0.5
0.4
0.3
0.2
0.1
0 50 100 150 200 250 300 350 400 450 500 Frequency (Hz)
EXPERIMENT NO: 5
OBJECTIVE: To design an FIR low/high pass filter using windowing techniques
SOFTWARE/HARDWARE REQUIRED: MATLAB
THEORY:
FIR filter specification
First of all, it is necessary to learn the basic concepts that will be used further in this book. You
should be aware that without being familiar with these concepts, it is not possible to understand
analyses and synthesis of digital filters.
Figure 2-2-1 illustrates a low-pass digital filter specification. The word specification actually
refers to the frequency response specification.
Where:
fs is a sampling frequency;
f is a frequency to normalize; and
is normalized frequency.
Specifications for high-pass, band-pass and band-stop filters are defined almost the same way as
those for low-pass filters. Figure 2-2-2 illustrates a high-pass filter specification.
PROGRAM:
clc;
close all;
clear all;
format long;
rp=input('enter the passband ripple');
rs=input('enter the stopband ripple');
fp=input('enter the passband frequency');
fs=input('enter the stopband frequency');
f=input('enter the sampling frequency');
wp=2*(fp/f);
ws=2*(fs/f); num=20*log10(sqrt(rp*rs))-13;
dem=14.6*(fs-fp)/f;
n=ceil(num/dem);
n1=n+1;
if(rem(n,2)~=0)
n1=n;
n=n-1;
end;
y=boxcar(n1);
%Lowpass filter
b=fir1(n,wp,y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,1,1);
plot(o/pi,m);
ylabel('gain in db---->');
xlabel('Normalised frequency---->');
title('FIR filter using Rectangular window of LPF ----');
grid on;
%Highpass filter
b=fir1(n,wp,'high',y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,1,2);
plot(o/pi,m);
ylabel('gain in db---->');
xlabel('Normalised frequency---->');
title('FIR filter using Rectangular window of HPF ----');
0.04
0.05
EXPERIMENT-6
OBJECTIVE: To design an IIR low/high pas filter using bilinear technique.
SOFTWARE/HARDWRE REQUIRED: MATLAB
THEORY:
Bilinear transform is a correction of the backwards difference method.The bilinear transform
(also known as Tustin's transformation) is defined as the substitution.It is the most popular
method.The bilinear transform produces a digital filter whose frequency response has the same
characteristics as the frequency response of the analogue filter (but its impulse response may
then be quite different).
The bilinear transform:
In some sources you will see the factor (2/T) multiplying the RHS of the bilinear transform; this
is an optional scaling, but it cancels and does not affect the final result.
The steps of the bilinear transform method are as follows:
1. Warp the digital critical (e.g. band-edge or "corner") frequencies i ,
in other words compute the corresponding analogue critical frequencies i
= tan(i/2).
2. Design an analogue filter which satisfies the resulting filter response
specification.
3. Apply the bilinear transform
to the s-domain transfer function of the analogue filter to generate the required z-domain transfer
function.
PROGRAM:
clc;
clear all;
close all;
freqz(num,den);
%High Pass Filter
[N,Wn]=buttord(2,4.83,-3,-15, 's');
[b,a]=butter(N,Wn,'high','s');
[num,den]=bilinear(b,a,1);
figure;freqz(num,den);
RESULT:
ow pass filter
0
-50
-100
-150
Phase (degrees) Magnitude
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
0.8
0.9
0.8
0.9
Normalized Frequencyrad/sample)(
0
-50
-100
-150
L
0.2
0.3 o 0.4
0.5
0.6
0.7
w
Normalized Frequencyrad/sample)(
l
-200
0.1
Magnitude
-100
-200
-300
Phase
(degrees)
-400
0 0.1
0.2
0.3
0.4
0.5
0.6
0.7
Normalized Frequencyrad/sample)(
200
150
100
50
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
Normalized Frequencyrad/sample)(
EXPERIMENT NO-7
OBJECTIVE: To perform interpolation operation on a given signal.
SOFTWARE/HARDWRE REQUIRED: MATLAB
THEORY: yi = interp1(x,Y,xi) interpolates to find yi, the values of the underlying function Y at
the points in the vector or array xi. x must be a vector. Y can be a scalar, a vector, or an array of
any dimension, subject to the following conditions:
If Y is a vector, it must have the same length as x. A scalar value for Y is expanded to
have the same length as x. xi can be a scalar, a vector, or a multidimensional array, and yi
has the same size as xi.
If Y is an array that is not a vector, the size of Y must have the form [n,d1,d2,...,dk],
where n is the length of x. The interpolation is performed for each d1-by-d2-by-...-dk
value in Y. The sizes of xi and yi are related as follows:
o If xi is a scalar or vector, size(yi) equals [length(xi), d1, d2, ..., dk].
o If xi is an array of size [m1,m2,...,mj], yi has size [m1,m2,...,mj,d1,d2,...,dk].
yi = interp1(Y,xi) assumes that x = 1:N, where N is the length of Y for vector Y, or size(Y,1) for
matrix Y.
yi = interp1(x,Y,xi,method) interpolates using alternative methods:
'nearest' Nearest neighbor interpolation
'linear'
'spline'
'pchip'
'cubic'
(Same as 'pchip')
'v5cubic' Cubic interpolation used in MATLAB 5. This method does not extrapolate. Also, if x
is not equally spaced, 'spline' is used/
For the 'nearest', 'linear', and 'v5cubic' methods, interp1(x,Y,xi,method) returns NaN for any
element of xi that is outside the interval spanned by x. For all other methods, interp1 performs
extrapolation for out of range values.
yi = interp1(x,Y,xi,method,'extrap') uses the specified method to perform extrapolation for out of
range values.
yi = interp1(x,Y,xi,method,extrapval) returns the scalar extrapval for out of range values. NaN
and 0 are often used for extrapval.
PROGRAM:
x = 0:10;
y = sin(x);
xi = 0:.25:10;
yi = interp1(x,y,xi);
plot(x,y,'o',xi,yi)
RESULT:
1
0.8
0.6
0.4
0.2
0
-0.2
-0.4
-0.6
-0.8
-1
0
10
EXPERIMENT NO.-8
OBJECTIVE: To perform decimation operation on a given signal.
SOFTWARE/HARDWARE REQUIRED: MATLAB
THEORY: Decimation reduces the original sampling rate for a sequence to a lower rate, the
opposite of interpolation. The decimation process filters the input data with a lowpass filter and
then resamples the resulting smoothed signal at a lower rate.
y = decimate(x,r) reduces the sample rate of x by a factor r. The decimated vector y is r times
shorter in length than the input vector x. By default, decimate employs an eighth-order lowpass
Chebyshev Type I filter with a cutoff frequency of 0.8*(Fs/2)/r. It filters the input sequence in
both the forward and reverse directions to remove all phase distortion, effectively doubling the
filter order.
y = decimate(x,r,n) uses an order n Chebyshev filter. Orders above 13 are not recommended
because of numerical instability. In this case, a warning is displayed.
PROGRAM/CODE:
t = 0:.00025:1;
% Time vector
x = sin(2*pi*30*t) + sin(2*pi*60*t);
y = decimate(x,4);
%View the original and decimated signals:
stem(x(1:120)), axis([0 120 -2 2]) % Original signal
title('Original Signal')
figure
stem(y(1:30))
title('Decimated Signal')
% Decimated signal
RESULT:
Original Signal
2
1.5
1
0.5
0
-0.5
-1
-1.5
-2
0
20
40
60
80
100
120
20
25
30
Decimated Signal 2
1.5
1
0.5
0
-0.5
-1
-1.5
-2
0
10
15