You are on page 1of 4

Jordan University of Science and Technology

Faculty of Engineering Electrical Engineering Department

Lab.1. Tutorial

1. Sampling a Signal in MATLAB

This section expands the discussion on the statement in the Lab Manual (Lab.1):
Generate 1024 samples of 1kHz sinusoidal (cos) signal sampled at 8kHz with the command:
n=(0:1023);X=cos(2*n*pi*1000/8000);

In fact, to sample a signal in MATLAB, generate a time vector at the appropriate rate, and use
this to generate the signal. Plot using the stem function. For example:

% Sample the sinusoid x = sin(2 pi f t), where f = 1 kHz.


% Let x1 be the signal sampled at 10 kHz.
% Let x2 be the signal sampled at 3 kHz.

f = 1000;
T = 1/f;
tmin = 0;
tmax = 5*T; % Plots 5 cycles
dt1 = 1/10000;
dt2 = 1/3000;
t1 = tmin:dt1:tmax;
t2 = tmin:dt2:tmax;
x1 = sin(2*pi*f*t1);
x2 = sin(2*pi*f*t2);
subplot(211)
stem(t1,x1);
subplot(212)
stem(t2,x2);

Dr Hazem Al_Otum Lab Handouts – Lab.1 EE462-Digital Communications Lab 1


Jordan University of Science and Technology
Faculty of Engineering Electrical Engineering Department

It is useful to plot the continuous time signal on the same plot (but after sampling and
reconstruction). All signals in MATLAB are discrete-time, but they will look like continuous-
time signals if the sampling rate is much higher than the Nyquist rate:

f = 1000;
T = 1/f;
tmin = 0;
tmax = 5*T;
dt = T/100;
dt1 = 1/10000;
dt2 = 1/3000;
t = tmin:dt:tmax;
t1 = tmin:dt1:tmax;
t2 = tmin:dt2:tmax;
x = sin(2*pi*f*t);
x1 = sin(2*pi*f*t1);
x2 = sin(2*pi*f*t2);
subplot(211)
plot(t1,x1,'r');
hold on
stem(t1,x1);
subplot(212)
plot(t2,x2,'r');
hold on
stem(t2,x2);

Dr Hazem Al_Otum Lab Handouts – Lab.1 EE462-Digital Communications Lab 2


Jordan University of Science and Technology
Faculty of Engineering Electrical Engineering Department

1. General Specifications of Filters

Since the frequency response of a digital filter is always periodic in the frequency domain with
a period of 2π, the design specifications need only be specified for one period; usually, over the
frequency region [-π , + π ]. Furthermore, when the frequency response is conjugate-symmetric
(i.e., D*(ω)=D(-ω), then it is sufficient to specify the response only on the positive frequency
interval [0, π] The conjugate-symmetric case is the most common, because it corresponds to
filters with real coefficients.

Fig. Ideal Filters

Causal filters cannot have a band of frequencies with zero response. Nor can they have an
infinitely sharp transition between the passband and the stopband. Nor can they have perfectly
flat passband. So a typical realistic magnitude response looks like what is shown in Fig.

Fig. Real Filter Example

Useful Example Using FDAtool in MATLAB:

The FDAtool in MATALB provides a very useful tool for filter design and analysis. Go to
MATLAB, open FDAtool, then, select Lowpass and Equiripple as shown in Fig. below Specify
Dr Hazem Al_Otum Lab Handouts – Lab.1 EE462-Digital Communications Lab 3
Jordan University of Science and Technology
Faculty of Engineering Electrical Engineering Department

the order of the filter, the sampling frequency of the system for which the filter is to be used, the
upper frequency (where the pass band ends), and the stop frequency (where the stop band starts), as
shown in figure blow: Note: It may be useful to specify the order as N-1 where N is the number of
coefficients that the filter will have. Chosen below is a filter of order 128 -1 = 127, with 128
coefficients.

Once, done, hit the design filter button to get the filter. As is seen in figure 4 below, the filter
has been generated and the response has been plotted.

Dr Hazem Al_Otum Lab Handouts – Lab.1 EE462-Digital Communications Lab 4

You might also like