Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
for
Use the link below to download the design files for the exercises:
http://www.altera.com/customertraining/ILT/DSPBA_QII_v_10_0.zip
Exercises
2
Copyright 2010 Altera Corporation
A-MNL-DSPBA-EX-10-0-v1
Exercises
Theoretical Background:
The objective of a communication system is to transport data between two or more points. At the
transmitter, the message bearing signal is usually superimposed on the carrier signal before the
actual transmission can occur. This is usually achieved by adjusting the characteristics (e.g.
amplitude, frequency, phase, or a combination of thereof) of the carrier wave. The process is
known as modulation. The signal is then transmitted over a noisy channel (to model after natural
interferences). Finally, at the receiver, the received signal is demodulated and the original
message bearing signal is recovered. The quality of the recovered message signal is affected by
the various factors (e.g. the amount of noise that exists in the channel).
Double-sideband (DSB) Modulation
The simplest modulation and demodulation scheme, which is also the topic of todays lab, is DSB
modulation and demodulation. In DSB modulation, the message signal is directly mixed together
with the carrier waveform; the resultant signal is transmitted directly without further modification.
More specifically, in DSB modulation, the transmitted signal, xc(t) is defined as follow:
-W
The carrier sinusoid (assuming c = 0) and the modulated signal, xc(t), have the following
frequency spectra:
|Cw(f)|
|Xc(f)|
-fc
fc
-fc
fc
Noisy Channel
The modulator is usually the last component of the transmitter. The modulated signal, xc(t), is
then transmitted through some sort of channel, during which the signal is usually corrupted by
some sort of interferences. Typically, some sort of additive noise, n(t), is used to model this signal
degradation. More specifically, the received signal, xr(t), can be represented as:
xr (t ) = xc (t ) + n(t )
In order to keep the calculation simple, the noisy channel is often modeled as additive white
Gaussian noise. Additive Rayleigh fading noise is often used to model a more realistic channel
condition. Here, we limit our discussion to additive white Gaussian noise.
3
Copyright 2010 Altera Corporation
A-MNL-DSPBA-EX-10-0-v1
Exercises
Pre-detection
Band Pass
Filter
xr(t)
e2(t)
e3(t)
Post-detection
Low Pass
Filter
yD(t)
2 cos(2f c t + c )
The first part of the DSB demodulator is the pre-detection linear band pass filter. The filter is used
to filter out the unwanted noise, which was introduced by the noisy channel. Then the filtered
signal, e2(t), is mixed with the same carrier sinusoid (different amplitude is permitted). After the
mixer, which is nothing more than a multiplier, a post-detection liner low pass filter is used to
isolate the desired message signal. The frequency spectra of the two filters and the intermediate
signals along the way are shown below:
|HBPF (f)|
|E2(f)|
2W
2W
-fc
fc
2W
2W
-fc
fc
|E3 (f)|
|HLPF(f)|
f
-2fc
-W
2fc
f
-W
From the above frequency spectra, we notice that the DSB modulation and demodulation scheme
only works if the following is true (otherwise, the signals get corrupted by aliasing):
2 fc W W fc W
Note: Linear phase FIR filters are often used in DSB demodulator as the exact phase information
needs to be preserved throughout the demodulator.
4
Copyright 2010 Altera Corporation
A-MNL-DSPBA-EX-10-0-v1
Exercises
Design Specifications:
You will build a two-channel DSB demodulator throughout the exercises today. The block
diagram of the DSB demodulator is shown below:
e2_f
x_r_f
HPF
Scaler
LPF1
pre_hfir
yd_f
yd
e3_f
Scaler
pre_lfir
Sync
e1
e1_f
e2
Scaler
Pre-detection BPF
LPF2
Scaler
pst_lfir
NCO
e3
Post-detection LPF
5
Copyright 2010 Altera Corporation
A-MNL-DSPBA-EX-10-0-v1
Exercises
6
Copyright 2010 Altera Corporation
A-MNL-DSPBA-EX-10-0-v1
Exercises
Exercise 1
7
Copyright 2010 Altera Corporation
A-MNL-DSPBA-EX-10-0-v1
Exercises
8
Copyright 2010 Altera Corporation
A-MNL-DSPBA-EX-10-0-v1
Exercises
Design:
Use blocks from the DSP Builder Advanced blockset to implement the DSB demodulator. The
instructions are outlined in this section.
9
Copyright 2010 Altera Corporation
A-MNL-DSPBA-EX-10-0-v1
Exercises
Step 1 Examine the Channel and Wire Structure of the DSB Demodulator
It is important to analyze the algorithm and understand how the channel and wire structure should
look before actual implementation can take place. Therefore, in this section, you will try to predict
the channel and wire structure throughout your DSB demodulator and verify the structure in your
MATLAB model.
1) Given the system clock rate, sample rate and channel count (see below), calculate the
channel and wire structure at all stages of the DSB demodulator:
System Clock Rate = Sample Rate
Channel Count
=2
Period (TDM Factor)
Channel Wire Count
Chan Cycle Count
2) Given the period, channel wire count and channel cycle count, please draw out the
wire/channel structure (add additional data wires if you need to):
clk
valid
channel
data
wire
The following sub-steps will help determine the validity of your wire/channel structure.
3) Open MATLAB, if it is not already opened. In the Current Directory window, set the path to
<exercise_install_directory>\Ex1\.
4) Open up lab_testbench.m. Take a moment to observe the MATLAB test bench. In this test
bench, MATLAB functions have been wrapped inside the interface that DSP Builder
Advanced Blockset expects. Ask your instructor if you need help understanding the test
bench.
5) Comment out lines 141 154 (if they have not been commented out already).
6) Make sure the MATLAB equivalent code is not commented out (lines 101 133).
7) Disable the sw_clip (line 5) and enable us_manual (line 9) flags and run the test bench.
10
Copyright 2010 Altera Corporation
A-MNL-DSPBA-EX-10-0-v1
Exercises
8) Type the following commands in the MATLAB command prompt to plot the generated
channel, and valid signals:
>>
>>
>>
>>
>>
figure;
subplot(211)
plot(xr_c.signals.values);title('channel');
subplot(212)
plot(xr_v.signals.values);title('valid');
This figure should match the channel/valid signals that you predicted in sub-step 2.
11
Copyright 2010 Altera Corporation
A-MNL-DSPBA-EX-10-0-v1
Exercises
Blockset requires, you are ready to build the hardware in Simulink using Altera s DSP Builder
Advanced Blockset. In the interest of time, the majority of the blocks have been connected for
you. The instructions to completing the design are outlined below.
1) Click on the Simulink button
4) From the Base Block library in the Altera DSP Builder Advanced Blockset, add Control,
Signals and Run Quartus II blocks to lab_dsbdm.mdl. (To add a block to the Simulink
model, simply drag and drop the block from the Simulink library browser to the model).
5) Double click on the Control block and configure it as follows:
Control
Hardware Destination Directory:
./rtl
Note: During the lab, only change the field specified by the lab instructions.
12
Copyright 2010 Altera Corporation
A-MNL-DSPBA-EX-10-0-v1
Exercises
clk
ClockRate
7) From the Sources library in the Simulink blockset, click and drag one From Workspace
block into lab_dsbdm.mdl. Duplicate the From Workspace block two more time to create
From Workspace1 and From Workspace2 blocks. Configure the three blocks as follows:
From Workspace:
Data:
Sample time:
xr_d
SampleTime
From Workspace1:
Data:
Sample time:
xr_v
SampleTime
13
Copyright 2010 Altera Corporation
A-MNL-DSPBA-EX-10-0-v1
Exercises
From Workspace2:
Data:
Sample time:
xr_c
SampleTime
8) From the Sink library in the Simulink blockset, click and drag one To Workspace block into
lab_dsbdm.mdl. Duplicate the To Workspace block two more time to create To
Workspace1 and To Workspace2 blocks. Configure the three blocks as follows:
To Workspace:
Data:
fy_d
To Workspace1:
Data:
fy_v
14
Exercises
To Workspace2:
Data:
9)
fy_c
From the Signal Attributes library in the Simulink blockset, click and drag one Data Type
Conversion block into lab_dsbdm.mdl. Duplicate the Data Type Conversion block two
more time to create Data Type Conversion1 and Data Type Conversion2 blocks. Configure
the three blocks as follows:
Data Type Conversion:
Output data type:
boolean
15
Copyright 2010 Altera Corporation
A-MNL-DSPBA-EX-10-0-v1
Exercises
uint8
fixdt(1,16,11)
button, right next to the output data
following for Data Type Assistant:
Fixed point
Signed
Binary point
16
11
16
Copyright 2010 Altera Corporation
A-MNL-DSPBA-EX-10-0-v1
Exercises
Stratix II Device
Auto
-3
17
Copyright 2010 Altera Corporation
A-MNL-DSPBA-EX-10-0-v1
Exercises
The Device block marks the DSB_Demod_Chip subsystem as the top level of the FPGA
design. All blocks in the subsystem below this level of hierarchy, become part of the RTL
design. All blocks above this level of hierarchy become part of test bench.
Now that you are done with the DSB_Demod_Chip subsystem, you are ready to start
building the DSB demodulator.
As shown in the system diagram (Figure 1 exercise 1), the DSB demodulator can be
separated into the following component:
-
Pre-detection BPF, which is built using the cascade of a high-pass and a low-pass
FIR filters.
NCO, which is used to generate the carrier sinusoids that we need to demodulate our
signals
A synchronizer, which is used to ensure data from the pre-detection BPF and the
NCO do indeed line up.
A multiplier that is used as a mixer
A post-detection LPF, which is used to isolate the demodulated signal
Scalers are placed throughout the demodulator to limit the bit-growths and thus,
making hardware implementation of the demodulator feasible
All the components, other than the customized synchronizer-and-mix block, NCO and postdetection LPF are created using ready-made ModelIP cores from DSP Bulder Advanced
Blockset and have been connected for you already. You will have instantiate the NCO and
post-detection LPF cores manually and build the customized synchronizer-and-mix block
using ModelPrim blocks from DSP Builder Advanced Blockset. Detail instructions to
completing the demodulator are listed below:
18
Copyright 2010 Altera Corporation
A-MNL-DSPBA-EX-10-0-v1
Exercises
13) Double-click on the DSB_Demod subsystem block to open up the subsystem. You should
see the following:
14) Replace the Post Detection LPF Placeholder with one instance of SingleRateFIR block from
the Filters library in the Altera DSP Builder Advanced Blockset. Name and configure the
instance of SingleRateFIR block as follows:
PostDetectionLPF
Parameter GUI (simply double-click on the block):
Input Rate per Channel:
SampleRate
Number of Channels:
ChanCount
Coefficients:
fi(pst_lfir,1,w_fir,f_fir)
Base Address:
PST_LFIR_COEFS
Block Annotation tab in Block Properties GUI (right click -> block properties):
Enter text and token:
Added Latency: %<latency>
19
Copyright 2010 Altera Corporation
A-MNL-DSPBA-EX-10-0-v1
Exercises
15) Replace the NCO Placeholder with one instance of NCO block from the Waveform
Synthesis library in the Altera DSP Builder Advanced Blockset. Name and configure the
instance of NCO block as follows:
NCO
Parameter GUI (simply double-click on the block):
Output Rate Per Channel:
Output Data Type:
Output scaling value:
Accumulator Bit Width:
Phase Increment and Inversion:
Phase Increment and Inversion Memory Map:
SampleRate
sfix(w_nco)
2^-f_nco
24
f_fs*2^24
NCO_PHASE_INCR
Block Annotation tab in Block Properties GUI (right click -> block properties):
Enter text and token:
Added Latency: %<latency>
Before the output of the pre-detection BPF can be mixed together with the carrier sinusoid
waves, you must make sure the two signals are aligned. (The Scale and NCO blocks have
different latencies, as noted by the annotation on the bottom). The most straight-forward way
to accomplish this is by simply delaying the Scale signals.
The aforementioned approach, although simple, is not the optimal approach; the delays
would be different with a different set of configurations (e.g. scaling factors). Rather than
delaying the signal, you will design a synchronizer that would work with different
configurations (e.g. different number of channels). Detailed instructions to completing the
customized synchronizer-and-mix block are listed below:
20
Copyright 2010 Altera Corporation
A-MNL-DSPBA-EX-10-0-v1
Exercises
Scheduled
18) From the ModelPrim library in the Altera DSP Builder Advanced Blockset, add an
instance of ChannelIn block to Sync_Mix subsystem. Configure the ChannelIn block as
follows:
ChannelIn
Number of data signals:
21
Copyright 2010 Altera Corporation
A-MNL-DSPBA-EX-10-0-v1
Exercises
19) From the ModelPrim library in the Altera DSP Builder Advanced Blockset, add an
instance of ChannelOut block to Sync_Mix subsystem. Configure the ChannelOut block as
follows:
ChannelOut
Number of data signals:
20) From the ModelPrim library in the Altera DSP Builder Advanced Blockset, add one
instance of Mult block to Sync_Mix subsystem, named Mult.
21) From the ModelPrim library in the Altera DSP Builder Advanced Blockset, add one
instance of DualMem block to Sync_Mix subsystem and configures as follows:
DualMem
Output data type mode:
Initial contents:
Use DONT CARE:
22
Copyright 2010 Altera Corporation
A-MNL-DSPBA-EX-10-0-v1
Exercises
22) From the Sink library in the Simulink Blockset, add one instance of Terminator block to
Sync_Mix subsystem.
23) Connect the blocks in Sync_Mux subsystem together in the following fashion:
-
Your DSB_Demod subsystem should look like the following (minus the annotation):
Note that this subsystem dynamically matches the NCO data stream with the data stream of the
pre-detection filter. The goal is to align the channel signals. This is achieved by storing NCO data
to a memory, and using the FIRs channel to read that data.
23
Copyright 2010 Altera Corporation
A-MNL-DSPBA-EX-10-0-v1
Exercises
24
Copyright 2010 Altera Corporation
A-MNL-DSPBA-EX-10-0-v1
Exercises
11) Close the lab_dsbm.mdl model. In the MATLAB testbench, lab_testbench.m, disable the
us_manual flag and enable the sw_clip flag. Re-run the MATLAB testbench.
With the us_manual flag on, the testbench will automatically open the lab_dsbm.mdl model and
simulate the model. Once the simulation is done, the model is closed automatically.
12) Next type the following in the MATLAB command prompt:
>> wavplay(f_data',fs);
What do you hear?
Summary Exercise 1
From this exercise, you have practiced:
-
25
Copyright 2010 Altera Corporation
A-MNL-DSPBA-EX-10-0-v1
Exercises
26
Copyright 2010 Altera Corporation
A-MNL-DSPBA-EX-10-0-v1
Exercises
Exercise 2
2A Device Selection and Performance Verification
(Optional) 2B Design Exploration Hardware Multiplier
Trade-Offs
27
Copyright 2010 Altera Corporation
A-MNL-DSPBA-EX-10-0-v1
Exercises
28
Copyright 2010 Altera Corporation
A-MNL-DSPBA-EX-10-0-v1
Exercises
b. Click into the DSB_Demod_Chip subsystem. Double click on the Device block.
Once the Block Parameter GUI is opened, change the following:
29
Copyright 2010 Altera Corporation
A-MNL-DSPBA-EX-10-0-v1
Exercises
Note: Given that Cyclone III device was chosen for your DSB demodulator project and
that the system clock has a 200MHz requirement. You can determine what speed grade
you should choose (even before you settle on a specific Cyclone III device). From the
Cyclone III embedded multiplier specification (shown below), you can determine that a
speed grade of 7 is needed to meet the 200MHz system clock requirement.
10) Double click on the Analysis & Synthesis task to perform the analysis and synthesis portion
of the compilation. This step would yield an approximate logic usage count for the DSB
30
Copyright 2010 Altera Corporation
A-MNL-DSPBA-EX-10-0-v1
Exercises
demodulator. Notice the progress bar right next to the Analysis & Synthesis task. Upon
completion, the task will turn green and a green check mark will appear right next to it.
12) Expand the Analysis & Synthesis folder and click on Summary. This will show you the
approximate resource count.
Exercises
overview table (shown below), estimate what Cyclone III device would fit the resource
requirement of the DSB demodulator:
15) From the estimated total pin requirement and from the Cyclone III device package and
maximum user I/O data sheet (table shown below), you can determine the specific device
you should choose for your design. For this lab, we will use the Cyclone III EP3C40F324C7
device.
16) Close Quartus II. Now go back to the Simulink model, lab_dsbm.mdl, and enter
EP3C40F324C7 as our targeted device.
17) Save and re-simulate lab_dsbm.mdl. This will regenerate optimized HDL codes, targeting
our specific Cyclone III device.
18) Once the simulation is done, double-click on the Run Quartus II icon to bring up the Quartus
II project.
32
Copyright 2010 Altera Corporation
A-MNL-DSPBA-EX-10-0-v1
Exercises
19) In Quartus II development tool, double click the Fitter (Place & Route) task under the Tasks
pane; the compiler will automatically run the analysis & synthesis and the place & route
portions of the compilation process.
20) Once the Fitter task is done, expand the Fitter folder and highlight Summary. Compare the
Fitter Summary report to the Analysis & Synthesis Summary report, which you copied
down earlier. Notice while the two correlate, they do not match. This is expected as the
resource summary from Analysis & Synthesis is merely an estimate.
21) Expand the Resource Section Folder (under the Fitter folder) and click on Resource
Utilization by Entity. As the report name indicates, you will be able to see the resource
utilization by all the entities in your design.
22) Notice how all the nodes are expanded in the compilation hierarchy node section. For our
benefit, collapse everything below the third node hierarchy.
23) From the Fitter Resource Utilization by Entity report, complete the following table:
Entity
Memory
Bits
M9K
DSP
18x18
Pins
LUTonly
LCs
RegisterOnly
LCs
LUT/
Register
LCs
NCO
PreDetectionHPF
PreDetectionLPF
PostDetectionLPF
Sync_Mix
Note: When applicable, copy the numbers outside the parentheses only; they indicate the total
number of resources of the given type used by the specific entity and all its sub-entities.
24) In Quartus II development tool, double click the TimeQuest Timing Analysis task under the
Tasks pane; the compiler will automatically perform static timing analysis on the design.
25) Expand the Slow 1200mV 85C Model folder and the Slow 1200 mV 0C Model folder (both
under the TimeQuest Timing Analyzer folder) and click on Fmax Summary for both.
Record the slower one in the table in step 27.
26) Collapse the Slow 1200mV 85C Model and the Slow 1200mV 0C Model folders. Click on
Multicorner Timing Analysis Summary. Complete the following table.
33
Copyright 2010 Altera Corporation
A-MNL-DSPBA-EX-10-0-v1
Exercises
Fmax (MHz)
Summary
From this exercise, you have practiced:
-
Verifying the hardware resource and timing performance using compilation results
34
Copyright 2010 Altera Corporation
A-MNL-DSPBA-EX-10-0-v1
Exercises
Memory
Bits
M9K
DSP
18x18
Pins
LUTonly
LCs
RegisterOnly
LCs
LUT/
Register
LCs
NCO
PreDetectionHPF
PreDetectionLPF
PostDetectionLPF
Sync_Mix
Note: Compare the resource utilization results to the ones obtained in exercise 3A. You
should notice that besides the three filters, everything else (with 16 bits resolutions) was built
out of logic cells. Hardware Multiplier Threshold can be used to limit the number of
hardware multipliers and thereby, saving multiplier resources.
Keep in mind that in hardware design, there is always a trade-off that you need to consider.
In this case, hardware multipliers can run at higher speed than soft logic cell based
multipliers. Hence, you should also check whether your design is still meeting timing or not.
6) Use the information from the TimeQuest Timing Analyzer section of the compilation report
to complete the following table:
Fmax (MHz)
35
Copyright 2010 Altera Corporation
A-MNL-DSPBA-EX-10-0-v1
Exercises
Note: Here you should see that you are no longer meeting the 200MHz Fmax requirement
and that you have a negative worst-case setup slack. Typically, you have several choices
here. You can:
-
Rather than debugging timing closure and re-architecting our DSB demodulator, we will
simply revert back the Hardware Multiplier Threshold to the default value of -1.
From the Control block, you can also influence how the memories are implemented in your
design, (similar to how you can influence your multiplier implementation).
7) Close Quartus II development tool window.
8) Inside the Simulink DSB demodulator model, lab_dsbm.mdl, change the Hardware
Multiplier Threshold back to default setting, -1.
9) Save and simulate the model. Upon completion of the simulation, close the model.
36
Copyright 2010 Altera Corporation
A-MNL-DSPBA-EX-10-0-v1