Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
MATLAB: MATLAB is a software package for high performance numerical computation and
visualization provides an interactive environment with hundreds of built in functions for
technical computation, graphics and animation. The MATLAB name stands for MATrix
Laboratory produced by Mathworks Inc., USA.
At its core ,MATLAB is essentially a set (a toolbox) of routines (called m files or mex
files) that sit on your computer and a window that allows you to create new variables with
names (e.g. voltage and time) and process those variables with any of those routines (e.g. plot
voltage against time, find the largest voltage, etc.).
Edit window: This is where you write edit, create and save your own programs in files called
M files.
Input-output: MATLAB supports interactive computation taking the input from the screen and
flushing, the output to the screen. In addition it can read input files and write output files.
Data Type: The fundamental data type in MATLAB is the array. It encompasses several
distinct data objects- integers, real numbers, matrices, character strings, structures and cells.
There is no need to declare variables as real or complex, MATLAB automatically sets the
variable to be real.
Dimensioning: Dimensioning is automatic in MATLAB. No dimension statements are required
for vectors or arrays. We can find the dimensions of an existing matrix or a vector with the size
and length commands.
a) Command window.
b) As an M file using Matlab editor.
1. T = 0:1:10
This instruction indicates a vector T which has initial value 0 and final value 10 with an
increment of 1
Therefore T = [0 1 2 3 4 5 6 7 8 9 10]
2. F= 20:1:100
Therefore F = [20 21 22 23 24 100]
3. T= 0: 1/pi: 1
Therefore T= [0, 0.3183, 0.6366, 0.9549]
4. zeros (1, 3)
The above instruction creates a vector of one row and three columns whose values are zero
Output= [0 0 0]
5. zeros (2,4)
Output =
0000
0000
6. ones (5,2)
The above instruction creates a vector of five rows and two columns
ans =
1 1
1 1
1 1
1 1
1 1
7 a = [ 1 2 3]
a=
1 2 3
b = [4 5 6]
4 5 6
a.*b
ans =
4 10 18
8. If C= [2 2 2]
b.*C results in [8 10 12]
9. plot (t, x)
If x = [6 7 8 9]
t = [1 2 3 4]
This instruction will display a figure window which indicates the plot of x versus t.
Change the limits on the x and y axis. axis([xmin xmax ymin ymax])
12. Conv
Syntax: w = conv(u,v)
13. 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,
14. xlabel
Syntax: xlabel('string')
15. ylabel
Syntax : ylabel('string')
16. Title
Syntax : title('string')
Description: title('string') outputs the string at the top and in the center of the current axes.
17. grid on
Syntax : grid on
18. FFT
FFT(X) is the discrete Fast Fourier transform (FFT) of vector X. For matrices, the FFT operation
is applied to each column. For N-D arrays, the FFT operation operates on the first non-singleton
dimension. FFT(X,N) is the N-point FFT, padded with zeros if X has less than N points and
truncated if it has more.
19. ABS
Absolute value.
ABS(X) is the absolute value of the elements of X. When X is complex, ABS(X) is the complex
modulus (magnitude) of the elements of X.
ANGLE(H) returns the phase angles, in radians, of a matrix with complex elements.
21. INTERP
Resample data at a higher rate using low-pass interpolation.
22. DECIMATE
Resample data at a lower rate after low-pass filtering.
Y = DECIMATE(X,M) re-samples the sequence in vector X at 1/M times the original sample
rate. The resulting re-sampled vector Y is M times shorter,
i.e., LENGTH(Y) = CEIL(LENGTH(X)/M). By default, DECIMATE filters the data with an 8th
order Chebyshev Type I low-pass filter with cut-off frequency .8*(Fs/2)/R, before re-sampling.
For More information MATLAB basics please go to APPENDIX-A at the end of this
manual.
You can now practice with basic MATLAB script writing as shown below. From MATLAB
window go to
File- New-Script this will open Editor Window. Copy the text inside the box
t = 0 : 0.001 : 5;
f = input ('Enter the value of frequency');
a = input ('Enter the value of amplitude');
y =a*sin(2*pi*f*t);
plot (t,y,'r');
xlabel ('time');
ylabel ('amplitude');
title ('sine wave')
Output:
Enter the value of frequency 2
Enter the value of amplitude 5
clc;
clear all;
close all;
t = 0 : 0.001 : 5;
f = input ('Enter the value of frequency');
a = input ('Enter the value of amplitude');
y =a*square(2*pi*f*t);
plot (t,y,'r');
xlabel ('time');
ylabel ('amplitude'); title ('Square wave')
grid on;
clc;
clear all;
close all;
a=0.5;
t=0:0.1:10;
Write-Up
Procedure:
Open MATLAB
Open new M-file
Type the program
Save in current directory
Compile and Run the program
For the output see command window\ Figure window
Theoretical Background
CONTINUOUS-TIME SYSTEM
A system in which continuous-time signals are applied and results in continuous-time output,
such a system has ( ) ( ) as input and output respectively.
DISCRETE-TIME SYSTEM
A discrete-time system is described as an operator [ . ] that takes a sequence x(n) called
excitation and transforms it into another sequence y(n) called response. i.e
( ) = [ ( )] (1)
CLASSIFICATION:
LINEAR SYSTEM
A discrete system [ . ] is a linear if and only if L[ . ] satisfies the principle of superposition as
shown in Eq. 2.
( ) = [ ( )] = [ ( ) ( ) = ( ) ( )
(3)
( ) [.] ( ) ( )
( ) ( ) [.] ( )
(4)
( )= [ ( )] = ( ) ( )
Hence we can say that LTI system is completely characterized in the time domain by the impulse
response h(n) as shown below.
( ) ( ) ( )= ( ) ( )
STABILITY
A system is said to be bounded-input boundedoutput (BIBO) stable if every bounded input
produces a bounded output.
| ( )| < | ( )| <, ,
Note: An LTI system is BIBO stable if and only if its impulse response is absolutely summable.
(5)
| ( )| <
CAUSALITY
A system is said to be causal if the output doesnt depend on the future values of the input. An
LTI system is causal if and only if the impulse response
( )= , >0 (6)
An LTI discrete system can also be described by a linear constant coefficient difference equation
of the form
(7)
( ) = ( ),
(8)
( )= ( ) ( )
( )= (10)
Where zk , k= 1,. N, are N roots (also called natural frequencies) of the characteristic
equation.
(11)
|zk| < 1, = 1, . . ,
LAB TASK
Note: make m-file, show functions plot, xlabel, ylabel, hold, stem and observe the output and
show to the instructor, see MATLAB help.
A routine called the FILTER is available to solve difference equations numerically, given the
input and the difference equation coefficients. This routine is invoked by
y = filter (b, a, x)
Where
B = [b0,b1,b2, bM]; a=[a0,a1,a2,.aN];
X is input sequence array. Y output has the same length as input x. one must ensure that
coefficient a0 not be zero.
y(n) y(n 1) + 0.9(n 2) = x(n), n
Calculate and plot the impulse response h(n) at n= -20, ., 100.
Calculate and plot the unit step response s(n) at n= -20, ., 100.
Task-2
MATLAB script for step response
Note: Impulse function is provided as below. Figure out the step function on your own. Also try
to use builtin impz function in matlab.
To determine the stability of the system, we have to determine h(n) for all n. we can use the plot
of impulse response to observe that h(n) is practically zero for n > 120. Hence the sum |h(n) |
can be determined from MATLAB using.
sum(abs(h))
ans =14.8785
This implies that the system is stable. An alternate approach is to use the matlab stability
condition using MATLABs root function.
>>z = roots(a); magz = abs(z)
magz = 0.9487
0.9487
Since the magnitudes of both roots are less than one, the system is stable.
The input sequence is of finite duration ( ) = ( ) ( 10) while the impulse response
is of infinite duration ( ) = (0.9) ( ). Determine ( ) = ( ) ( ).
Solution
If the LTI system, given by the impulse response h(n), can be described by a difference equation,
then y(n) can be obtained from the filter function. From the ( ) expression
0. ( 1) = 0.9(0.9) ( 1)
= (0.9) ( 1)
or
( ) 0.9 ( 1) = (0.9) ( ) (0.9) ( 1)
= (0.9) ( ( ) ( 1) )
= (0.9) ( )
= ( )
The last step follows from the fact that ( ) is nonzero only at n = 0. By definition ( ) is the
output of an LTI system when the input is ( ). Hence substituting ( ) for ( ) and ( )
for ( ), the difference equation is ( ) 0.9 ( 1) = ( ).
LAB ASSIGNMENT
P1. A particular linear and time-invarient system is described by the difference equations
P2. Let ( ) = ( . ) ( ) .
a. Determine ( ) ( ) analytically.
b. Using the filter function, determine the first 50 samples of ( ) ( ).
Write-Up
Related Topics from the course textbook: Chapter 3 Sec 3.1 and sec 3.2
Students responsibilities in this lab
1. Write MATLAB script 2. Generate all the
(.m file) MATLAB
/SIMULINK graphs
3. Do all the tasks 4. Submit report write-up
for previous lab at the
start of the lab
5. Save your files for 6. Show your work to
future usage your lab instructor
Procedure:
Open MATLAB
Open new M-file
Type the program
Save in current directory
Compile and Run the program
For the output see command window\ Figure window
Theoretical Background
Just as the Fourier transform forms the basis of signal analysis, the z-transform forms the basis of
system analysis. If x[n] is a discrete signal, its z-transform X(z) is given by:
LINEARITY
[ ( )+ ( )] = ( )+ ( )]; :
Frequency shifting
[ ( )] = =;
| |
FOLDING
[ ( )] = =;
COMPLEX CONJUGATION
[ ( )] = ( );
[ ( )]
( )
=
MULTIPLICATION
[ ( ) ( )]
= ( ) ( ) ;
CONVOLUTION
[ ( ) ( )] = ( ) ( );
( ) [ ( )]
= ( )
+ + ..+
( )= , < | |
+ + ,+
< +
Performing a partial fraction expansion on the proper rational part of X(z) to obtain.
+ + ..+
( )= +
+ + ,+
Proper rational part polynomial part MN
( )= +
TASK1. Let ( ) = ( ), < | | , find x(z) by definition also find out ROC.
Solution:
a 1 a
X(z) = a z = = if <1
z 1 az z
= , |z| > 1: |a| < <
( )
=X(z) ( )
=
B(z) is called the zeros of x(z)and A(z)is called the poles of X(z).
MATLAB SCRIPT:
x1 =[2,3,4];
x2 =[3,4,5,6];
x3 =conv(x1,x2)
X3 = 6 17 34 43 38 24
3 4 5 6
r=
0 0 0 0
TASK4.a: In MATLAB fucntion residuez is available to compute the residue part and
direct (or polynomial) terms of a rational function in .
z
X(Z) =
3z 4z + 1
Solution.
First rearrange X(Z) so that it is a function in ascending powers of z .
z
X(Z) =
3 4z + z
b=[0,1];
a=[3,-4,1];
[R,p,C]=residuez[b,a];
R =
0.5000
-0.5000
P =
1.0000
0.3333
So,
0.5 0.5
X(Z) =
1z 1 0.333z
TASK4.b: Similarly to convert back to the rational function form
LAB ASSIGNMENT
Write-Up
Procedure:
Open MATLAB and open new M-file
Type the program
Save in current directory
Compile and Run the program
For the output see command window\ Figure window
Theoretical Background:
If x(t) is a periodic function with period T, then x(t) may be written as the infinite Fourier series,
( )= + cos + sin (1)
where
= + ( ) cos dt and = + ( ) sin dt
we can write the complex form of the Fourier series as
n = 0, 1, 2.... We can then extend the ideas of frequency decomposition to non-periodic signals
via the Fourier Transform so that the equivalent of the above discrete equations becomes
Xk = ( ) k = 0, 1, 2, . . . , N 1 (3)
( )= Xk k = 0, 1, 2, . . . , N 1 (4)
These equations are known as the Discrete Fourier Transform (DFT) and Inverse Discrete
Fourier Transform (IDFT) respectively.
Matlab Implementation:
If x(n) is of infinite duration, then MATLAB cannot be used directly to compute X(ejw) from
x(n). However, we can use it to evaluate the expression X(ejw) over [0, ] frequencies and then
plot its magnitude and angle (or real and imaginary parts).
Task-1: Evaluate X(ejw) in Example 1 at 501 equispaced points between [0,] and plot its
magnitude, angle, real, and imaginary parts.
Matlab Script
>> w=[0:1:500]*pi/500; % [0,pi] axis divided into 501 points.
>> X= exp(j*w) ./ (exp(j*w)- 0.5*ones(1,501));
>> magX = abs(X); angX = angle(X);
>> realX = real(X); imagX = imag(X);
>> subplot(2,2,1); plot(w/pi, magX); grid
>> xlabel('frequency in pi units'); title('Magnitude Part'); ylabel('Magnitude')
>> subplot(2,2,3); plot(w/pi, angX); grid
>> xlabel('frequency in pi units'); title('Angle Part'); ylabel('Radians')
>> subplot(2,2,2); plot(w/pi, realX); grid
>> xlabel('frequency in pi units'); title('Real Part'); ylabel('Real')
>> subplot(2,2,4); plot(w/pi, imagX); grid
>> xlabel('frequency in pi units'); title('Imaginary Part'); ylabel('Imaginary')
Matlab Script
>> 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'); ylabel('Magnitude')
>> subplot(2,2,3); plot(k/500, angX/pi); grid
>> xlabel('frequency in pi units'); title('Angle Part'); ylabel('Radians')
>> subplot(2,2,2); plot(k/500, realX); grid
>> xlabel('frequency in pi units'); title('Real Part'); ylabel('Real')
>> subplot(2,2,4); plot(k/500, imagX); grid
>> xlabel('frequency in pi units'); title('Imaginary Part'); ylabel('Imaginary')
Matlab Script
>> n = 0:10; x = (0.9*exp(j*pi/3)).^n;
>> k = -200:200; w = (pi/100)*k;
>>X = x*(exp(-j*pi/100)).^ (n'*k);
>> magX = abs(X); angX = angle(X);
>> subplot(2,1,1); plot(w/pi, magX); grid
>> xlabel('frequency in pi units'); title('Magnitude Part'); ylabel('Magnitude')
>> subplot(2,1,2); plot(w/pi, angX/pi); grid
>> xlabel('frequency in pi units'); title('Angle Part'); ylabel('Radians/pi')
Task-4: Let x(n) = (-0.9)n , -10 n 10. Investigate the conjugate-symmetry property of its
discrete-time Fourier transform.
Matlab Script
>> subplot(1,1,1)
>> n = -5:5; x = (-0.9).^n;
>> k = -200:200; w = (pi/100)*k;
>> X = x*(exp(-j*pi/100)).^ (n'*k);
>> magX = abs(X); angX = angle(X);
>> subplot(2,1,1); plot(w/pi, magX); grid
>> axis([-2,2,0,15])
>> xlabel('frequency in pi units'); title('Magnitude Part'); ylabel('Magnitude')
>> subplot(2,1,2); plot(w/pi, angX/pi); grid
>> axis([-2,2,-1,1])
>> xlabel('frequency in pi units'); title('Angle Part'); ylabel('radians/pi')
Lab Assignment
P1.
Write a MATLAB function to compute the DTFT of a finite-duration sequence. The format of
the function should be
Use this function to compute the DTFT in the Task-1 and II.
P2.
For each of the following sequences, determine the DTFT X(ejw). Plot the magnitude and angle
of X(ejw).
x(n) = 3(0.9)nu(n)
x(n) = { 4, 3, 2, 1, -1,-2, -3, -4}
P3.
Repeat Problem II for the following sequence.
x(n) = 5(-0.9)n cos (0.1n) u(n)
Write-Up
Procedure:
Open MATLAB and open new M-file
Type the program
Save in current directory
Compile and Run the program
For the output see command window\ Figure window
Theoretical Background:
If x(n) is absolutely summable, then its discrete-time Fourier transform is given by
[ ( )] = ( )
1
( ) =
2
Provide the plots for the following along with the title of each by matching its response to
Low pass, high pass, band pass or band stop filter. Also include in the title whether the system is
FIR or IIR. The frequency response can be obtained using freqz(num,den). Poles and zero plot is
obtained using zplane(num,den). Comment on the poles and zeros location of each filter.
b = [ 1 2 1];
a = [1 -1.11 0.57 ];
figure
subplot(2,1,1), freqz(b,a)
subplot(2,1,2), zplane(b,a)
b = [1 -2 1];
a = [ 1 -1.11 0.57];
figure
subplot(2,1,1), freqz(b,a)
subplot(2,1,2), zplane(b,a)
Properties of DTFT
In this part fft(x,n) function will be used to prove some of the Fourier transform properties.
Task-1
Verify the linearity property using real-values finite duration sequences
Since the maximum absolute error between the two Fourier transform arrays is less than 10-14,
the two arrays are identical within the limited numerical precision of MATLAB.
Matlab Script
>> n = 0:100; x = cos(pi*n/2);
>> k = -100:100; w = (pi/100)*k; % frequency between -pi and +pi
>> X = x * (exp(-j*pi/100)).^(n'*k); % DTFT of x
>> y = exp(j*pi*n/4).*x; % signal multiplied by exp(j*pi*n/4)
>> Y = y * (exp(-j*pi/100)).^(n'*k); % DTFT of y
>> subplot(1,1,1)
>> subplot(2,2,1); plot(w/pi, abs(X)); grid; axis([-1,1,0,60])
>> xlabel('frequency in pi units'); ylabel('Magnitude');
>> title('Magnitude of X')
>> subplot(2,2,2); plot(w/pi, angle(X)/pi); grid; axis([-1,1,-1,1])
>> xlabel('frequency in pi units'); ylabel('radians/pi')
>> title('Angle of X')
>> subplot(2,2,3); plot(w/pi, abs(Y)); grid; axis([-1,1,0,60])
>> xlabel('frequency in pi units'); ylabel('Magnitude')
>> title('Magnitude of Y')
>> subplot(2,2,4); plot(w/pi, angle(Y)/pi); grid; axis([-1,1,-1,1])
>> xlabel('frequency in pi units'); ylabel('radians/pi')
And from plots we observe that X (ej) is indeed shifted /4 in both magnitude and angle.
Task-3
To verify the folding property
Solution: Let x(n) be a random sequence over -5 n 10 uniformly distributed between [0,
1]. The MATLAB verification is as follows.
Matlab Script
>> n = -5:10; x = rand(1,length(n));
>> k = -100:100; w = (pi/100)*k; % frequency between -pi and +pi
>> X = x * (exp(-j*pi/100)).^(n'*k); % DTFT of x
>> % folding propery
>> y = fliplr(x); m = -fliplr(n); % signal folding
>> Y = y * (exp(-j*pi/100)).^(m'*k); % DTFT of y
>> % verification
>> Y_check = fliplr(X); % X(-w)
>> error = max(abs(Y-Y_check)) % Difference
error = 1.8310e-015
Let
x(n) = sin( n/2), -5 n 10
Then using the evenodd function we can compute the even and odd parts of x(n) and then
evaluate their discrete-time Fourier transforms. We will provide numerical as well as graphical
verification. It is a good exercise to develop a simple MATLAB function to decompose a given
sequence into its even and odd components. This is done in evenodd function.
Matlab Script
error1 = 6.4467e-014
error2 = 6.4712e-014
1:length(n);
x1 = zeros(1,length(m));
x1(n1+nm) = x; x = x1;
xe = 0.5*(x + fliplr(x));
xo = 0.5*(x - fliplr(x));
From the plots we observe that the real part of X (ej) (or the imaginary part of X (ej) is equal to
the discrete-time Fourier transform of xe(n) (or xo(n).
Lab Assignment
P1. Verify the time shifting and conjugation property of DTFT using matlab.
P2. Using the frequency-shifting property, show that the DTFT of a sinusoidal pulse
X(n) = cos (on). N (n)
is given by
( ) ( )
X(ej) = [ ]+ [ ]
( ) ( )
where N (n) is the rectangular pulse as given is previous lab. Compute and plot X(ej) for o =
2 and N = 5, 15, 25, 100. Use the plotting interval [- , ]. Comment on your results.
Write-Up
Write down a paragraph of your understanding developed in this Lab.
Procedure:
Open MATLAB
Open new M-file
Type the program
Save in current directory
Compile and Run the program
For the output see command window\ Figure window
Theoretical Background:
DF analysis equation is given below
( )= ( )
Task-1
Generate DFT Spectrum of a noisy signal
Matlab Script
clear all; clc; close all;
[y,Fs,bits] = wavread('noisy.wav');
Ts = 1/Fs;
n = [0:length(y)-1];
t = n.*Ts;
k = n;
Df = Fs./length(y);
F = k.*Df;
Y = fft(y);
magY = abs(Y);
sound(y,Fs);
figure,
subplot(2,1,1);
plot(F,magY);
grid on;
xlim([0 Fs/2]);
xlabel('Frequency (Hz)');
ylabel('DFT Magnitude');
title('Discrete Fourier Transform');
subplot(2,1,2);
plot(F,magY);
grid on;
xlim([0 2000]);
xlabel('Frequency (Hz)');
ylabel('DFT Magnitude');
title('Discrete Fourier Transform');
Write-Up
What is the significance of finding DFT and PSD? How these are different from one
another?
What are different applications of DFT. Go to section 7.3 of your text book
An efficient implementation of DFT is Fast Fourier Transform. Google it and write
a 1-page summary on FFT and its engineering applications.
Discrete Cosine Transform (DCT) is a special form of DFT. Describe briefly what is
DCT. Read sec 7.5 for some details.
The goal of this weeks assignment is simple. First, you are to get your development environment
set up. Second, you are to become familiar with the tools so that you can write your own basic
software and debug it on the DSK. This assignment is the (only!) one where you do not need to
understand absolutely everything about your code. Code examples can be taken as is, and
understood at a basic level.
Equipment/Software:
For most exercises in this laboratory, the following equipment will be needed at every lab station:
A signal can be defined as a function that conveys information, generally about the state or behavior
of a physical system. There are two basic types of signals viz. Analog (continuous time signals which
are defined along a continuum of times) and Digital (Discrete-time). Remarkably, under reasonable
constraints, a continuous time signal can be adequately represented by samples, obtaining discrete time
signals. Thus digital signal processing is an ideal choice for anyone who needs the performance
advantage of digital manipulation along with today's analog reality. Hence a processor which is
designed to perform the special operations (digital manipulations) on the digital signal within very less
time can be called as a Digital signal processor. The difference between a DSP processor, conventional
microprocessor and a Microcontroller are listed below.
Microprocessor or General Purpose Processor such as Intel xx86 or Motorola 680xx family
Contains
- Only CPU
-No RAM
-No ROM
-No I/O ports
-No Timer
Microcontroller such as 8051 family
Contains - CPU
- RAM
- ROM
-I/O ports
- Timer
- Interrupt circuitry Some Micro Controllers also contain A/D, D/A and Flash Memory
DSP Processors such as Texas instruments and Analog Devices
Contains - CPU
- RAM
-ROM
- I/O ports
- Timers
Optimized for - fast arithmetic
- Extended precision
- Dual operand fetch
- Zero overhead loop
Multiple - access memory architecture Many data-intensive DSP operations require reading a
program instruction and multiple data items during each
instruction cycle for best performance
Specialized addressing modes Efficient handling of data arrays and first-in, first-out FIFO
buffers in memory
Specialized program control Efficient control of loops for many iterative DSP
algorithms. Fast interrupt handling for frequent I/O
operations.
On-chip peripherals and I/O On-chip peripherals like A/D converters allow for small
interfaces low cost system designs. Similarly I/O interfaces tailored
for common peripherals allow clean interfaces to off-chip
I/O devices.
The preferred way to code algorithms is to code them in C. Coding in C requires a compiler that
will convert C code to the assembly code of a given DSP instruction set. C compilers are very
common, so this is not a limitation. In fact, it is an advantage, since C coded algorithms may be
implemented on a variety platforms (provided there is a C compiler for a given architecture and
instruction set). Most of the programs created in this course will be coded in C. In CCS, the C
compiler has four optimization levels. The highest level of optimization will not achieve the same
level of optimization that programmer-optimized assembly programs will, but TI has done a good
job in making the optimized C compiler produce code that is comparable to programmer-
optimized assembly code.
Lastly, a cross between assembly language and C exists within CCS. It is called linear assembly
code. Linear assembly looks much like assembly language code, but it allows for symbolic names
and does not require the programmer schedule events and manage CPU core registers on the DSP.
Its advantage over C code is that it uses the DSP more efficiently, and its advantage over assembly
code is that it requires less time to program with. This will be apparent in future labs when
assembly and linear assembly code are given.
Codec
The codec (coder/decoder) is a chip located on-board the DSK which interfaces the DSP chip to
the analog world, specifically signal generator(s) and either an oscilloscope or stereo headphones.
The codec contains a coder, or analog-to-digital converter (ADC), and a decoder or digital-to-
analog converter (DAC). Both coder and decoder run at sample rates which can be set from 8 KHz
to 96 KHz and support data word lengths of 16b, 20b, 24b, and 32b at the digital interfaces.
C6713 DSP Chip
The C6713 DSP chip is a floating point processor which contains a CPU (Central Processing Unit),
internal memory, enhanced direct memory access (EDMA) controller, and on-chip peripheral
interfaces. These interface include a 32-bit external memory interface (EMIF), four Multi-channel
Buffered Serial Ports (McASP and McBSP), two 32-bit timers, a host port interface (HPI) for high-
speed communication between chips in a multi-DSP system, an interrupt selector, and a phase lock
loop (PLL), along with hardware for Boot Configurations and Power Down Logic.
Timing
The DSP chip must be able to establish communication links between the CPU (DSP core), the
codecs, and memory. The two McBSPs, serial port 0 (SP0) and serial port 1 (SP1), are used to
establish bidirectional asynchronous links between the CPU and the codec or alternately an
external daughter card (not used in this course). SP0 is used to send control data between the codec
and CPU; SP1 plays a similar role for digital audio data. The McBSPs use frame synchronization
to communicate with external devices Each McBSP has seven pins. Five of them are used for
timing and the other two are connected to the data receive and data transmit pins on the on-board
codec or daughter card. Also included in each McBSP is a 32-bit Serial Port Control Register
1. u:\DSP\Support {h initialization header files, .c initialization source code files, .lib pre-compiled
binary library files, .asm vector files, and .cmd linker command file}
2. u:\DSP\Lab x\ {.c project source code}
To create the first path, open Windows Explorer and create the folder DSP to save your work for
this class. This folder will contain all of the sub-folders in this class. This organization is crucial
and cannot be over-stressed. Now double click on your new folder DSP and copy the sub-folder
Support. The Support folder contains the following files:
c6713dskinit.c
c6713dskinit.h
dsk6713.h
dsk6713 aic23.h
dsk6713 dip.h
dsk6713 flash.h
dsk6713 led.h
csl6713.lib
dsk6713bsl.lib
rts6700.lib
Vectors intr.asm
Vectors poll.asm
OR Visit this folder after CCS installation and see the file hierarchy
C:\CCStudio_v3.1\C6000\dsk6713
Task-1
Creating Projects, Debugging and Analysis, and Resets
.sect .data
.short 0
.short 7
.short 10
.short 7
.short 0
.short 7
.short 10
.short 7
.short 0
.short 7
In your project folder, Save the file as initializemem, and choose type .asm.
Create another source file, main.c, given below, and save in your project folder.
//main.c C program
#include <stdio.h>
void main()
{
printf("Begin\n");
printf("End\n");
}
MEMORY
{
IRAM : origin = 0x0, len = 0x10000
}
SECTIONS
{
.vectors > IRAM
.text > IRAM
.bss > IRAM
.cinit > IRAM
.const > IRAM
.far > IRAM
.stack > IRAM
.cio > IRAM
.sysmem > IRAM
}
We must also add the run-time support library for the board, since we have a C program. Add
the file located at c:\ti\c6000\cgtools\lib\rts6701.lib. This file should now appear under the
Libraries folder in the Project View window.
Step 5: Creating the executable file, lab1.out
Before we compile, assemble, and link, there are a number of options we can choose to
determine the amount of optimization to be done. There are four levels (Opt Levels) of
optimization: 0, 1, 2, and 3. The lowest level is 0. However, sometimes, debugging cannot be
done when we use optimization.
Select Compiler and in the Category column, click on Basic. Check that Target
Version is 671x and Opt Level is .
Similarly, select Linker and then Basic. You can change the name of the executable file
that will be produced. Change the output file name to Lab1.out.
Project > Rebuild All compiles, assembles, and links all of the files in the project and
produces the executable file lab1.out. A window at the bottom shows if there are errors.
Project > Build can be used when you have made a change to only a few files and now
wish to compile, assemble, and link with the changed files. There are shortcut buttons on
the window to do Project Build and Rebuild.
Upon building, there should have been a lot of errors. Scroll up until you reach the first red line
with error! in it. Double click on the line. The file initializemem.asm opens at the line where
the error occurred. Assembly code requires that all of the lines in the assembly file not start in
the first column. So enter a space at the beginning of each line in the file and then save the file.
Since we didnt change every file in the project, we can do a Project > Build.
In order to run the program, we need to load the program into the DSP memory.
This step is to check if the values of our intializemem file are in the memory location that we
established in the .cmd file.
Select View > memory.
Type in 0x80000000 in Address memory location.
Select Format: 16bit Signed Int.
A Memory window appears with the memory addresses and their contents.
Compare the first 10 values with the initializemem file data.
Save, Rebuild, and Load the program into the DSP memory.
Run the program.
A pointer is assigned to the beginning of our data in memory. This allows us to bring data into our
c program and print out the data.
Use the mouse to highlight the variable point in the line beginning with: point = (short*).
Right click and select Add to Watch window. A watch window should open with variable
point.
Repeat above procedure for variable i in the line beginning with: printf([%d].
Select Debug > Run.
The program stops at the breakpoint and the watch window shows the value of point before the
pointer is set. To advance the program or move through the breakpoint, hit the shortcut button
step over a line or select Debug > Step Over. The pointer is now set and you can see the value
of the pointer is 0x80000000.
{
int i, ret; short *point;
point= (short *) 0x80000000;
printf(Begin\n);
for (i=0;i<10;i++)
{
printf([%d]%d\n,i, point[i]);
}
ret = ret_sum(point,10); printf(Sum =%d\n,ret); printf(End\n);
}
{
int count, sum; sum=0;
for(count=0; count<N; count++)
sum += array[count];
return(sum);
}
Now we will benchmark or time the subroutine to determine how long it takes to return the sum.
Reload the program.
Select Profiler > Start New Session.
Title the session Lab 1. A profile window comes up in the bottom.
Double click on main.c in the project window.
Put your cursor on the line: int ret_sum(const short* array, int N).
Several shortcut buttons are on the left side of the Profile window.
Hit the Create Profile Area button. Make sure the type is Function and the line number
corresponds to the beginning of the function, since this is where you placed the cursor.
Hit OK.
Expand Lab1.out under the Files window pane. The function ret_sum should be there.
Run the program.
The value for the Incl. Total in the profiler window is the number of clock cycles needed
to run the function ret_sum.
To redo this exercise, highlight ret_sum in the Files window pane, right click, and
select Clear Selected.
Then hit Debug > Restart and Run the program.
Optimization can change the amount of time required to run the function. To observe the effects,
follow these instructions:
The best way to get started with Code Composer is to run some of the simple examples
included with the DSK. The LED example is the easiest example to get started with to become
familiar with the DSK and make sure your development tools are configured correctly. When run,
it will:
To examine the program code, expand the Projects tree at the left of the workspace, then expand
the led.pjt and Source sub items. Double click on led.c to see its contents. You should something
like this:
The LED example demonstrates use of the LED and DIP switch BSL modules. Each has its own
initialization function that must be called before other functions in the module. The
DSK6713_LED_toggle( ) call toggles the state of LED #0. A software delay loop:
/* Spin in a software delay loop for about 200ms */
DSK6713_waitusec (200000);
introduces roughly 200 millisecond delay before toggling the LED again. This delay loop is
responsible for controlling the speed of the blinking LED.
// led.c
#include "ledcfg.h"
/*
* The Board Support Library is divided into several modules, each
* of which has its own include file. The file dsk6713.h must be included
* in every program that uses the BSL. This example also includes
* dsk6713_led.h and dsk6713_dip.h because it uses the LED and DIP modules.
*/
#include "dsk6713.h"
#include "dsk6713_led.h"
#include "dsk6713_dip.h"
/*
* main() - Main code routine, initializes BSL and runs LED application
*/
/*
* EXTRA: Pressing DIP switch #3 changes LED #3 from off to on.
*/
void main()
{
/* Initialize the board support library, must be first BSL call */
DSK6713_init();
while(1)
{
/* Toggle LED #0 */
DSK6713_LED_toggle(0);
TASK-3
Making Simple Changes in led.c program. Modify the loop to make LED blink at approximately 100ms
In order to become familiar with Code Composer, this example will take a quick walk through the
steps involved in making simple changes to the example. One of the easiest changes to make is to
make the LED blink at a higher rate.
To try out your new changes:
1) Save the program code that was just modified. Select File-> Save.
2) Re-compile your program. Every time you make changes to your code you must re-compile
the source code to generate a new executable file. Select Project -> Build. Wait for the build
to complete before continuing.
3) Load the new led.out executable file. Select File-> Load Program then select led.out in the
led\Debug directory in the file browser.
4) Select the Debug-> Run. LED #0 will start blinking twice as quickly as the original version.
5) When you are satisfied that the changes youve made have actually made the LED blink
faster, stop the program by selecting Debug -> Halt.
Introduction to DSP/BIOS
Watch training videos:
1. DSP Kit Tutorial 3A - Make new project with _without DSP_BIOS using CCS 3.1.mp4
2. DSP Kit Tutorial 3B - Make new project with_without DSP_BIOS using CCS 3.1.mp4
3. DSP Kit Tutorial 3C - Make new project with_without DSP_BIOS using CCS 3.1.mp4
Even though the LED example may seem simple, it is built on top of TIs DSP/BIOS, a real-time
multitasking kernel. One of the features of the Code Composer development environment is its
close integration with DSP/BIOS which allows users to easily add functionality to their code that
typically requires a considerable amount of effort with other tools. All of the DSK specific
examples use DSP/BIOS.
DSP/BIOS programs are organized such that logically independent parts of a program are executed
as independent tasks and threads. In the context of an application like a mobile phone, one task
could be assigned to listening for wireless communication transfers, another assigned to wait for
user input, another to periodically check the battery level and so on rather than have a single task
To examine the program code, expand the Projects tree at the left of the workspace, then expand
the ledprd.pjt and Source subitems. Double click on ledprd.c to see its contents.
You can see that only initialization is done in the main() function. When main() is finished, it
returns back to the DSP/BIOS scheduler which takes over responsibility of finding more work to
be done. In this case, blinkLED0() is defined as a periodic thread that is scheduled to run every
200ms. Advantages of this method are:
No time is wasted spinning in loops. Work is done when it is scheduled or a resource that
work depends on becomes available.
Independent work can be separated into logical threads that are managed by DSP/BIOS,
simplifying your code.
* ======== ledprd.c ========
*
* This example blinks LED #0 at a rate of about 4 times per second using
* the LED module of the the 6713 DSK Board Support Library. The example
* also reads the state of DIP switch #3 and lights LED #3 if the switch
* is depressed or turns it off if the switch is not depressed.
*
* When the program is run, DSP/BIOS initializes itself and calls the main()
* function. Main() initializes the BSL then exits and returns control back
* To DSP/BIOS. The real work is done inside blinkLED0() which is a DSP/BIOS
* periodic thread that is run every 125ms.
* A second thread named blinkLED1() is also included that blinks LED #1
* Asynchronously with blinkLED0 () to demonstrate DSP/BIOS multitasking.
* It is not enabled by default but can be added by creating a new periodic
* thread entry for it in the DSP/BIOS scheduler.
1) Expand the Scheduling entry in the DSP/BIOS Configuration Tool and right clock on PRD -
Periodic Function Manager. Select the Insert PRD menu option. It will create a new scheduling
entry called PRD0.
2) Right click on PRD0 and select Properties. Change the period field to 100 and the function
field to _blinkLED1. It will look like this when you are done:
3) Hit OK to confirm the settings. Single click on PRD0 and the Configuration Tool will let
you change the name. Change it to PRD_blinkLED1.
4) Save the new DSP/BIOS configuration file. Select File Save.
5) Re-compile your program. Select Project ->Build.
6) Load the new led.out executable file. Select File -> Load Program then select ledprd.out
in the ledprd\Debug directory in the file browser.
Task-4:
TONE Example-A 1 KHz sine wave
When you are satisfied that the program is indeed running correctly, stop the program by
selecting Debug ->Halt.
The array sinetable contains a pre-generated sine wave using signed 16-bit data that matches the
AIC23. The data covers exactly one period and the amplitude matches the full range of the codec.
#define SINE_TABLE_SIZE 48
/* Pre-generated sine wave data, 16-bit signed samples */
Int16 sinetable[SINE_TABLE_SIZE] = {
0x0000, 0x10b4, 0x2120, 0x30fb, 0x3fff, 0x4dea, 0x5a81, 0x658b,
0x6ed8, 0x763f, 0x7ba1, 0x7ee5, 0x7ffd, 0x7ee5, 0x7ba1, 0x76ef,
0x6ed8, 0x658b, 0x5a81, 0x4dea, 0x3fff, 0x30fb, 0x2120, 0x10b4,
0x0000, 0xef4c, 0xdee0, 0xcf06, 0xc002, 0xb216, 0xa57f, 0x9a75,
0x9128, 0x89c1, 0x845f, 0x811b, 0x8002, 0x811b, 0x845f, 0x89c1,
0x9128, 0x9a76, 0xa57f, 0xb216, 0xc002, 0xcf06, 0xdee0, 0xef4c
};
The main loop of the code writes each data point in the sine wave table out to the codec using the
AIC23 codec package of the BSL. Each write function sends a single 16 bit sample to the codec.
In this case the same data is sent out twice, once to the left channel and once to the right channel.
The codec is configured to accept data at a rate of 48,000 stereo samples per second. Since the
sine table is 48 entries long, the resulting output wave will be a 1KHz sine wave with the same
output on both the left and right channels.
The serial port McBSP1 is used to transmit data to the codec at a much slower rate than the DSP
can process data. It accepts data 16 bits at a time and shifts them out slowly one at a time. The
write function returns a 1 if the write is completed successfully or a 0 if the serial channel is busy.
The while( ) loop around the writes waits while the serial port is busy so program can be
synchronized to the data rate of the codec.
The following two commands are used to initialize and shut down the codec and are found at the
beginning and end of all programs that use BSL codec module. The DSK6713_openCodec()
command returns a handle that is passed each of the other codec functions.
Task-5:
DSK Application Example: Playing a song or some audio file
The DSK_App example digitally processes audio data from the line input on the AIC23 codec
and plays the result on the headphone and line output. It uses the McBSP and EDMA (Enhanced
Direct Memory Access) to efficiently handle the data transfer without intervention from the DSP.
The example resides in c:\CCStudio_v3.1\examples\dsk6713\bsl\dsk_app.
The EDMA driven audio implemented by the audio example is highly optimized and
representative of what might be used in production code. It is a good base to use for your own
audio code.
When you are satisfied that the program is indeed running correctly, stop the program by
selecting Debug -> Halt.
1. The -c line in dsk6713.cmd tells the linker to use the auto initialization feature of C
programs. The TI C compiler builds a table containing the data required to initialize all
variables initialized in the C program. Code is included in the executable module to load
the data values in the table into the variables when the program starts. The -heap and
2. -stack lines allocate memory for the heap and stack. The number after these commands
is the allocated memory size in bytes.
3. The -lrts6700.lib line tells the linker to search the C run-time library rts6700.lib for
unresolved references. This library provides the standard functions the C compiler expects.
4. The line -lcsl6713.lib tells the linker to search the Chip Support Library (CSL) csl6713.lib.
CCS has been set to know the path to these libraries. They are almost always used by C
programs. Including these lines in the linker command file automatically includes them in
the linker search path without any further effort on your part.
5. The MEMORY portion of the command file is used to define the physical memory layout.
For example, the line
IRAM : origin = 0x0, len = 0x40000 /* 256 Kbytes */ defines the internal program memory to
be a region called IRAM which starts at byte address 0x00000000, and has a length of 0x00040000
bytes which is 256 Kbytes.
dskstart32.c
/*************************************************************/
/* Function DSK6713_AIC23_openCodec() in dsk6713_opencodec.c */
/* is a modification of the same function in the BSL module */
/* DSK6713_AIC23_openCodec.c. It configures McBSP1 to trans- */
/* mit and receive 32-bit words rather than 16-bit words by */
/* changing the RWDLEN1 value to 32BIT, XWDLEN1 to 32BIT, */
/* RFRLEN1 to OF(0), and XFRLEN1 to OF(0) in structure */
/* mcbspCfgData in dsk6713_opencodec.c. This causes McBSP1 */
/* to use a single phase frame consisting of one 32-bit word */
/* per frame. Words are sent to the codec by using the BSL */
/* function DSK6713_AIC23_write() and read from the codec by */
/* using the function DSK6713_AIC23_read(). */
/*************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <dsk6713.h>
#include <dsk6713_aic23.h>
#include <intr.h>
#include <math.h>
/* Codec configuration settings */
/* See dsk6713_aic23.h and the TLV320AIC23 Stereo Audio CODEC Data Manual */
/* for a detailed description of the bits in each of the 10 AIC23 control */
/* registers in the following configuration structure. */
DSK6713_AIC23_Config config = { \
0x0017, /* 0 DSK6713_AIC23_LEFTINVOL Left line input channel volume */ \
0x0017, /* 1 DSK6713_AIC23_RIGHTINVOL Right line input channel volume */\
0x00d8, /* 2 DSK6713_AIC23_LEFTHPVOL Left channel headphone volume */ \
0x00d8, /* 3 DSK6713_AIC23_RIGHTHPVOL Right channel headphone volume */ \
0x0011, /* 4 DSK6713_AIC23_ANAPATH Analog audio path control */ \
0x0000, /* 5 DSK6713_AIC23_DIGPATH Digital audio path control */ \
0x0000, /* 6 DSK6713_AIC23_POWERDOWN Power down control */ \
0x0043, /* 7 DSK6713_AIC23_DIGIF Digital audio interface format */ \
0x0081, /* 8 DSK6713_AIC23_SAMPLERATE Sample rate control (48 kHz) */ \
0x0001 /* 9 DSK6713_AIC23_DIGACT Digital interface activation */ \
};
/***********************************************************/
/* Main program: Replace with your code */
/***********************************************************/
void main(void){
DSK6713_AIC23_CodecHandle hCodec;
The lower level functions McBSP_xrdy( ) and MCBSP_write( ) are in TIs CSL library.
MCBSP_rrdy() and MCBSP_read() are in TIs CSL library. MCBSP_rrdy() tests the receive ready
(RRDY) flag of the McBSP associated with the handle. MCBSP_read() reads a 32-bit word from
the Data Receive Register (DRR) of the McBSP. Notice that the word read is typed as an unsigned
int.
Equipment/Software:
A PC running Windows OS and MATLAB
Required Output Files for this lab: .m files for various tasks
Background: Familiarity with MATLAB
Reference Book: Digital Signal Processing Principles, Algorithms and Applications 4TH
Edition John G Proakis, Dimitris G. Manolakis
Related Topics from the course textbook: Chapter 6 Sec 6.1
Students responsibilities in this lab
1. Write MATLAB script 2. Generate all the
(.m file) MATLAB
/SIMULINK graphs
3. Do all the tasks 4. Submit report write-up
for previous lab at the
start of the lab
5. Save your files for 6. Show your work to
future usage your lab instructor
Theoretical Background:
Related topics from course textbook: section
Background on Sampling, Quantization and Reconstruction
Analog signal is sampled at a fixed time interval so the ADC (Analog-to-Digital Converter) will
convert the sampled voltage level to a digital value; this is called the sampling process.
The fixed time interval between two samples is the sampling period, and the reciprocal of the
sampling period is the sampling rate. Half of the sampling rate is the folding frequency (Nyquist
limit).
The sampling theorem condition that the sampling rate be larger than twice the highest frequency
of the analog signal to be sampled must be met in order to have the analog signal be recovered.
The sampled spectrum is explained using the well-known formula
Task-1:
Generate the graph for continuous-time signal ( ) as shown below and save the figure
in your working directory.
Determine the highest frequency in ( ) . What is the corresponding sampling
frequency and sampling period using Nyquist Theorem?
Generate the graph for sampled signal with Ts1 = 0.05 s. Complete the values in Colum-3
of the following table.
Do you see any aliasing? How you will determine if aliasing is happening.
Note that there are no frequencies between -ws2/2 and +ws2/2 except the original frequencies, but
now the filter used to recover x(t) from the samples must be much closer to ideal than before
since the next frequencies outside the band of +/- ws2/2 are at +/- 39.8 rad/sec. In the figure
below, It is clear that the samples exactly equal the x(t) values at the sample points,
but if you looked only at the sample values, you would not have as clear an idea of what x(t)
actually looks like as you would be the Ts1=0.05 sampling period.
Samples of x(t) with Ts2 = 0.1 s
Task-3: Identify the aliased frequencies that appear in the sampled spectrum.
If an ideal low-pass filter with a cut-off frequency of ws3/2 = 15.7080 rad/sec is used to process
the discrete-time samples, the original frequency of 23 rad/sec would be eliminated, and the
frequency of 8.4159 rad/sec would be included. This produces a completely different signal than
the original x(t), even though the sample values correspond to x(t) exactly. If we define the new
signal by. ( ) = cos(7 ) + cos(8.4159 )
We can see that the samples with Ts3 = 0.2 seconds exactly equal the values of x(t) and x1(t) at
the sample points even though they are two completely different signals. This illustrates the fact
that in order to recover the original continuous-time signal from discrete-time samples, the
sampling frequency must be at least twice as high as the highest frequency in the continuous-
time signal. The higher the sampling frequency, the more reliable and easier will be the recovery
-- compare the sampled signals using ws1 vs. ws2. When the sampling frequency is less than twice
the highest frequency in the continuous-time signal, recovery cannot be accomplished using only
the sample values, even with ideal filtering.
Write-up
Why do we need an anti-aliasing filter before sampling? The fact that the signal is band-limited
before sampling is a very powerful constraint in the reconstruction of the continuous-time signal.
Can we faithfully recover the following two sampled sinusoids of 200Hz frequency? How can
we do that? Why we sampled this sinusoid at a much higher rate of 8192 Hz than Nyquist rate.
Equipment/Procedure:
A PC running Windows OS and MATLAB/Audacity
Related topics from Course textbook: Section
Procedure for this LAB
Open the MATLAB and locate the directory on your PC folder with name: Quantization_Lab
Locate the corresponding MATLAB file Lab_quantization_round.m
Open this file in MATLAB editor, read it and hit the simulation. Perform Task1 to Task-3 and
show your work to Lab instructor.
Theoretical Background:
Quantization
Quantization of Sinusoidal Signal (rounding to nearest integer bit) and Signal-to-Quantization-
Noise Ratio (SQNR) calculation
In this experiment you will explore the experimental and theoretical SQNRs. It is expected that
by increasing the quantization bits improve the SQNR. Run the following Matlab script. Note: X
denotes the original signal and xd is the quantized signal for all graphs in this lab.
%Lab_quantization_round.m
t=0:0.1:4*pi;
Task-1: After running the MATLAB script fill the following table
Each dot in the figure above represents one audio sample. There are two factors that determine
the quality of a digital recording:
Sample rate: The rate at which the samples are captured or played back, measured in Hertz
(Hz), or samples per second. An audio CD has a sample rate of 44,100 Hz, often written as 44
KHz for short. This is also the default sample rate that Audacity uses, because audio CDs are so
prevalent.
Sample format or sample size: Essentially this is the number of digits in the digital
representation of each sample. An audio CD has a precision of 16 bits, which corresponds to
about 5 decimal digits.
Higher sampling rates allow a digital recording to accurately record higher frequencies of sound.
The sampling rate should be at least twice the highest frequency you want to represent. Humans
can't hear frequencies above about 20,000 Hz, so 44,100 Hz was chosen as the rate for audio
CDs to just include all human frequencies. Sample rates of 96 and 192 KHz are starting to
Sound Recording: Set up a microphone and use Audacity to record a few seconds of your
speech at 44,100 Hz and 16 bits, which are the default settings for Audacity. The lab
instructor will show you how to set up the microphone and record if you have difficulty. You
After you record (or otherwise obtain) a short sound file you may use Audacity to change the
sampling rate. This may be accomplished by going to the Project Rate area in the lower
left hand corner of the project window. You are shown a pop up menu in which you may
choose among fixed sample rate options or you can type in any sample rate value you want.
Make sure that you start with sound files that are in 44.1 kHz 16 bit format.
Task-2 Convert and save your files to 22,050 kHz, 11 kHz, 5.5 kHz, 2 kHz, and
1 kHz and comment on the audible artifacts of reducing the sampling rate. Play
the files in Audacity.
R, nbits % Print out the sample rate R and the number of quantization levels nbits
The number of quantization levels may be adjusted by changing the value of bits. On
the following line put in the name of the wav file that you want to manipulate,
salinasCDAudio.wav is a guitar recording. This is a good recording with which to
Analytical Questions
For both recorded speech and the music files at what bit resolution do the quantization
effects become audible? Describe the audible effects in both the spoken and music files at the
different bit-resolution levels. Can you still recognize the sound at 4-bit and 2-bit (even 1-
bit) quantization?
Construct a table of the Signal to Noise Ratio (in decibels) for bit resolutions from 4 bit to
32 bits. (each additional bit is a 6 dB increase of signal to quantization noise ratio)
Sampling Quantization Quality of SQNR, dB
Bits
Rate, R Levels Audio
4
8
16
32
Write-up
Your write-up should answer all questions posed above and well as to furnish qualitative
descriptions of what you heard in the various tests.
Equipment/Software:
A PC running Windows OS and MATLAB
Reference Book: Digital Signal Processing Principles, Algorithms and Applications 4TH
Edition John G Proakis, Dimitris G. Manolakis
Related Topics from the course textbook: Chapter 6 Sec 6.4 and sec 6.5
Theoretical Background
Pre-lab: Lab instructor should provide a document: Butterworth Filter design to students for next
lab. Background on Reconstruction
Analog signal is sampled at a fixed time interval so the ADC (Analog-to-Digital Converter) will
convert the sampled voltage level to a digital value; this is called the sampling process.
( ) ( )
Then the impulse train is filtered through an ideal analog low-pass filter band-limited to the
[Fs/2, Fs/2] band.
( )= ( ) [ ( )]
Using sinc function is of infinite order and not causal, not practical so in practice we need a
different approach. The two-step procedure is still feasible, but now we replace the ideal low-
pass filter by a practical analog low-pass filter. Ideal Interpolation via sinc function, Zero-Order-
Hold (ZOH), First-Order-hold (FOH), Spline interpolation are familiar methods to reconstruct
the original band-limited analog signal.
The reconstruction (analog low-pass) filter is adopted after DAC to remove the spectral images
that exist in the sample-and-hold signal and obtain the smoothed analog signal. The sample-and-
hold DAC effect may distort the baseband spectrum, but it also reduces image spectrum.
Procedure for this LAB
Open the MATLAB and locate the directory on your PC folder with name: Reconstruction_Lab
Run the reconstruction demos by running the Matlab files. reconstruction_demo_SINC.m,
reconstruction_demo_ZOH.m, reconstruction_demo_FOH.m by locating these files in your
working directory.
Open this file in MATLAB editor, read it and hit the simulation. Perform Task1 to Task-3 and
show your work to Lab instructor.
Sinc Reconstruction
The maximum error between the reconstructed and the actual analog signal is 0.0363, which is
due to the fact that xa(t) is not strictly band-limited (and also we have a finite number of
samples).
Task-1:
Reconstruct the analog ( ) = exp(| |) using Ts=0.001 and record your observations. Try
different Ts.
Revisit reconstruction_demo_SINC.m and change the analog signal to x(t)=cos7t+cos23t .
Again run the code. Check if sinc interpolation is working or not. Change Ts and try to recover
x(t).What is the error.
which can be obtained by filtering the impulse train through an interpolating filter of the form
MATLAB approach for signal reconstruction is a plotting approach. The stairs function plots a
staircase (ZOH) rendition of the analog signal, given its samples,
%% reconstruction_demo_ZOH.m
% reconstruction demo_ZOH
clear all,clf
endt=10;
ylims=[-1.2 1.2];
t=0:1/100:endt;
multiplier=2
x=cos(multiplier*t);
fs=[1 2 3 4];% Sampling Frequencies
%
% ZOH RECONSTRUCTION
%
figure(1), clf;
numplots=length(fs)+1; % no of plots
% original signal
subplot(numplots,1,1), plot(t,x);
title('Cosine function and Its ZOH Reconstructions');
Task-2:
Now change the analog signal to x(t)=cos(5*t) and make the following changes in the code at
appropriate places
endt=10;
x=cos(5*t);
xs=cos(5*ts)
fs=[3 6 9 12];% Sampling Frequencies
and run MATLAB script reconstruction_demo_ZOH.m again. Check if ZOH interpolation is
working or not. Change fs vector according to signal and try to recover x(t).
Equipment/Software:
A PC running Windows OS and MATLAB
Required Output Files for this lab: .m files for various tasks none
Background: Familiarity with MATLAB
Reference Book: Digital Signal Processing Principles, Algorithms and Applications 4TH
Edition John G Proakis, Dimitris G. Manolakis
Related Topics from the course textbook: Chapter 6 Sec 6.4
Students responsibilities in this lab
1. Write MATLAB script 2. Generate all the
(.m file) MATLAB
/SIMULINK graphs
3. Do all the tasks 4. Submit report write-up
for previous lab at the
start of the lab
5. Save your files for 6. Show your work to
future usage your lab instructor
Theoretical Background
Analog signal is sampled at a fixed time interval so the ADC (Analog-to-Digital Converter) will
convert the sampled voltage level to a digital value; this is called the sampling process.
A band-limited analog signal ( ) with bandwidth F0 can be reconstructed from its sample
values ( ) = ( ) if the sampling frequency Fs = 1/Ts is greater than twice the bandwidth
F0 of ( ) i.e. Fs > 2F0.Otherwise aliasing would result in ( ). The sampling rate of 2F0 for
an analog band-limited signal is called the Nyquist rate.
Samples ( )are converted into weighted impulse train
( ) ( )
( )= ( ) [ ( )]
Using sinc function is of infinite order and not causal, not practical so in practice we need a
different approach. The two-step procedure is still feasible, but now we replace the ideal low-
pass filter by a practical analog low-pass filter. Ideal Interpolation via sinc function, Zero-Order-
Hold (ZOH), First-Order-hold (FOH), Spline interpolation are familiar methods to reconstruct
the original band-limited analog signal.
The reconstruction (analog low-pass) filter is adopted after DAC to remove the spectral images
that exist in the sample-and-hold signal and obtain the smoothed analog signal. The sample-and-
hold DAC effect may distort the baseband spectrum, but it also reduces image spectrum.
Reconstruction using Analog Low-Pass Filter
In practice, we often use one of the standard analog low pass filters having order 2 to 10 (or so)
as reconstruction filters. In the previous labs we dealt with basic sampling theory, quantization
and reconstruction using sinc, ZOH and FOH in MATLAB.
This lab
is a
continuation of the sampling and quantization lab. A continuous-time signal which is the sum of
sinusoids, with frequencies of 7 rad/sec and 23 rad/sec, is sampled at three different rates T s1 =
0.05 seconds, Ts2 = 0.1 seconds, and Ts3 = 0.2 seconds. This lab will look at what happens when
these three sampled signals are passed through a low-pass filter in an attempt to reconstruct the
original x(t). For reference, the signal x(t) is shown in the following figure.
( ) = cos(7 ) + cos(23 )
Task-1: Determine the highest frequency in ( ) . What is the corresponding sampling
frequency and sampling period using Nyquist Theorem?
( )=( )( )( )
Butterworth Coefficients
n a1 c a2 c2 a3 c3 a4 c4 a5 c5 a6 c6 a7 c7 a8 c8
1 1.0000
2 1.4141 1.0000
3 2.0000 2.0000 1.0000
4 2.6131 3.4142 2.6131 1.0000
5 3.2361 5.2361 5.2361 3.2361 1.0000
Task-2 Generate Magnitude and Phase response for Butterworth Filter of 5th order by
modifying MATLAB code and using coefficients from table above.
We will start by passing the signal which was sampled with Ts1 = 0.05 seconds through the 4th
order Butterworth filter. Remember that both of the sinusoidal frequencies which make up x(t),
w1 = 7 rad/sec and w2 = 23 rad/sec, are less than 1/2 of the sampling frequency (ws1/2 = 62.8319
rad/sec) and that the first few frequencies which appear in X*(jw) when Ts = 0.05 s are:
[-132.6637 -118.6637 -102.6637 -23.0000 -7.0000 7.0000 23.0000
102.6637 118.6637 132.6637] rad/sec
The cutoff frequency for the filter is ws1/2. In the figure below, you can see that the filtered
signal approximates the original x(t) quite well. There is a slight time delay between the original
and reconstructed signal, but not much distortion. One reason for this is that with Ts = 0.05 s,
there is a big gap between the frequencies in x(t) and the next frequency in the sampled signal.
Observation: Why there is a delay between original signal and reconstructed signal?
Signal Reconstruction of x(t) with Ts2 = 0.1 s
Next, consider Ts2 = 0.1 seconds (ws2 = 62.8319 rad/sec). Both of the frequencies in x(t) are less
than ws2/2 = 31.4159 rad/sec, but now the higher frequency (23 rad/sec) is closer to the top of the
primary strip than with the first sampling period. The first few frequencies which appear in
X*(jw) when Ts = 0.1 s are:
[-69.8319 -55.8319 -39.8319 -23.0000 -7.0000 7.0000 23.0000
39.8319 55.8319 69.8319 85.8319] rad/sec
We will pass this sampled signal through the 4th-order Butter worth filter. The cutoff frequency
is ws2/2 rad/sec. The filtered signal approximates the original x(t) fairly well, in that most of the
peaks and valleys of x(t) are also in the filtered signal. Now there is more time delay and more
distortion in the signal. There is less gap between the frequencies in x(t) and the next frequency
in the sampled signal.
Signal Reconstruction of x(t) with Ts2 = 0.1 s
Write-Up
Theoretical Background: Familiarity with FIR Filter structures and design methodologies
Related Topics from the course textbook: Chapter 9 section 9.2, chapter 10 Sec 10.2
MATLAB abs, fdatool, fft, fir1, fir2, fircls1, freqz,
Commands fvtool, imag, impz, log, stem, unwrap, window,.
and functions
The digital filters are used to modify the digital signal amplitude (the gain of the signal
frequency components) according to a desired frequency response. The linear phase
response of the FIR filter means that all of the signal frequency components in the input
are delayed by the same amount.
General Procedure for this LAB
Open the MATLAB editor for writing .m script files
Do examples 1-2 to see the magnitude response of FIR filters
Select the appropriate FIR filter design method (Window Method).
Select the type of the window for the truncation of desired filter impulse response.
Set the appropriate sampling (Fs) and cutoff (Fc) frequencies and design formulas.
Calculate the order of the FIR filter to satisfy the given stopband attenuation.
FIR Filters Design Method: Available MATLAB functions
B = fir1(N,Wn) designs an N'th order lowpass FIR digital filter and returns the filter
coefficients in length N+1 vector B. The cut-off frequency Wn must be between 0 < Wn < 1.0,
with 1.0 corresponding to half the sample rate. The filter B is real and has linear phase,
i.e., even symmetric coefficients obeying B(k) = B(N+2-k), k = 1,2,...,N+1.
If Wn is a two-element vector, Wn = [W1 W2], FIR1 returns an order N bandpass filter with
passband W1 < W < W2.
B = FIR1(N,Wn,'high') designs a highpass filter.
B = FIR1(N,Wn,'stop') is a bandstop filter if Wn = [W1 W2].
B = FIR1(N,Wn,'DC-1') makes the first band a passband.
B = FIR1(N,Wn,'DC-0') makes the first band a stopband.
For filters with a passband near Fs/2, e.g., highpass and bandstop filters, N must be even.
By default FIR1 uses a Hamming window. Other available windows, including Boxcar,
Hanning, Bartlett, Blackman, Kaiser and Chebwin can be specified with an optional trailing
argument.
For example,
B = FIR1(N,Wn,kaiser(N+1,4)) uses a Kaiser window with beta=4.
B = FIR1(N,Wn,'high',chebwin(N+1,R)) uses a Chebyshev window.
Example 1: Design a 48th-order Linear Phase FIR bandpass filter with passband
0.35 0.65: Run the following code in MATLAB for a bandpass FIR filter.
b = fir1(48,[0.35 0.65]);
freqz(b,1,512)
( )= ( )
1
( )= ( )
2
The desired impulse response defined above is infinite in duration and must be truncated and
shifted by( M1)/2 samples to design a real valued and causal FIR filter. Truncation can be
performed by multiplying the desired impulse response ( ) by a window function. The
rectangular window is defined by
1, , = 0,12, . , 1
( )= 0,
The effect of application of rectangular window to the desired frequency response of the filter
can be evaluated by convolution of ( ) with ( )
1
( )= ( ) ( )
2
The Fourier transform W (w) of the rectangular window w (n) is defined by
Where I0 [ ]is the modified zero-order Bessel function and controls the stopband
attenuation,
Empirical equations:
% fir_LP_hamming.m
wp = 0.2*pi; ws = 0.3*pi; tr_width = ws - wp;5 Delta_W
M = ceil(6.6*pi/tr_width) + 1; % window size
n=0:1:M-1;
wc = (ws+wp)/2; % Ideal LPF cutoff frequency
hd = ideal_lp(wc,M);% ideal low pass filter function
w_ham = (hamming(M))'; % Using Haming window
h = hd .* w_ham;% Actual windowed response
%ideal_lp.m
function hd = ideal_lp(wc,M);
% Ideal LowPass filter computation
% --------------------------------
% [hd] = ideal_lp(wc,M)
% hd = ideal impulse response between 0 to M-1
% wc = cutoff frequency in radians
% M = length of the ideal filter
%
alpha = (M-1)/2; n = 0:1:(M-1);
m = n - alpha; fc = wc/pi; hd = fc*sinc(fc*m);
RESPONSE
%fir_lp_kaiser.m
% Low Pass filter design using Kaiser window
wp = 0.2*pi; ws = 0.3*pi; As = 50; tr_width = ws wp;
M = ceil((As-7.95)/(2.285*tr_width)+ 1);
n=0:1:M-1;
beta = 0.1102*(As-8.7);
wc = (ws+wp)/2;
hd = ideal_lp(wc,M);% ideal low pass filter function
w_kai = (132aiser(M,beta));
h = hd .* w_kai;
[db,mag,pha,grd,w] = freqz_m(h,1); delta_w = 2*pi/1000;
As = -round(max(db(ws/delta_w+1:1:501))); % Min Stopband Attenuation
% plots
subplot(2,2,1); stem(n,hd); title(Ideal Impulse Response)
axis([0 M-1 -0.1 0.3]); xlabel(n); ylabel(hd(n))
subplot(2,2,2); stem(n,w_kai);title(Kaiser Window)
axis([0 M-1 0 1.1]); xlabel(n); ylabel(w(n))
subplot(2,2,3); stem(n,h);title(Actual Impulse Response)
axis([0 M-1 -0.1 0.3]); xlabel(n); ylabel(h(n))
subplot(2,2,4); plot(w/pi,db);title(Magnitude Response in dB);grid
axis([0 1 -100 10]); xlabel(frequency in pi units); ylabel(Decibels)
Please refer to John G Proakis : Digital Signal Processing using MATLAB, 3rd edition, Cengage
Learning, 2010 Chapter-7 Section 7.4 for more details.
Task-4
Design a digital FIR lowpass filter with the following specifications:
p = 0.2=passband frequency
s = 0.3=stopband frequency
Rp = 0.25 dB=Passband ripple
As = 50 dB=Stop band attenuation
Use Frequency Sampling method.
The digital filters are used to modify the digital signal amplitude (the gain of the signal
frequency components) according to a desired frequency response. The linear phase
response of the FIR filter means that all of the signal frequency components in the input
are delayed by the same amount.
General Procedure for this LAB
Open the MATLAB get familiar with the graphical user interface (GUI) for digital filter design
found in DSP System Toolbox (The MathWorks, Inc.).
Start the Filter Design and Analysis Tool
Select the filter response type accordingly to the task requirements.
Select the appropriate FIR filter design method (Window).
Select the type of the window for the truncation of desired filter impulse response.
Set the appropriate sampling (Fs) and cutoff (Fc) frequencies.
FDATool: The Filter Design and Analysis Tool (FDATool) is a powerful user interface for
designing and analyzing filters. FDATool enables you to quickly design digital FIR or IIR filters
by setting filter performance specifications, by importing filters from your MATLAB workspace,
or by directly specifying filter coefficients. FDATool also provides tools for analyzing filters,
such as magnitude and phase response plots and pole-zero plots. FVTool, which can be launched
from FDATool, provides a separate window for analyzing filters. You can use FDATool as a
convenient alternative to the command line filter design functions. This chapter contains the
following sections, which walk you through a typical filter design session using the FDATool:
fdatool opens the Filter Design and Analysis Tool (FDATool). Use this tool to
Design filters
Analyze filters
Modify existing filter designs
Getting Started
Type fdatool at the MATLAB command prompt:
>>fdatool
Filter Order You have two mutually exclusive options for determining the filter order when
you design an Equiripple filter:
Specify order: You enter the filter order in a text box.
Minimum order: The filter design method determines the minimum order filter.
Bandpass Filter Frequency Specifications
For a bandpass filter, you can set
Units of frequency:
Hz
kHz
MHz
Normalized (0 to 1)
Sampling frequency
Passband frequencies
Stopband frequencies
You specify the passband with two frequencies. The first frequency determines the lower edge of
the passband, and the second frequency determines the upper edge of the passband.
from the Analysis menu or click the Full View Analysis button:
This launches the Filter Visualization Tool (fvtool).
You can use this tool to annotate your design, view other filter characteristics, and print your
filter response. You can link FDATool and FVTool so that changes made in FDATool are
immediately reflected in FVTool. See fvtool for more information.
To move a data marker, grab its black square at the corner of the marker. Dragging the marker
with your mouse changes the Frequency and Magnitude values.
To change the properties of a data marker, right-click on the marker to display the properties
menu:
Alignment--Change the position of the marker. Available options are top-right, top-left, bottom-
right, and bottom-left.
Font Size--Change the font size.
Movable--Allow the marker to be moved on the response.
Interpolation--Select Nearest to force the marker to snap to nearest point along the plotted
curve. Select Linear to interpolate between points along the plotted curve.
on the sidebar, gives you access to the Realize Model panel and the options for realizing
your quantized filter as a Simulink subsystem block.
On the panel, as shown here, are the options provided for configuring how FDATool realizes
your model.
Task-3: Very important: After hands-on experience with fdatool and fvtool
For Task 1
Using FDATool/FVTool
Plot Magnitude and phase response
Plot Group delay response
Plot Impulse response
Plot Step response
Pole-zero plot
Export filter coefficients into a text file (.mat file)
What is the order of the filter that you designed in Task-1
Is it stable?
In fdatool select Quantization icon and quantize filter coefficients to fixed-point filter
arithmetic
What is the filter-structure
Task 4: TAKE-HOME
Design Band-stop Filter
design specifications
Tool: fdatool
Design Method: FIREquiripple
Stopband attenuation of 45 dB
Frequencies at the edge of the pass band: 610 Hz and 1050 Hz
Frequencies at the edge of the stopband: 680 Hz and 940 Hz
use Hamming window
Order: Minimum
Write-up and Analysis: Explore different features of fdatool, FVTool along with SPTool. Write
a one page summary how would you implement your designed filters in hardware, say you have
a DSP processor board and CODE Composer software studio from Texas Instruments and you
have a quantized coefficients of the filter. You do the simulation in MATLAB and your design is
ready for hardware implementation.
The primary advantage of IIR Filters over FIR filters is that they typically meet a given set of
specifications with a much lower filter order than a corresponding FIR filter. This has the
obvious implementation advantages. IIR filters have nonlinear phase (they cannot have linear
phase; they might almost have linear phase).However, if data processing is to be performed
offline, then the effects of the nonlinear phase can be eliminated. So let us assume that the entire
Task-1
Design first Butterworth Lowpass IIR Filter and then convert it into High pass filter
Get the passband and stopband ripples
Get the passband and stopband edge frequencies
Calculate the order of the filter using buttord function
Find the filter coefficients, using butter function
Draw the magnitude and phase response
% Lowpass Butterworth Filter
clc;
clear all;
close all;
rp=input('enter the passband attenuation:');
rs=input('enter the stop band attenuation:');
wp=input('enter the pass band frequency:');
ws=input('enter the stop band frequency:');
[N,wn]=buttord(wp/pi,ws/pi,rp,rs);
[b,a]=butter(N,wn);
freqz(b,a);
Lowpass and Highpass Butterworth IIR Filters
Use SAMPLE INPUT for Lowpass filter
enter the passband attenuation:0.4
enter the stop band attenuation:50
enter the pass band frequency:0.2*pi
enter the stop band frequency:0.4*pi
Use SAMPLE INPUT for Highpass filter
% for Highpass use [b,a]=butter(N,wn,high);
enter the passband attenuation:0.4
enter the stop band attenuation:30
enter the pass band frequency:0.6*pi
enter the stop band frequency:0.4*pi
For BandSTOP enter the following after running the same above code
Use [b,a]=butter(N,wn,stop);
% Note the difference: vector of frequencies are provided
enter the passband attenuation:0.2
enter the stop band attenuation:30
enter the pass band frequency:[0.1*pi,0.5*pi]
enter the stop band frequency:[0.2*pi,0.4*pi]
%code
clc;
clear all;
close all;
rp=input ('Enter the pass band attenuation:');
rs=input ('Enter the stop band attenuation:');
wp=input ('Enter the pass band frequency:');
ws=input ('Enter the stop band frequency:');
[N,wn]=cheb1ord(wp/pi,ws/pi,rp,rs);
[b,a]=cheby1(N,rp,wn);
freqz(b,a);
Sample input:
Enter the pass band attenuation:2
Enter the stop band attenuation:80
Enter the pass band frequency:0.3*pi
Enter the stop band frequency:0.4*pi
For Bandstop:use
[N,wn]=cheb1ord(wp/pi,ws/pi,rp,rs); % Chebyshev Type-1
[b,a]=cheby1(N,rp,wn,'stop');
Type-2 Chebyshev Filters
[N,wn]=cheb2ord(wp/pi,ws/pi,rp,rs);
[b,a]=cheby2(N,rp,wn);%Lowpass and Bandpass depending upon wn
%[N,wn]=cheb2ord(wp/pi,ws/pi,rp,rs);
%[b,a]=cheby2(N,rp,wn,'high');%Highpass
[N,wn]=cheb2ord(wp/pi,ws/pi,rp,rs);
[b,a]=cheby2(N,rp,wn,'stop');%Bandstop
Elliptic filters
Finally, for designing an elliptic digital filter, the commands are
[num,den] = ellip(N,Rp,Rs,Wn)
[num,den] = ellip(N,Rp,Rs,Wn,filtertype)
Get the following information using >>fvtool(b,a) then Analysis- Filter information
Procedure: IIR
/*
* main() - Main code routine, initializes BSL and Creates Filter response
* Based on User input
*/
int i,w,wc,c,N;
float H[100];/*Filter Magnitude Array*/
Result:
Enter order of filter 2
Enter the cut off frequency 50
Enter the choice for IIR Filter 1.LPF 2.HPF 2
The Highpass filter coefficients are calculated as follows:
H[0]=0.000000
H[1]=0.000000
H[2]=0.000003
H[3]=0.000013
H[4]=0.000041
H[5]=0.000100
H[6]=0.000207
/*
* Filter Coefficients (C Source) generated by the Filter Design and Analysis Tool
*
* Generated by MATLAB(R) 7.12 and the Signal Processing Toolbox 6.15.
*
* Generated on: 29-Dec-2013 12:45:03
*
*/
/*
* Discrete-Time FIR Filter (real)
* -------------------------------
* Filter Structure : Direct-Form FIR
* Filter Length : 51
* Stable : Yes
* Linear Phase : Yes (Type 1)
*/
/*************************LOW-PASS FILTER COEFFICIENTS****************************/
//4KHz Lowpass filter coefficients
const int low = 41;
const real32_T lowpass[41] = {
0.003413982689, -0.04797660932, -0.01539621036,-0.008595237508,-1.524966956e-005,
0.00999723468, 0.01822434552, 0.02121619135, 0.01687069982, 0.005175150465,
-0.01131861564, -0.02771880478, -0.03797810152, -0.03647312522, -0.01977176033,
0.01220615022, 0.0556156598, 0.1033837795, 0.1466035396, 0.1767215133,
0.1875034124, 0.1767215133, 0.1466035396, 0.1033837795, 0.0556156598,
0.01220615022, -0.01977176033, -0.03647312522, -0.03797810152, -0.02771880478,
-0.01131861564, 0.005175150465, 0.01687069982, 0.02121619135, 0.01822434552,
0.00999723468,-1.524966956e-005,-0.008595237508, -0.01539621036, -0.04797660932,
0.003413982689
};
/***********************************************************************************/
/***********************************************************************************/
/*************************band-PASS FILTER COEFFICIENTS****************************/
//Bandpass filter coefficients
/*******************************************BAND-PASS Filter
coefficients************************/
//[Fstop1 Fpass1 Fpass2 Fstop2 Wstop]=[100 2000 2500 5000 60]
const int band = 51;
const real32_T bandpass[51] = {
0.0009632759611, 0.002002550522, 0.003695710329, 0.00584884733, 0.008191553876,
0.01026241574, 0.01144373138, 0.01104936376, 0.008456530049, 0.003261316568,
-0.004570978228, -0.01459527761, -0.02585300803, -0.03693319112, -0.0461339727,
-0.05171122774, -0.0521716997, -0.04656642303, -0.03472302109, -0.01736706495,
0.003897946095, 0.02676513419, 0.04852762446, 0.06646967679, 0.07827630639,
0.08239423484, 0.07827630639, 0.06646967679, 0.04852762446, 0.02676513419,
0.003897946095, -0.01736706495, -0.03472302109, -0.04656642303, -0.0521716997,
-0.05171122774, -0.0461339727, -0.03693319112, -0.02585300803, -0.01459527761,
-0.004570978228, 0.003261316568, 0.008456530049, 0.01104936376, 0.01144373138,
0.01026241574, 0.008191553876, 0.00584884733, 0.003695710329, 0.002002550522,
0.0009632759611
};
/******************************************************************************************
******/
/*******************************************BAND-STOP Filter
coefficients************************/
//[Fpass1 Fstop1 Fstop22 Fpass2 Wstop] = [100 1000 3500 5000 7]
const int bstop = 51;
const real32_T bandstop[51] = {
0.1176750958, -0.04280536994, -0.02905246243, -0.01399032492, 0.001051147236,
0.01495537348, 0.02547941729, 0.0304671675, 0.02896331251, 0.02110535465,
0.009219906293,-0.002751755528, -0.01036386192, -0.00987265911,0.0001494093158,
0.01788694598, 0.03832666948, 0.05434468761, 0.05854714289, 0.04572274163,
0.01455296483, -0.03134330362, -0.08400481939, -0.1328259408, -0.1673213243,
0.820253551, -0.1673213243, -0.1328259408, -0.08400481939, -0.03134330362,
0.01455296483, 0.04572274163, 0.05854714289, 0.05434468761, 0.03832666948,
0.01788694598,0.0001494093158, -0.00987265911, -0.01036386192,-0.002751755528,
0.009219906293, 0.02110535465, 0.02896331251, 0.0304671675, 0.02547941729,
0.01495537348, 0.001051147236, -0.01399032492, -0.02905246243, -0.04280536994,
0.1176750958
};
/******************************************************************************************
******/
union {
Uint32 combo;
short channel[2];
} temp;
Uint32 Leftchannel,Rightchannel,data;
DSK6713_AIC23_CodecHandle hCodec;
DSK6713_AIC23_Config config=DSK6713_AIC23_DEFAULTCONFIG;
>> c600lib
>>ccsboardinfo
>>ccsdsp
>> ccsboardinfo
>> ticcs
??? Error using ==> compareAndWarnCCSVersions at 53
This version of the Embedded Coder does not support your
version of Code Composer Studio(TM) IDE.
The Code Composer Studio(TM) version supported in this release is 3.3.
Refer to the Embedded Coder data sheet for more information on product requirements.
>>simulink
Find in find tab
6713
Under embedded coder you will see Texas Instruments C6000--------C6713 DSK
Double click on it