Time vector

For each task you are expected to generate a plot for inclusion in a document that you will submit electronically
for this project. Be sure to properly label your figures to receive full credit.

  1. For the continuous-time signal x(t):
    a. Create the signal x(t) in MATLAB using a time vector, t, that has 1024 samples over four
    periods of the signal, beginning at t = 0 seconds. Plot x(t) as subplot(2, 1, 1) of Figure 1.
    b. Plot the magnitude response, |X(e
    jω)|. Generate the magnitude response by applying the DFT
    using N = 4096, i.e., X = abs(fftshift(fft(x, 4096))). Plot this as a function of analog frequency
    to ensure that the sinusoids are at the expected frequencies. This can be accomplished by first
    creating the plot vector for w = linspace(−pi, pi, 4096) and then scaling it by 1
    2π∆t
    , where ∆t
    is the difference between adjacent samples in your continuous-time vector, t, from part a., i.e.,
    dt = t(2) − t(1). Plot the resulting magnitude response as subplot(2, 1, 2) in Figure 1.
  2. Now, we are going to sample x(t) at the specified sampling rate fs and then reconstruct it. To do so:
    a. Define a sample vector of n = 0 : 256. Then, generate x[n] = x(nTs). Plot x[n] as a function of
    n as subplot(3, 1, 1) of Figure 2.
    b. Plot the magnitude response, |X(e
    jω)|. Generate the magnitude response by applying the DFT
    using N = 4096. Plot this as a function of digital frequency in radians/sample from ω = [−π, π].
    Plot the resulting magnitude response as subplot(3, 1, 2) in Figure 2.
    c. Now, reconstruct x(t) from its samples x[n] using the provided reconstruction function, i.e.,
    [xr, tr] = reconstruct(xn, n, fs), where xn are the samples x[n], fs is the sampling rate fs, xr is
    the reconstructed continuous-time signal xr(t), and tr is the corresponding continuous-time time
    vector, tr. Plot the resulting reconstructed signal xr(t) as a function of tr as subplot(3, 1, 3) in
    Figure 2.
  3. Now, we are going to down-sample x[n] by a factor of M = 2 and then reconstruct it. To do so:
    a. Define a sample vector of nds = 0 : length(n)/2. Then, downsample the signal according to
    x ds = xn(1 : 2 : end). Plot xds[n] as a function of nds as subplot(3, 1, 1) of Figure 3.
    b. Plot the magnitude response, |Xds(e
    jω)| for N = 4096 from ω = [−π, π] as subplot(3, 1, 2) in
    Figure 3.
    c. Now, reconstruct xrds (t) from its samples xds[n] using the provided reconstruction function, i.e.,
    [xr ds, tr ds] = reconstruct(xn ds, nds, fs/2). Plot the resulting reconstructed signal xrds (t) as
    a function of trds as subplot(3, 1, 3) in Figure 3.
  4. Now, we are going to up-sample x[n] by a factor of L = 3 and then reconstruct it. To do so:
    a. Define a sample vector of nus = 0 : 3 ∗ length(n) − 1. First, zero-initialize the upsample vector,
    i.e., x us = 0 ∗ nus. Then, upsample the signal according to x us(1 : 3 : end) = xn. Plot xus[n] as
    a function of nus as subplot(3, 1, 1) of Figure 4.
    b. Plot the magnitude response, |Xus(e
    jω)| for N = 4096 from ω = [−π, π] as subplot(3, 1, 2) in
    Figure 4.
    c. Now, reconstruct xrus
    (t) from its samples xus[n] using the provided reconstruction function, i.e.,
    [xr us, tr us] = reconstruct(xn us, nus, 3 ∗ fs). Plot the resulting reconstructed signal xrus
    (t) as
    a function of trus
    as subplot(3, 1, 3) in Figure 4.
  5. Now, we are going to apply a decimation filter to x[n] in order to properly band-limit the signal before
    down-sampling. To do so:
    a. We first define our decimation filter by creating the sample vector m = −25 : 25. Then, we create
    an ideal decimation filter using hde = sinc(m/2). Then, we normalize the filter so that all terms
    sum to 1, i.e., hde = hde./(sum(hde)). Now, we apply the decimation filter via convolution, i.e.,
    x de = conv(xn, hde,
    0 same0
    ), to properly decimate x[n].
    2
    b. We next repeat step 3.a to down-sample the decimated version of x[n]. Plot xde[n] as a function
    of nds as subplot(3, 1, 1) of Figure 5.
    c. Plot the magnitude response, |Xde(e
    jω)| for N = 4096 from ω = [−π, π] as subplot(3, 1, 2) in
    Figure 5.
    d. Now, reconstruct xrde (t) from its samples xde[n] using the provided reconstruction function, i.e.,
    [xr de, tr de] = reconstruct(xn de, nds, fs/2). Plot the resulting reconstructed signal xrde (t) as
    a function of trde as subplot(3, 1, 3) in Figure 5.
  6. Now, we are going to apply an interpolation filter to xus[n] in order to properly filter out all spectral
    replicas from the signal after up-sampling. To do so:
    a. We first define our interpolation filter by creating the sample vector m = −25 : 25. Then, we
    create an ideal interpolation filter using hin = sinc(m/3). Then, we normalize the filter so that all
    terms sum to L = 3, i.e., hin = 3 ∗ hin./(sum(hin)).
    b. We next use the previously up-sampled signal from step 4.a, xus[n]. Then, we apply the interpolation filter via convolution, i.e., x in = conv(xus, hin,
    0 same0
    ), to properly interpolate xus[n]. Plot
    xin[n] as a function of nus as subplot(3, 1, 1) of Figure 6.
    c. Plot the magnitude response, |Xin(e
    jω)| for N = 4096 from ω = [−π, π] as subplot(3, 1, 2) in
    Figure 6.
    d. Now, reconstruct xrin (t) from its samples xin[n] using the provided reconstruction function, i.e.,
    [xr in, tr in] = reconstruct(xn in, nus, 3 ∗ fs). Plot the resulting reconstructed signal xrin (t) as
    a function of trin as subplot(3, 1, 3) in Figure 6.
  7. Finally, we are going to change the sampling rate of our signal by the fractional rate of 2
    3
    .
    a. In this case we need to define our rate-change filter to have a cutoff of π
    max(2,3) . To perform the
    rate-change we first up-sample the signal by a factor of 3 and apply the rate-change filter. Notice
    that this step results in the same interpolated signal as obtained in 6.b. Thus, to finish the rate
    change we simply need to downsample xrin (t) by a factor of 2. Thus, x rc = x in(1 : 2 : end) and
    the sample vector is nrc = 0 : length(x rc) − 1. Plot xrc[n] as a function of nrc as subplot(3, 1, 1)
    of Figure 7.
    c. Plot the magnitude response, |Xrc(e
    jω)| for N = 4096 from ω = [−π, π] as subplot(3, 1, 2) in
    Figure 7.
    d. Now, reconstruct xrrc
    (t) from its samples xrc[n] using the provided reconstruction function,
    i.e., [xr rc, tr rc] = reconstruct(xn rc, nrc,(2/3) ∗ fs). Plot the resulting reconstructed signal
    xrrc
    (t) as a function of trrc
    as subplot(3, 1, 3) in Figure 7.