Professional Documents
Culture Documents
3.new DSP Lab DOC
3.new DSP Lab DOC
3.new DSP Lab DOC
1
Exc.No.
GENERATION OF RANDOM SIGNALS
Dt.
EQUIPMENT:
THEORY:
1, for n 0
Unit impulse sequence. x (n) (n)
0, otherwise
1, for n 0
Unit step sequence. x (n) u(n)
0, otherwise
n, for n 0
Unit ramp sequence. x (n) r (n)
0, otherwise
Sinusoidal sequence. x (n) A sin(n ) .
Exponential sequence. x(n) = A a n, where A and a are
constant.
PROCEDURE:
Source code :
%DT SIGNAL
%UNIT IMPULSE
clc;
clear all;
close all;
n0=input('enter the value of n0');
n1=input('enter the value of n1');
n2=input('enter the value of n2');
[x,n]=impseq(n0,n1,n2);
stem(n,x);
xlabel('n');
ylabel('x(n)');
clc;
clear all;
close all;
n0=input('enter the value of n0');
n1=input('enter the value of n1');
n2=input('enter the value of n2');
%EXPONENTIAL SIGNAL
clc;
clear all;
close all;
a=input('enter the value of a');
n=[0:10];
x=a.^n;
stem(x);
xlabel('n');
ylabel('x(n)');
title('exponential seq');
%UNIT RAMP SIGNAL
n=-10:10;
x=n;
stem(n,x);
xlabel('time');
ylabel('Amplitude');
title('Unit ramp signal');
%SINUSOIDAL SIGNAL
clc;
clear all;
close all;
A=input('Enter the amplitude:');
0.9
0.8
0.7
0.6
x(n)
0.5
0.4
0.3
0.2
0.1
0
-10 -8 -6 -4 -2 0 2 4 6 8 10
n
0.9
0.8
0.7
x(n) 0.6
0.5
0.4
0.3
0.2
0.1
0
-10 -8 -6 -4 -2 0 2 4 6 8 10
n
3)exponential sequence
exponential seq
1
0.9
0.8
0.7
0.6
x(n)
0.5
0.4
0.3
0.2
0.1
0
1 2 3 4 5 6 7 8 9 10 11
n
4).Unit Ramp
Amplitude 2
-2
-4
-6
-8
-10
-10 -8 -6 -4 -2 0 2 4 6 8 10
time
5)Sinusoidal sequence:
Sinusoidal signal
2
1.5
1
Amplitude
0.5
-0.5
-1
-1.5
-2
-2 -1.5 -1 -0.5 0 0.5 1 1.5 2
time
Viva questions:
Exp.No. 2
Exc.No.
ENERGY AND POWER OF A SIGNAL
Dt.
Aim: Write a program in MATLAB to find energy and power of given signal
Theory:
clear all;
close all;
clc;
n= 0:0.01:4;
x = cos(2*pi*n);
M = length(x);
sum = 0;
for i = 1:M,
sum = sum + x(i)*x(i);
end;
disp('Energy of the given sequence is ..... :: ');
Energy = sum;
disp(Energy);
disp('Average Power of the given sequence is ..... :: ');
Average_power = sum/M;
disp(Average_power);
PROCEDURE:
Output:
Result:
Viva Questions:
Exp.No. 3 a)
Exc.No.
LINEAR CONVOLUTION
Dt.
EQUIPMENT:
y[n] = x[n]*h[n] = or
If the input x[n] has N1 samples and impulse response h[n] has N2 samples then the output
sequence y[n] will be a finite duration sequence consisting of (N 1 + N2 - 1) samples. The
convolution results in a non periodic sequence called Aperiodic convolution.
4. Summation: Find the sum of all the values of the product sequence to obtain values of
output at n = n0
Repeat steps 2 to 4 for all possible time shifts ‘n0’ in the range - <n<
Eg: x[n]={1, 2, 3, 4}
h[k]={1, 2, 3, 4}
where n=4, k=4.; size of n&k should be a multiple of 4.
If n & k are not multiples of 4, pad with zero’s to make multiples of 4
r=n+k-1; size of output sequence
=4+4-1
=7
r=0 0 1 2 3 4 5 6
Program
PROCEDURE:
OUTPUT:
4
---->x(n)
---->h(n)
2 0
-2 -5
0 5 10 0 5 10
---->n ---->n
convolution of x(n) & h(n) is :
40
30
---->y(n)
20
10
-10
1 2 3 4 5 6 7 8
---->n
Result:
Exc.No.
Dt.
AIM: Write a program in MATLAB to find cross and auto correlation of a two given sequences
EQUIPMENT:
x=[x zeros(1,k-n)]';
h=wrev(h);
h=[h zeros(1,k-m)]';
for i=1:k
c(:,i)=circshift(x,i-1);
end
y=c*h;
disp('Correlation of the sequences')
disp(y');
subplot(2,2,[3,4]),stem(y);
title('crosscorrelation of x(n) & h(n) is :');
xlabel('---->n');
ylabel('---->y(n)');grid;
PROCEDURE:
---->x(n)
---->h(n)
4 4
2 2
0 0
1 2 3 4 1 2 3 4 5
---->n ---->n
crosscorrelation of x(n) & h(n) is :
60
---->y(n)
40
20
0
1 2 3 4 5 6 7 8
---->n
Auto correlation
Result:
VIVA QUESTIONS
1. What is the requirement for convolution?
2. What is the difference between convolution & correlation?
3. What is meant by impulse response?
4. Is it possible to represent any discrete time signal in terms of impulses? If yes, represent by using
an example.
5. Draw the h(2n-k) & h(n-2k) for the following sequence h(n) = { 4 3 2 1} assume (i) k= 3
(ii) k =5.
6. Write the expressions for LTI system convolution formula & causal LTI system convolution
formula.
7. What is the length of linear convolution if length of input & impulse responses are N1 & N2
respectively?
8. What is the difference between continuous and discrete convolution?
Exp.No. 4
Exc.No.
DTFT OF A GIVEN SIGNAL
Dt.
EQUIPMENT:
clc;
clear all;
close all;
x=input('enter the input seq');
n=length(x);
n=1:n;
%n = -1:3;
%x = 1:5;
k = 0:500;
w = (pi/500)*k;
X = x * (exp(-j*pi/500)) .^ (n'*k);
magX = abs(X);
angX = angle(X);
realX = real(X);
imagX = imag(X);
subplot(2,2,1);
plot(k/500,magX);grid
xlabel('frequency in pi units');
title('Magnitude Part')
subplot(2,2,3);
plot(k/500,angX/pi);grid
xlabel('frequency in pi units');
title('Angle Part')
subplot(2,2,2);
plot(k/500,realX);grid
xlabel('frequency in pi units');
title('Real Part')
subplot(2,2,4);
plot(k/500,imagX);grid
xlabel('frequency in pi units');
title('Imaginary Part')
PROCEDURE:
Output:
5 0
-5
0 -10
0 0.5 1 0 0.5 1
frequency in pi units frequency in pi units
Angle Part Imaginary Part
1 5
0.5
0
0
-5
-0.5
-1 -10
0 0.5 1 0 0.5 1
frequency in pi units frequency in pi units
Result:
Exp.No. 5
Exc.No.
N-Point FFT
Dt.
AIM:
Write a MATLAB program to perform the Discrete Fourier Transform for the given
sequences.
Write a MATLAB Script to compute Discrete Fourier Transform and Inverse Discrete
Fourier Transform of the given sequence using FFT algorithms (DIT-FFT & DIF-FFT)
EQUIPMENT:
COMPUTATION OF DFT:
FFT is a method of having computationally efficient algorithms for the execution of DFT,
under the approach of Divide and Conquer. The number of computations can be reduced in N point
DFT for complex multiplications to N/2log2N and for complex addition to N/2log2N.
x [n] =
where, wN=e-j2/N.
N x*[n] =
The right hand side of the equation is the DFT of the sequence X*(k). Now x[n] can be found
by taking the complex conjugate of the DFT and dividing by N to give,
x [n]=
The idea is to successively split the N-point time domain sequence into smaller sub
sequence. Initially the N-point sequence is split into x e[n] and xo[n], which have the even and
odd indexed samples of x[n] respectively. The N/2 point DFT’s of these two sequences are
evaluated and combined to give N-point DFT. Similarly N/2 point sequences are represented as
a combination of two N/4 point DFT’s. This process is continued, until we are left with 2 point
DFT.
The output sequence X(k) is divided into smaller sequence.. Initially x[n] is divided
into two sequences x1[n], x2[n] consisting of the first and second N/2 samples of x[n]
respectively. Then we find the N/2 point sequences f[n] and g[n] as
f[n]= x1[n]+x2[n],
The N/2 point DFT of the 2 sequences gives even and odd numbered output samples. The above
procedure can be used to express each N/2 point DFT as a combination of two N/4 point DFTs.
This process is continued until we are left with 2 point DFT.
LIBRARY FUNCTION:
ALGORITHM/PROCEDURE:
clc;
clear all;
close all;
x = input('Enter the input sequence = ');
N = length(x);
for k = 1:N
y(k) = 0;
for n = 1:N
y(k) = y(k)+x(n).*exp((-1i*2*pi*(k-1)*(n-1))/N);
end
end
%code block to plot the input sequence
t = 0:N-1;
subplot(2,2,1);
stem(t,x);
ylabel('Amplitude ---->');
xlabel('n ---->');
title('Input Sequence');
grid on;
output:
Amplitude ---->
Amplitude ---->
3
2 5
0 0
0 1 2 3 0 1 2 3
n ----> K ---->
IFFT sequence
4
3
Amplitude ---->
0
0 0.5 1 1.5 2 2.5 3
n ---->
SOURCE CODE:(DITFFT)
clc;
clear all;
close all;
N=input('Enter the number of elements:');
for i=1:N
re(i)= input('Enter the real part of the element:');
im(i)= input('Enter the imaginary part of the element:');
end
%% Call Dit_fft function
[re1,im1]= ditfft(re,im,N);
disp(re1);
disp(im1);
figure(1);
subplot(2,2,1);
stem(re1);
xlabel('Time period');
ylabel('Amplitude');
[re1,im1]=ditifft(re,im,N);
for i=1:N
re1(i)=re1(i)/N;
im1(i)=-im1(i)/N;
end
disp(re1);
disp(im1);
%figure(2)
subplot(2,2,3);
stem(re1);
xlabel('Time period');
ylabel('Amplitude');
Function Table:(DITFFT)
for i=2:N-2
if i<j
tr=re(j);
ti=im(j);
re(j)=re(i);
im(j)=im(i);
re(i)=tr;
im(i)=ti;
end
k=N2;
while k<=j
j=j-k;
k=k/2;
end
j=j+k;
j=round(j);
end
for l=1:M
le=2.^l;
le2=le/2;
ur=1;
ui=0;
sr=cos(pi/le2);
si=sin(pi/le2);
for j=2:(le2+1)
jm=j-1;
for i=jm:le:N
ip=i+le2;
tr=re(ip)*ur-im(ip)*ui;
ti=re(ip)*ui-im(ip)*ur;
re(ip)=re(i)-tr;
im(ip)=im(i)-ti;
re(i)=re(i)+tr;
im(i)=im(i)+ti;
end
tr=ur;
ur=tr*sr-ui*si;
ui=tr*si+ui*sr;
end
end
Function Table:(DITIFFT)
function [ re,im] = ditifft(re,im,N)
%UNTITLED2 Summary of this function goes here
% Detailed explanation goes here
N1=N-1;
N2=N/2;
j=N2+1;
M=log2(N);
%Bit reversal sorting
for i=2:N-2
if i<j
tr=re(j);
ti=im(j);
re(j)=re(i);
im(j)=im(i);
re(i)=tr;
im(i)=ti;
end
k=N2;
while k<=j
j=j-k;
k=k/2;
end
j=j+k;
j=round(j);
end
for l=1:M
le=2.^l;
le2=le/2;
ur=1;
ui=0;
sr=cos(pi/le2);
si=-sin(pi/le2);
for j=2:(le2+1)
jm=j-1;
for i=jm:le:N
ip=i+le2;
tr=re(ip)*ur-im(ip)*ui;
ti=re(ip)*ui+im(ip)*ur;
re(ip)=re(i)-tr;
im(ip)=im(i)-ti;
re(i)=re(i)+tr;
im(i)=im(i)+ti;
end
tr=ur;
ur=tr*sr-ui*si;
ui=tr*si+ui*sr;
end
end
end
Command Window:
Result:
VIVA QUESTIONS:
1. FFT is in complex domain how to use it in real life signals optimally?
2. What is the difference between FFT and IFFT?
3. Explain using convolution the effects of taking an FFT of a sample with no windowing
4. What is the need of FFT ?
5. What’s the difference between FFT and DFT?
6. Why do we need Fourier transform in DSP?
7. Give any practical application of fft in daily life?
8. What is the importance of fft in OFDMA technology?
9. In STB DVB how many point fft is currently using?
10. Give FFT & IFFT formulae and calculate for any sequence?
11. What is "decimation-in-time" versus "decimation-in-frequency"?
12. What is "bit reversal"?
13. How does the FFT work?
Exp.No. 6
Exc.No.
FIR FILTER
Dt.
AIM:
To verify FIR filters.
EQUIPMENTS:
Operating System – Windows XP
Software - MATLAB 7.5
THEORY:
A Finite Impulse Response (FIR) filter is a discrete linear time-invariant system whose
output is based on the weighted summation of a finite number of past inputs. An FIR transversal
filter structure can be obtained directly from the equation for discrete-time convolution.
In this equation, x(k) and y(n) represent the input to and output from the filter at time n. h(n-
k) is the transversal filter coefficients at time n. These coefficients are generated by using FDS
(Filter Design Software or Digital filter design package). FIR – filter is a finite impulse response
filter. Order of the filter should be specified. Infinite response is truncated to get finite impulse
response. placing a window of finite length does this. Types of windows available are Rectangular,
Bartlett, Hamming, Hanning, Blackmann window etc. This FIR filter is an all zero filter.
% Algorithm for FIR filter%
Step 1: read the specifications of the filter
rp : pass band ripple
rs: stop band ripple
fp : pass band frequency
fs : stop band frequency
step2: wp = 2 fp / f, ws = 2 x fs / f
Num=20log10sqrt (rp*rs)-13
Den=14.6*fs-fp/f
Step 3: n=num/den
up truncate n and find its absolute value
n1=n+1;
if n/2 ~=0;
n1=n;
n=n-1;
Step 4: select the window type (i.e. rectangular, triangular, Kaiser) and find the filter
response using the function y=rectwin(n1) where n1 is the n1-point rectangular window
Step 5: for LPF
X1=fir1 (n,wp,y)
Step 6: plot magnitude and phase response of FIR filters
PROGRAM:
%fir filt design window techniques
clc;
clear all;
close all;
rp=input('enter passband ripple');
rs=input('enter the stopband ripple');
fp=input('enter passband freq');
fs=input('enter stopband freq');
f=input('enter sampling freq ');
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
c=input('enter your choice of window function 1. rectangular 2. triangular 3.kaiser: \n ');
if(c==1)
y=rectwin(n1);
disp('Rectangular window filter response');
end
if (c==2)
y=triang(n1);
disp('Triangular window filter response');
end
if(c==3)
y=kaiser(n1);
disp('kaiser window filter response');
end
%LPF
b=fir1(n,wp,y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,1);plot(o/pi,m);
title('LPF');
ylabel('Gain in dB-->');
xlabel('(a) Normalized frequency-->');
%HPF
b=fir1(n,wp,'high',y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,2);plot(o/pi,m);
title('HPF');
ylabel('Gain in dB-->');
xlabel('(b) Normalized frequency-->');
%BPF
wn=[wp ws];
b=fir1(n,wn,y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,3);plot(o/pi,m);
title('BPF');
ylabel('Gain in dB-->');
xlabel('(c) Normalized frequency-->');
%BSF
b=fir1(n,wn,'stop',y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,4);plot(o/pi,m);
title('BSF');
ylabel('Gain in dB-->');
xlabel('(d) Normalized frequency-->');
OUTPUT:
LPF HPF
0 50
Gain in dB-->
0
-40
-50
-60
-80 -100
0 0.5 1 0 0.5 1
(a) Normalized frequency--> (b) Normalized frequency-->
BPF BSF
20 0
0
Gain in dB-->
Gain in dB-->
-10
-20
-20
-40
-60 -30
0 0.5 1 0 0.5 1
(c) Normalized frequency--> (d) Normalized frequency-->
RESULT:
VIVA QUESTIONS
1. What are the advantages of FIR as compared to IIR?
2. How many types of FIR design methods are used in real time?.
3. What is meant by Gibbs Phenomenon? Where we find such type of effect in FIR filters?
4. What are the advantages& disadvantages of Rectangular window FIR filter as compared to
remaining window techniques?
5. Which window technique having less peak amplitude of side lobe as compared to all?
6. What do you understand by linear phase responce?
7. To design all types of filters what would be the expected impulse response?
8. What are the properties of FIR filter?.
9. How the zeros in FIR filter is located?
10. What are the desirable characteristics
Exp.No. 7 A
Exc.No.
DESIGN OF BUTTERWORTH FILTERS
Dt.
AIM:
Write a MATLAB Script to design Analog Butterworth filters for the given specifications.
APPARATUS REQUIRED:
THEORY:
BUTTERWORTH FILTER:
Low pass Analog Butterworth filters are all pole filters characterised by magnitude
frequency response by
2
=
As N , the low pass filter is said to be normalized. All types of filters namely-Low pass,
High pass, Band pass and Band elimination filters can be derived from the Normalized Low pass
filter.
LIBRARY FUNCTIONS:
Lowpass: Wp = .1, Ws = .2
Highpass: Wp = .2, Ws = .1
buttord: also returns Wn, the Butterworth natural frequency (or) the "3 dB frequency" to
be used with BUTTER to achieve the specifications.
[N, Wn] = buttord (Wp, Ws, Rp, Rs, 's') does the computation for an analog filter, in
which case Wp and Ws are in radians/second. When Rp is chosen as 3 dB, the Wn in
BUTTER is equal to Wp in BUTTORD.
given the numerator and denominator coefficients in vectors B and A. The frequency
response is evaluated at the points specified in vector W (in rad/s). The magnitude and
phase can be graphed by calling freqs(B,A,W) with no output arguments.
ALGORITHM/PROCEDURE:
1. Click on the MATLAB icon on the desktop (or go to Start – All programs and click on
MATLAB) to get into the Command Window.
2. Type ‘edit’ in the MATLAB prompt ‘>>’ that appears in the Command window.
3. Write the program in the ‘Edit’ window and save it in ‘M-file’.
4. Run the program.
5. Enter the input in the command window.
6. The result is displayed in the Command window and the graphical output is displayed in the
Figure Window.
Butterworth Filters
SOURCE CODE:1
clc;
clear all;
close all;
%% Butterworth low pass Filter
% Filter Specifications
%Find the order and Cutofrf frequency using the given specification of
%filter
[n,Wc]=buttord(w1,w2,k1,k2,'s');
disp('The order is:');
disp(n);
disp('The cutoff frequency is:');
disp(Wc);
f=linspace(1,512,1000);
h=freqs(b,a,f);
m=20*log(abs(h));
subplot(2,1,1);
semilogx(f,m);
xlabel('Frequency');
ylabel('Magnitude');
title('Magnitude response of Butterworth LPF');
% Phase response
p=angle(h);
subplot(2,1,2);
semilogx(f,p);
xlabel('Frequency');
ylabel('Phase');
title('Phase response of Butterworth LPF');
SOURCE CODE:2
clc;
clear all;
close all;
%% Butterworth high pass Filter
% Filter Specifications
%Find the order and Cutofrf frequency using the given specification of
%filter
[n,Wc]=buttord(w1,w2,k1,k2,'s');
disp('The order is:');
disp(n);
disp('The cutoff frequency is:');
disp(Wc);
f=linspace(1,512,1000);
h=freqs(b,a,f);
m=20*log(abs(h));
subplot(2,1,1);
semilogx(f,m);
xlabel('Frequency');
ylabel('Magnitude');
title('Magnitude response of Butterworth HPF');
% Phase response
p=angle(h);
subplot(2,1,2);
semilogx(f,p);
xlabel('Frequency');
ylabel('Phase');
title('Phase response of Butterworth HPF');
SOURCE CODE:3
clc;
clear all;
close all;
%% Bandpass Filter Specifications
Wp=input('Enter the pass band edge frequency : ');
SOURCE CODE:4
clc;
clear all;
close all;
%% Bandstop Filter Specifications
Wp=input('Enter the pass band edge frequency : ');
Ws=input('Enter the stop band edge frequency : ');
Rp=input('Enter the Pass band ripple: ');
Rs=input('Enter the stop band gain: ');
Command Windows :
OUTPUTS:
RESULT:
Exp.No. 7 B
Exc.No. DESIGN OF CHEBYSHEV FILTERS
Dt.
AIM:
Write a MATLAB Script to design Analog Chebyshev filter for the given specifications.
APPARATUS REQUIRED:
THEORY:
Chebyshev Filters :
Type I are all-pole filters that exhibit equi-ripple behaviour in pass band and monotonic
characteristics in stop band.
Type II are having both poles and zeros and exhibit monotonic behavior in pass band and equi-
ripple behavior in stop band. The zero lies on the imaginary axis.
CN(x) =
LIBRARY FUNCTIONS:
[N, Wn] = cheb1ord (Wp, Ws, Rp, Rs) returns the order N of the lowest order digital
Chebyshev Type I filter that loses no more than Rp dB in the pass band and has at least Rs
dB of attenuation in the stop band. Wp and Ws are the pass band and stop band edge
frequencies, normalized from 0 to 1 (where 1 corresponds to pi radians/sample). For
example,
Lowpass: Wp = .1, Ws = .2
Highpass: Wp = .2, Ws = .1
cheb1ord also returns Wn, the Chebyshev natural frequency to use with cheby1 to achieve
the specifications.
[N, Wn] = cheb1ord (Wp, Ws, Rp, Rs, 's') does the computation for an analog filter, in
which case Wp and Ws are in radians/second.
ALGORITHM/PROCEDURE:
1. Click on the MATLAB icon on the desktop (or go to Start – All programs and click on
MATLAB) to get into the Command Window.
2. Type ‘edit’ in the MATLAB prompt ‘>>’ that appears in the Command window.
3. Write the program in the ‘Edit’ window and save it in ‘M-file’.
4. Run the program.
5. Enter the input in the command window.
6. The result is displayed in the Command window and the graphical output is displayed in the
Figure Window.
CHEBYSHEV FILTERS :
Source code:1
clc;
clear all;
close all;
%% Chebyshev low pass Filter
% Filter Specifications
k1=input('Enter the passband ripple in db:');
k2=input('Enter the stopband attenuation in db:');
w1=input('Enter the passband edge frequency in rad/Sec:');
w2=input('Enter the stopband edge frequency in rad/Sec:');
%Find the order and Cutofrf frequency using the given specification of
%filter
[n,Wc]=cheb1ord(w1,w2,k1,k2,'s');
disp('The order is:');
disp(n);
disp('The cutoff frequency is:');
disp(Wc);
Source code:2
clc;
clear all;
close all;
%% Chebyshev High pass Filter
% Filter Specifications
k1=input('Enter the passband ripple in db:');
k2=input('Enter the stopband attenuation in db:');
w1=input('Enter the passband edge frequency in rad/Sec:');
w2=input('Enter the stopband edge frequency in rad/Sec:');
%Find the order and Cutofrf frequency using the given specification of
%filter
[n,Wc]=cheb1ord(w1,w2,k1,k2,'s');
disp('The order is:');
disp(n);
disp('The cutoff frequency is:');
disp(Wc);
Source code: 3
clc;
clear all;
close all;
Source code: 4
clc;
clear all;
close all;
%% Bandstop Filter Specifications
Wp=input('Enter the pass band edge frequency : ');
Ws=input('Enter the stop band edge frequency : ');
Rp=input('Enter the Pass band ripple: ');
Rs=input('Enter the stop band gain: ');
%Bandstop Filtering
[b,a]=cheby1(N,Rp,Wc,'stop','s');
Output:
Output:
Output:
Output:
RESULT:
Exp.No. 8
Exc.No.
DESIGN OF IIR FILTERS
Dt.
AIM:
Write a MATLAB Script to design Butterworth and Chebyshev low pass filters using
Bilinear Transformation
Impulse Invariant Transformation
.
APPARATUS REQUIRED:
PC, MATLAB software
THEORY:
A digital filter is a linear time invariant discrete time system. The digital filters are
classified into two, based on their lengths of impulse response
1. Finite Impulse response (FIR)
They are of non-recursive type and h [n] has finite number of samples
2. Infinite Impulse response (IIR)
h[n] has finite number of samples. They are of recursive type. Hence, their transfer
function is of the form
H ( z ) h( n) z n
n 0
The digital filters are designed from analog filters. The two widely used methods for
digitizing the analog filters include
1. Bilinear transformation
2. Impulse Invariant transformation
H(Z) =
This transformation maps the jΩ axis (from Ω = -∞ to +∞) repeatedly around the unit circle (exp
( jw), from w=-π to π ) by
2
tan
T 2
BILINEAR TRANSFORMATION:
DESIGN STEPS:
LIBRARY FUNCTIONS:
Impinvar: Impulse Invariant method for analog-to-digital filter conversion [bz,az] =
impinvar(b,a,fs) creates a digital filter with numerator and denominator coefficients bz and
az, respectively, whose impulse response is equal to the impulse response of the analog
filter with coefficients b and a, scaled by 1/fs. If you leave out the argument fs (or) specify
fs as an empty vector [ ], it takes the default value of 1 Hz.
Bilinear: Bilinear transformation method for analog-to-digital filter conversion. The bilinear
transformation is a mathematical mapping of variables. In digital filtering, it is a standard
method of mapping the s or analog plane into the z or digital plane. It transforms analog
filters, designed using classical filter design
ALGORITHM/PROCEDURE:
SOURCE CODE:
/ Butterworth Lowpass Impulse invariant method
clc;
clear all;
close all;
warning off;
% Design of IIR Filters
%% Filter Specifications
% Input Wp,Ws,Sp,Ss,T
% T=1,bothe ripple gains should be b/w .1 to .3
disp(' Butterworth Lowpass filter using Impulse invariant method ');
% Calculation of ohmp,ohms,Ap,As
Ap=abs(20*log10(1-Sp));
As=abs(20*log10(Ss));
ohmp=Wp/T;
ohms=Ws/T;
% Butterworth Filter
% Calculation of order and cutoff freq. for the above filter specs.
[n,Wc]=buttord(ohmp,ohms,Ap,As,'s');
% Magnitude Response
Hm=20*log10(abs(H));
subplot(2,1,1);
semilogx(O,Hm);
xlabel('Frequency');
ylabel('Magnitude');
title('Magnitude Response of IIR Filter using Impulse Invariant Method');
% Phase Response
Ha=angle(H);
subplot(2,1,2);
semilogx(O,Ha);
xlabel('Frequency');
ylabel('Phase');
title('Phase Response of IIR Filter using Impulse Invariant Method');
close all;
warning off;
% Design of IIR Filters
%% Filter Specifications
% Input Wp,Ws,Sp,Ss,T
% T=1,both the ripple gains should have band width( .1 to .3)
disp(' Butterworth Lowpass filter using Bilnear transformation method ');
% Calculation of ohmp,ohms,Ap,As
Ap=abs(20*log10(1-Sp));
As=abs(20*log10(Ss));
ohmp=Wp/T;
ohms=Ws/T;
% Butterworth Filter
% Calculation of order and cutoff freq. for the above filter specs.
[n,Wc]=buttord(ohmp,ohms,Ap,As,'s');
% Magnitude Response
Hm=20*log10(abs(H));
subplot(2,1,1);
semilogx(O,Hm);
xlabel('Frequency');
ylabel('Magnitude');
title('Magnitude Response of IIR Filter using Bilinear Transformation Method');
% Phase Response
Ha=angle(H);
subplot(2,1,2);
semilogx(O,Ha);
xlabel('Frequency');
ylabel('Phase');
title('Phase Response of IIR Filter using Bilinear Transformation Method');
% Calculation of ohmp,ohms,Ap,As
Ap=abs(20*log10(1-Sp));
As=abs(20*log10(Ss));
ohmp=Wp/T;
ohms=Ws/T;
% Chebyshev Filter
% Calculation of order and cutoff freq. for the above filter specs.
[n,Wc2]=cheb1ord(ohmp,ohms,Ap,As,'s')
% Magnitude Response
Hm=20*log10(abs(H));
subplot(2,1,1);
semilogx(O,Hm);
xlabel('Frequency');
ylabel('Magnitude');
title('Magnitude Response of IIR Filter using Impulse Invariant Method');
% Phase Response
Ha=angle(H);
subplot(2,1,2);
semilogx(O,Ha);
xlabel('Frequency');
ylabel('Phase');
title('Phase Response of IIR Filter using Impulse Invariant Method');
clc;
clear all;
close all;
warning off;
% Design of IIR Filters
%% Filter Specifications
% Input Wp,Ws,Sp,Ss,T
% T=1,bothe ripple gains should be b/w .1 to .3
disp(' Chebyshev Lowpass filter using Bilnear transformation method ');
% Calculation of ohmp,ohms,Ap,As
Ap=abs(20*log10(1-Sp));
As=abs(20*log10(Ss));
ohmp=Wp/T;
ohms=Ws/T;
% Chebyshev Filter
% Calculation of order and cutoff freq. for the above filter specs.
[n,Wc2]=cheb1ord(ohmp,ohms,Ap,As,'s')
% Magnitude Response
Hm=20*log10(abs(H));
subplot(2,1,1);
semilogx(O,Hm);
xlabel('Frequency');
ylabel('Magnitude');
title('Magnitude Response of IIR Filter using Bilinear Transformation Method');
% Phase Response
Ha=angle(H);
subplot(2,1,2);
semilogx(O,Ha);
xlabel('Frequency');
ylabel('Phase');
title('Phase Response of IIR Filter using Bilinear Transformation Method');
Output:
Command Window :
Output:
Command Window:
Output:
Command Window:
Output:
RESULT:
Exp.No. 1
Exc.No.
GENERATION OF RANDOM SIGNALS
Dt.
AIM:- To generate a sine wave and square wave using C6713 simulator
EQUIPMENT:-
1. Operating System - Windows XP
2. Software - CC STUDIO 3
3. DSK 6713 DSP Trainer kit.
4. USB Cable
5. Power supply
PROCEDURE:
1. Open Code Composer Studio, make sure the DSP kit is turned on.
2. To open project:
Project open rollnumber.pjt
3. To create a source file:
File new type the code ( save and give File name/ Eg: lineconv.c)
4. To add source files to project:
Project add files to project lineconv.c
5. To add rts6700.lib (Library file):
Project add files to project rts6700.lib
Library files: rts6700.lib(path: c:\cc studio\c6000\cgtools\lib\rts6700)
Note: select object & library in type of files
6. To add hello.cmd file (Linker command file):
Project add files to project hello.cmd
Linker command file:rts6700.lib(path:c:\cc studio\tutorial\dsk6713\hello1\hello)
Note: select Linker command in type of files
7. To compile source file: project compile
8. To rebuild all: project rebuild all
Which will create the final.out executable file (Eg: rollnumber.out)
9. To load the program in DSP chip:
File load program rollnumber.out
10. To run the program:
Debug Run
11. To view output graphically:
Select view graph time/frequency
PROGRAM: (a)
#include <stdio.h>
#include <math.h>
float a[500];
void main()
{
int i=0;
for(i=0;i<500;i++)
{
a[i]=sin(2*3.14*10000*i);
}
}
PROGRAM: (b)
#include <stdio.h>
#include <math.h>
int a[1000];
void main()
{
int i,j=0;
int b=5;
for(i=0;i<10;i++)
{
for (j=0;j<=50;j++)
{
a[(50*i)+j]=b;
}
b=b*(-1) ;
}
}
Square wave:-
Result:-.
Exp.No. 2
Exc.No. LINEAR CONVOLUTION
Dt.
EQUIPMENTS:-
PROCEDURE:
1. Open Code Composer Studio, make sure the DSP kit is turned on.
2. To open project:
Project open rollnumber.pjt
3. To create a source file:
File new type the code ( save and give File name/ Eg: lineconv.c)
4. To add source files to project:
Project add files to project lineconv.c
5. To add rts6700.lib (Library file):
Project add files to project rts6700.lib
Library files: rts6700.lib(path: c:\cc studio\c6000\cgtools\lib\rts6700)
Note: select object & library in type of files
6. To add hello.cmd file (Linker command file):
Project add files to project hello.cmd
Linker command file:rts6700.lib(path:c:\cc studio\tutorial\dsk6713\hello1\hello)
Note: select Linker command in type of files
7. To compile source file: project compile
8. To rebuild all: project rebuild all
Which will create the final.out executable file (Eg: rollnumber.out)
9. To load the program in DSP chip:
File load program rollnumber.out
10. To run the program:
Debug Run
11. To view output graphically:
Select view graph time/frequency
PROGRAM:
main()
{
int i,j,m,n;
printf("\n enter value for m");
scanf("%d",&m);
printf("\n enter value for n");
scanf("%d",&n);
printf("Enter values for i/p x(n):\n");
for(i=0;i<m;i++)
scanf("%d",&x[i]);
printf("Enter Values for i/p h(n) \n");
for(i=0;i<n; i++)
scanf("%d",&h[i]);
// padding of zeros
for(i=m;i<=m+n-1;i++)
x[i]=0;
for(i=n;i<=m+n-1;i++)
h[i]=0;
/* convolution operation */
for(i=0;i<m+n-1;i++)
{
y[i]=0;
for(j=0;j<=i;j++)
{
y[i]=y[i]+(x[j]*h[i-j]);
}
}
//displaying the o/p
for(i=0;i<m+n-1;i++)
printf("\n The Value of output y[%d]=%d",i,y[i]);
}
Output:-
enter value for m 4
enter value for n 4
Enter values for i/p 1234
Enter Values for n 1234
The Value of output y[0]=1
The Value of output y[1]=4
The Value of output y[2]=10
The Value of output y[3]=20
The Value of output y[4]=25
The Value of output y[5]=24
The Value of output y[6]=16
RESULT:
Exp.No. 3
Exc.No. FIR FILTER DESIGN
Dt.
EQUIPMENTS:-
PROGRAM:
#include<stdio.h>
#include<math.h>
#define pi 3.1415
int n,N,c;
float wr[64],wt[64];
void main()
scanf("%d",&N);
scanf("%d",&c);
switch(c)
case 1:
for(n=0;n<=N-1;n++)
wr[n]=1;
printf(" \n wr[%d]=%f",n,wr[n]);
break;
case 2:
for(n=0;n<=N-1;n++)
wt[n]=1-(2*(float)n/(N-1));
printf("\n wt[%d]=%f",n,wt[n]);
break;
PROCEDURE:
1. Open Code Composer Studio, make sure the DSP kit is turned on.
2. To open project:
Project open rollnumber.pjt
3. To create a source file:
File new type the code ( save and give File name/ Eg: lineconv.c)
4. To add source files to project:
Project add files to project lineconv.c
5. To add rts6700.lib (Library file):
Project add files to project rts6700.lib
Library files: rts6700.lib(path: c:\cc studio\c6000\cgtools\lib\rts6700)
Note: select object & library in type of files
6. To add hello.cmd file (Linker command file):
Project add files to project hello.cmd
Linker command file:rts6700.lib(path:c:\cc studio\tutorial\dsk6713\hello1\hello)
Note: select Linker command in type of files
7. To compile source file: project compile
8. To rebuild all: project rebuild all
Which will create the final.out executable file (Eg: rollnumber.out)
9. To load the program in DSP chip:
File load program rollnumber.out
10. To run the program:
Debug Run
11. To view output graphically:
Select view graph time/frequency
OUTPUT:
RESULT:
Dt.
EQUIPMENTS:-
PROGRAM:
//iirfilters
#include<stdio.h>
#include<math.h>
int i,w,wc,c,N;
float H[100];
void main()
scanf("%d",&N);
scanf("%d",&wc);
printf("\n enter the choice for IIR filter 1. LPF 2.HPF ");
scanf("%d",&c);
switch(c)
case 1:
for(w=0;w<100;w++)
H[w]=1/sqrt(1+mul((w/(float)wc),2*N));
printf("H[%d]=%f\n",w,H[w]);
break;
case 2:
for(w=0;w<=100;w++)
H[w]=1/sqrt(1+mul((float)wc/w,2*N));
printf("H[%d]=%f\n",w,H[w]);
break;
for(i=0;i<x-1;i++)
a*=a;
return(a);
PROCEDURE:
1. Open Code Composer Studio, make sure the DSP kit is turned on.
2. To open project:
Project open rollnumber.pjt
3. To create a source file:
File new type the code ( save and give File name/ Eg: lineconv.c)
4. To add source files to project:
Project add files to project lineconv.c
5. To add rts6700.lib (Library file):
Project add files to project rts6700.lib
Library files: rts6700.lib(path: c:\cc studio\c6000\cgtools\lib\rts6700)
Note: select object & library in type of files
6. To add hello.cmd file (Linker command file):
Project add files to project hello.cmd
Linker command file:rts6700.lib(path:c:\cc studio\tutorial\dsk6713\hello1\hello)
Note: select Linker command in type of files
OUTPUT:
RESULT:
APPENDIX A
MATLAB
A.1 Introduction
MATLAB is a high-performance language for technical computing. It integrates
computation, visualization, and programming in an easy-to-use environment where problems and
solutions are expressed in familiar mathematical notation. MATLAB stands for matrix laboratory,
and was written originally to provide easy access to matrix software developed by LINPACK
(linear system package) and EISPACK (Eigen system package) projects. MATLAB is therefore
built on a foundation of sophisticated matrix software in which the basic element is array that does
not require pre dimensioning which to solve many technical computing problems, especially those
with matrix and vector formulations, in a fraction of time.
Typical uses of MATLAB include: Math and computation, Algorithm development, Data
acquisition, Modeling, simulation, prototyping, Data analysis, exploration, visualization, Scientific
and engineering graphics, Application development, including graphical user interface building.
A.2 Basic Building Blocks of MATLAB
The basic building block of MATLAB is MATRIX. The fundamental data type is the array.
Vectors, scalars, real matrices and complex matrix are handled as specific class of this basic data
type. The built in functions are optimized for vector operations. No dimension statements are
required for vectors or arrays.
clicking on a variable in the workspace browser launches the Array Editor, which can be used to
obtain information.
window shows a list of recently used paths. MATLAB uses a search path to find M-files
and other MATLAB related files. Any file run in MATLAB must reside in the current directory or
in a directory that is on search path.
MATLAB editor window has numerous pull-down menus for tasks such as saving, viewing,
and debugging files. Because it performs some simple checks and also uses color to differentiate
between various elements of code, this text editor is recommended as the tool of choice for writing
and editing M-functions.
MATLAB has three types of files for storing information. They are: M-files and MAT-files.
A.3.1 M-Files
These are standard ASCII text file with ‘m’ extension to the file name and creating own
matrices using M-files, which are text files containing MATLAB code. MATLAB editor or another
text editor is used to create a file containing the same statements which are typed at the MATLAB
command line and save the file under a name that ends in .m. There are two types of M-files:
1. Script Files
It is an M-file with a set of MATLAB commands in it and is executed by typing name of
file on the command line. These files work on global variables currently present in that
environment.
2. Function Files
A function file is also an M-file except that the variables in a function file are all local. This
type of files begins with a function definition line.
A.3.2 MAT-Files
These are binary data files with .mat extension to the file that are created by MATLAB
when the data is saved. The data written in a special format that only MATLAB can read. These are
located into MATLAB with ‘load’ command.
A.4.4 Graphics:
MATLAB has extensive facilities for displaying vectors and matrices as graphs, as well as
annotating and printing these graphs. It includes high-level functions for two-dimensional and
three-dimensional data visualization, image processing, animation, and presentation graphics. It
also includes low-level functions that allow you to fully customize the appearance of graphics as
well as to build complete graphical user interfaces on your MATLAB applications.
This is a library that allows you to write C and FORTRAN programs that interact with
MATLAB. It includes facilities for calling routines from MATLAB (dynamic linking), calling
MATLAB as a computational engine, and for reading and writing MAT-files.
APPENDIX-B
MATLAB COMMANDS
clc:
GUI Alternatives
As an alternative to the clc function, select Edit > Clear Command Window in the
MATLAB desktop.
Syntax
clc
Description
clc clears all input and output from the Command Window display, giving you a
"clean screen."
clear:
Graphical Interface
As an alternative to the clear function, use Edit > Clear Workspace in the MATLAB®
desktop.
Syntax
clear
clear name
Description
clear removes all variables from the workspace. This frees up system memory.
clear name removes just the M-file or MEX-file function or variable name from the
workspace. You can use wildcards (*) to remove items selectively. For example, clear my*
removes any variables whose names begin with the string my. It removes debugging
breakpoints in M-files and reinitializes persistent variables, since the breakpoints for a
function and persistent variables are cleared whenever the M-file is changed or cleared. If
name is global, it is removed from the current workspace, but left accessible to any
functions declaring it global. If name has been locked by mlock, it remains in memory.
close:
Syntax
close
close(h)
close name
close all
Description
close deletes the current figure or the specified figure(s). It optionally returns the
status of the close operation.
close(h) deletes the figure identified by h. If h is a vector or matrix, clse deletes all
figures identified by h.
sin:
Syntax
Y = sin(X)
Description
The sin function operates element-wise on arrays. The function's domains and
ranges include complex values. All angles are in radians.
pi :
Syntax
pi
Description
sin(pi)
ans = 1.2246e-16
GUI Alternative
To control the presence and appearance of axis labels on a graph, use the Property
Editor, one of the plotting tools . For details, see The Property Editor in the MATLAB®
Graphics documentation.
Syntax
xlabel('string')
xlabel(fname)
xlabel(...,'PropertyName',PropertyValue,...)
xlabel(axes_handle,...)
Description
Each axes graphics object can have one label for the x-, y-, and z-axis. The label
appears beneath its respective axis in a two-dimensional plot and to the side or beneath the
axis in a three-dimensional plot.
grid:
GUI Alternative
To control the presence and appearance of grid lines on a graph, use the Property
Editor, one of the plotting tools . For details, see The Property Editor in the MATLAB®
Graphics documentation.
Syntax
grid on
grid off
grid
Description
The grid function turns the current axes' grid lines on and off.
grid off removes major and minor grid lines from the current axes.
grid(axes handle,...) uses the axes specified by axes handle instead of the current
axes.
tic, toc :
Synopsis
t = toc
Description
Remarks
The tic and toc functions work together to measure elapsed time. tic saves the
current time that toc uses later to measure the elapsed time. The sequence of commands
Tic
operations
toc
measures the amount of time the MATLAB® software takes to complete one or more
operations, and displays the time in seconds.
title:
GUI Alternative
To create or modify a plot's title from a GUI, use Insert Title from the figure menu.
Use the Property Editor, one of the plotting tools , to modify the position, font, and other
properties of a legend. For details, see The Property Editor in the MATLAB® Graphics
documentation.
Syntax
title('string')
title(fname)
title(...,'PropertyName',PropertyValue,...)
Description
Each axes graphics object can have one title. The title is located at the top and in the
center of the axes.
title('string') outputs the string at the top and in the center of the current axes.
title(fname) evaluates the function that returns a string and displays the string at the top and
in the center of the current axes.
Input :
Syntax
user_entry = input('prompt')
Description
The response to the input prompt can be any MATLAB expression, which is
evaluated using the variables in the current workspace.
user_entry = input('prompt') displays prompt as a prompt on the screen, waits for input from
the keyboard, and returns the value entered in user_entry.
user_entry = input('prompt', 's') returns the entered string as a text variable rather than as a
variable name or numerical value.
Remarks
If you press the Return key without entering anything, input returns an empty
matrix.
The text string for the prompt can contain one or more '\n' characters. The '\n' means to skip
to the next line. This allows the prompt string to span several lines. To display just a
backslash, use '\\'.
If you enter an invalid expression at the prompt, MATLAB displays the relevant error
message and then prompts you again to enter input.
legend :
GUI Alternatives
Add a legend to a selected axes on a graph with the Insert Legend tool on the figure
toolbar, or use Insert —> Legend from the figure menu. Use the Property Editor to modify
the position, font, and other properties of a legend. For details, see Using Plot Edit Mode in
the MATLAB® Graphics documentation.
Syntax
legend('string1','string2',...)
legend(h,'string1','string2',...)
legend(M)
legend(h,M)
legend(M,'parameter_name','parameter_value',...)
legend(h,M,'parameter_name','parameter_value',...)
legend(axes_handle,...)
legend('off'), legend(axes_handle,'off')
legend('toggle'), legend(axes_handle,'toggle')
Description
legend places a legend on various types of graphs (line plots, bar graphs, pie charts,
etc.). For each line plotted, the legend shows a sample of the line type, marker symbol, and
color beside the text label you specify. When plotting filled areas (patch or surface objects),
the legend contains a sample of the face color next to the text label.
The font size and font name for the legend strings match the axes FontSize and FontName
properties.
plot :
GUI Alternatives
Use the Plot Selector to graph selected variables in the Workspace Browser and the
Plot Catalog, accessed from the Figure Palette. Directly manipulate graphs in plot edit
mode, and modify them using the Property Editor. For details, see Using Plot Edit Mode,
and The Figure Palette in the MATLAB® Graphics documentation, and also Creating
Graphics from the Workspace Browser in the MATLAB Desktop documentation.
Syntax
plot(Y)
plot(X1,Y1,...)
plot(X1,Y1,LineSpec,...)
plot(...,'PropertyName',PropertyValue,...)
Description
subplot :
GUI Alternatives
To add subplots to a figure, click one of the New Subplot icons in the Figure Palette,
and slide right to select an arrangement of subplots. For details, see Plotting Tools —
Interactive Plotting in the MATLAB® Graphics documentation.
Syntax
h = subplot(m,n,p) or subplot(mnp)
subplot(m,n,p,'replace')
subplot(m,n,P)
subplot(h)
Description
subplot divides the current figure into rectangular panes that are numbered rowwise.
Each pane contains an axes object. Subsequent plots are output to the current pane.
stem :
GUI Alternatives
To graph selected variables, use the Plot Selector in the Workspace Browser, or use
the Figure Palette Plot Catalog. Manipulate graphs in plot edit mode with the Property
Editor. For details, see Plotting Tools — Interactive Plotting in the MATLAB® Graphics
documentation and Creating Graphics from the Workspace Browser in the MATLAB
Desktop Tools documentation.
Syntax
stem(Y)
stem(X,Y)
stem(...,'fill')
Description
A two-dimensional stem plot displays data as lines extending from a baseline along
the x-axis. A circle (the default) or other marker whose y-position represents the data value
terminates each stem.
stem(Y) plots the data sequence Y as stems that extend from equally spaced and
automatically generated values along the x-axis. When Y is a matrix, stem plots all elements
in a row against the same x value.
stem(...,'fill') specifies whether to color the circle at the end of the stem.
disp :
Syntax
disp(X)
Description
disp(X) displays an array, without printing the array name. If X contains a text
string, the string is displayed.
Another way to display an array on the screen is to type its name, but this prints a leading
"X=," which is not always desirable.
fir1 :
Syntax
b = fir1(n,Wn)
b = fir1(n,Wn,'ftype')
b = fir1(n,Wn,window)
b = fir1(n,Wn,'ftype',window)
b = fir1(...,'normalization')
Description
fir1 implements the classical method of windowed linear-phase FIR digital filter
design [1]. It designs filters in standard lowpass, highpass, bandpass, and bandstop
configurations. By default the filter is normalized so that the magnitude response of the
filter at the center frequency of the passband is 0 dB.
If Wn is a two-element vector, Wn = [w1 w2], fir1 returns a bandpass filter with passband
w1 < ?< w2.
fopen :
Syntax
fid = fopen(filename)
Description
fid = fopen(filename) opens the file filename for read access. (On Windows®
systems, fopen opens files for binary read access.) The filename argument is a string
enclosed in single quotes. It can be a MATLABPATH relative partial pathname if the file is
opened for reading only.
A relative path is always searched for first with respect to the current directory. If it
is not found, and reading only is specified or implied, then fopen does an additional search
of the MATLABPATH.
fid is a scalar MATLAB® integer, called a file identifier. You use the fid as the first
argument to other file input/output routines. If fopen cannot open the file, it returns -1. Two
file identifiers are automatically available and need not be opened. They are fid=1 (standard
output) and fid=2 (standard error).
fid = fopen(filename, permission) opens the file filename in the specified permission.
winopen :
Syntax
winopen(filename)
Description
fprintf (serial):
Syntax
fprintf(obj,'cmd')
fprintf(obj,'format','cmd')
fprintf(obj,'cmd','mode')
fprintf(obj,'format','cmd','mode')
Arguments
obj
'cmd'
'format'
'mode'
Description
fprintf(obj,'cmd') writes the string cmd to the device connected to obj. The default
format is %s\n. The write operation is synchronous and blocks the command line until
execution is complete.
fseek :
Syntax
Description
status = fseek(fid, offset, origin) repositions the file position indicator in the file with
the given fid to the byte with the specified offset relative to origin.
For a file having n bytes, the bytes are numbered from 0 to n-1. The position immediately
following the last byte is the end-of-file, or eof, position. You would seek to the eof position
if you wanted to add data to the end of a file.
This figure represents a file having 12 bytes, numbered 0 through 11. The first command
shown seeks to the ninth byte of data in the file. The second command seeks just past the
end of the file data, to the eof position.
fseek does not seek beyond the end of file eof position. If you attempt to seek beyond eof,
the MATLAB® software returns an error status.
Arguments
offset > 0 Move position indicator offset bytes toward the end of
the file.
boxcar :
bartlett :
Bartlett window
Syntax
w = bartlett(L)
Description
w = bartlett(L) returns an L-point Bartlett window in the column vector w, where L must be
a positive integer. The coefficients of a Bartlett window are computed as follows:
The Bartlett window is very similar to a triangular window as returned by the triang
function. The Bartlett window always ends with zeros at samples 1 and n, however, while
the triangular window is nonzero at those points. For L odd, the center L-2 points of
bartlett(L) are equivalent to triang(L-2).
kaiser :
Kaiser window
Syntax
w = kaiser(L,beta)
Description
To obtain a Kaiser window that designs an FIR filter with sidelobe attenuation of a dB, use
the following ß.
Increasing beta widens the main lobe and decreases the amplitude of the sidelobes (i.e.,
increases the attenuation).
freqs :
Syntax
h = freqs(b,a,w)
[h,w] = freqs(b,a,n)
freqs
Description
freqs returns the complex frequency response H(j?) (Laplace transform) of an analog
filter
Syntax
[h,w] = freqz(ha)
[h,w] = freqz(ha,n)
freqz(ha)
[h,w] = freqz(hd)
[h,w] = freqz(hd,n)
freqz(hd)
Description
The next sections describe common freqz operation with adaptive, discrete-time, and
multirate filters. For more input options, refer to freqz in Signal Processing Toolbox
documentation.
Adaptive Filters
For adaptive filters, freqz returns the instantaneous frequency response based on the
current filter coefficients.
[h,w] = freqz(ha) returns the frequency response vector h and the corresponding
frequency vector w for the adaptive filter ha. When ha is a vector of adaptive filters, freqz
returns the matrix h. Each column of h corresponds to one filter in the vector ha.
[h,w] = freqz(ha,n) returns the frequency response vector h and the corresponding frequency
vector w for the adaptive filter ha. freqz uses the transfer function associated with the
adaptive filter to calculate the frequency response of the filter with the current coefficient
values. The vectors h and w are both of length n. The frequency vector w has values ranging
from 0 to p radians per sample. If you do not specify the integer n, or you specify it as the
empty vector [], the frequency response is calculated using the default value of 8192
samples for the FFT.
Discrete-Time Filters
[h,w] = freqz(hd) returns the frequency response vector h and the corresponding
frequency vector w for the discrete-time filter hd. When hd is a vector of discrete-time
filters, freqz returns the matrix h. Each column of h corresponds to one filter in the vector
hd.
fft :
Syntax
Y = fft(X)
Y = fft(X,n)
Y = fft(X,[],dim)
Y = fft(X,n,dim)
Definition
The functions X = fft(x) and x = ifft(X) implement the transform and inverse
transform pair given for vectors of length
Description
Y = fft(X) returns the discrete Fourier transform (DFT) of vector X, computed with a fast
Fourier transform (FFT) algorithm.
If X is a matrix, fft returns the Fourier transform of each column of the matrix.
log :
Natural logarithm
Syntax
Y = log(X)
Description
The log function operates element-wise on arrays. Its domain includes complex and
negative numbers, which may lead to unexpected results if used unintentionally.
Y = log(X) returns the natural logarithm of the elements of X. For complex or negative Z,
abs :
Syntax
abs(X)
Description
abs(X) returns an array Y such that each element of Y is the absolute value of the
corresponding element of X.