DSP 05
DSP 05
Nishat Jahan
2002012
a Department
of Electrical and Electronics Engineering,
CUET, Chattogram, 4349, Bangladesh
Abstract
Frequency domain analysis of discrete-time (DT) signals and systems provides
essential insights into their behavior under various transformations. This anal-
ysis utilizes Fourier transforms to represent signals in the frequency domain,
revealing critical characteristics such as magnitude and phase spectra. Convo-
lution, a fundamental operation in signal processing, demonstrates significant
effects on the frequency domain representation, emphasizing the relationship
between time-domain operations and their spectral consequences. The study
explores the properties of DT systems, including linearity and time invariance,
and their influence on frequency responses. It also examines the role of sampling
and aliasing in shaping the spectral content of signals. The analysis underscores
the importance of frequency response in evaluating and designing systems for
specific applications, ensuring optimal performance. Practical examples comple-
ment theoretical discussions, offering a clear understanding of frequency domain
principles in DT signal processing. This comprehensive approach supports both
the analysis and design of efficient signal processing systems.
Keywords: Frequency domain, discrete-time signals, Fourier transform,
convolution, time invariance, frequency response, sampling, aliasing, spectral
analysis, MATLAB
1. Objective
2. Introduction
The analysis of discrete-time signals and systems in the frequency domain plays
a vital role in digital signal processing (DSP). Understanding and applying
the Discrete-Time Fourier Series (DTFS), Discrete-Time Fourier Transform
(DTFT), and Discrete Fourier Transform (DFT) are essential for representing
and analyzing discrete-time signals and their frequency-domain characteristics.
These methods facilitate the decomposition of signals into spectral components,
revealing important insights into their frequency behavior.
The Discrete-Time Fourier Series (DTFS) represents periodic discrete-
time signals x[n] with period N as a summation of complex exponentials. The
The distribution of signal power across frequencies is obtained from the Power
Density Spectrum (PDS), given by:
Pk = |Ck |2 , k = 0, 1, . . . , N − 1
The Discrete-Time Fourier Transform (DTFT) generalizes the DTFS to
aperiodic signals, producing a continuous spectrum. It is defined as:
∞
X
X(ω) = x[n]e−jωn , ω ∈ [−π, π]
n=−∞
3. Lab Work
2
3.1.1. MATLAB Code
1 Fs = 100 e3 ; % Sampling frequency
2 T = 1e -3; % Period
3 D = 0.1; % Duty cycle
4 PW = D * T ; % Pulse width
5 t = -T /2 : 1/ Fs : T /2; % Time vector
6 x = ( mod (t , T ) < PW ) ; % Rectangular pulse train
7 % DTFS coefficients
8 N = length ( x ) ;
9 c = zeros (1 , N ) ;
10 for k = 1: N
11 c ( k ) = sum ( x .* exp ( -1 j * 2 * pi * (k -1) * t / T ) ) / N ;
12 end
13 % Recons truction
14 x_recon = zeros ( size ( x ) ) ;
15 for n = 1: N
16 x_recon = x_recon + c ( n ) * exp (1 j * 2 * pi * (n -1) * t / T ) ;
17 end
18 % Plotting Original and Reconstructed Signals
19 figure ;
20 subplot (2 , 1 , 1) ;
21 plot (t , x , ’ LineWidth ’ , 1.5) ;
22 title ( ’ Original ␣ Signal ␣ ( Rectangular ␣ Pulse ␣ Train ) ’) ;
23 xlabel ( ’ Time ␣ ( s ) ’) ;
24 ylabel ( ’ Amplitude ’) ;
25 grid on ;
26 subplot (2 , 1 , 2) ;
27 plot (t , real ( x_recon ) , ’ LineWidth ’ , 1.5) ; % Real part of
reconstructed signal
28 title ([ ’ Reconstructed ␣ Signal ␣ using ␣ ’ , num2str ( N ) , ’␣ Fourier ␣
Coefficients ’ ]) ;
29 xlabel ( ’ Time ␣ ( s ) ’) ;
30 ylabel ( ’ Amplitude ’) ;
31 grid on
32 % Fourier Coefficient Magnitudes
33 figure ;
34 stem (0: N -1 , abs ( c ) , ’ filled ’ , ’ LineWidth ’ , 1.5) ;
35 title ( ’ Fourier ␣ Coefficients ␣ Magnitude ’) ;
36 xlabel ( ’ Harmonic ␣ Index ␣ ( k ) ’) ;
37 ylabel ( ’| c_k | ’) ;
38 grid on ;
3
‘fft()‘ function is utilized to calculate the spectrum of the signal efficiently. The
magnitude and phase response of the spectrum are then plotted to provide a
clear visualization of the signal’s behavior in the frequency domain.
4
3.3. Part C: DFT Analysis
A sinusoidal signal x[n] = sin(2πf0 nTs ) is generated. The DFT is computed
using MATLAB’s ‘fft()‘ to analyze the spectrum. Zero-padding is applied to
improve frequency resolution. The signal is then reconstructed using the inverse
DFT and compared to the original.
5
3.3.2. Plotted Graph
Figure 4: Original sinusoidal signal, Magnitude and Phase Spectrum of the DFT
Signal.
6
4. Post-Lab Questions
1. How does the duty cycle of the pulse train affect its frequency
spectrum?
7
Figure 7: Frequency Spectrum with Figure 8: Original VS Reconstructed
Varying Duty cycles. Signal with Varying Duty cycles.
2. What is the relationship between the length of DFT and the fre-
quency resolution?
Solution : The frequency resolution of the Discrete Fourier Transform (DFT)
is determined by the relationship:
Fs
∆f =
N
where:
• Fs is the sampling frequency, and
• N is the length of the DFT (number of points).
This means that the frequency resolution is inversely proportional to the
length of the DFT. As N increases, the frequency resolution improves, allowing
the DFT to distinguish closely spaced frequency components more effectively.
Conversely, a smaller N results in a coarser frequency spectrum, making it
harder to resolve fine frequency details.
1 % Parameters
8
2 Fs = 1000; % Sampling frequency ( Hz )
3 T = 1; % Duration of the signal ( s )
4 t = 0:1/ Fs :T -1/ Fs ; % Time vector
5 f1 = 50; % Frequency of the first sine wave ( Hz )
6 f2 = 60; % Frequency of the second sine wave ( Hz )
7
8 % Signal with two closely spaced frequencies
9 x = sin (2* pi * f1 * t ) + sin (2* pi * f2 * t ) ;
10
11 % DFT lengths
12 N_values = [256 , 512 , 1024]; % Different DFT lengths
13
14 % Plot original signal
15 figure ;
16 plot (t , x , ’ LineWidth ’ , 1.5) ;
17 title ( ’ Original ␣ Signal ’) ;
18 xlabel ( ’ Time ␣ ( s ) ’) ;
19 ylabel ( ’ Amplitude ’) ;
20 grid on ;
21
22 % Frequency analysis with different DFT lengths
23 figure ;
24 for i = 1: length ( N_values )
25 N = N_values ( i ) ; % Current DFT length
26 X = fft (x , N ) ; % Compute DFT with zero - padding to length N
27 freq = linspace (0 , Fs , N ) ; % Frequency vector
28
29 % Plot magnitude spectrum
30 subplot ( length ( N_values ) , 1 , i ) ;
31 plot ( freq , abs ( X ) , ’ LineWidth ’ , 1.5) ;
32 title ([ ’ Magnitude ␣ Spectrum , ␣ DFT ␣ Length ␣ N ␣ = ␣ ’ , num2str ( N ) ]) ;
33 xlabel ( ’ Frequency ␣ ( Hz ) ’) ;
34 ylabel ( ’ Magnitude ’) ;
35 grid on ;
36
37 % Display frequency resolution
38 delta_f = Fs / N ; % Frequency resolution
39 text (0.7* Fs , max ( abs ( X ) ) /2 , [ ’\ Deltaf ␣ = ␣ ’ , num2str ( delta_f , ’
%.2 f ’) , ’␣ Hz ’] , ...
40 ’ FontSize ’ , 12 , ’ B ac kg r ou nd Co l or ’ , ’ white ’) ;
41 end
This figure demonstrates how the resolution of the Discrete Fourier Transform
(DFT) affects the spectrum of a signal by comparing three cases with different
DFT lengths: N = 256, N = 512, and N = 1024. The frequency resolution,
denoted by ∆f , is inversely proportional to the DFT length and is calculated
as
fs
∆f = ,
N
9
where fs is the sampling frequency. For N = 256, the resolution is ∆f = 3.91 Hz,
which results in a less detailed spectrum with broader peaks. As the DFT
length increases to N = 512 (∆f = 1.95 Hz), the peaks in the spectrum become
narrower, providing greater clarity. Finally, for N = 1024 (∆f = 0.98 Hz), the
resolution is highest, producing sharp, well-defined peaks that allow for precise
identification of frequency components.
The improvement in resolution as N increases enables the spectrum to represent
the signal more accurately. At lower resolutions (smaller N ), closely spaced fre-
quencies appear merged, and the spectrum lacks detail. In contrast, at higher
resolutions (larger N ), the spectrum reveals finer details, with closely spaced
frequencies clearly distinguishable. This highlights the importance of selecting
an appropriate DFT length to achieve the desired frequency resolution for ana-
lyzing a signal’s spectral characteristics.
3. Compare the results obtained from DTFT and DFT for the same
signal.
Solution : Here’s the Comparison between the outputs obtained from DTFT
and DFT -
Frequency Resolution:
The DTFT provides infinitely fine resolution, offering a continuous frequency
spectrum, while the DFT is limited by ∆f = Fs /N . Zero-padding improves the
DFT’s resolution, making it approximate the DTFT more closely.
Spectral Leakage :
The DTFT avoids spectral leakage due to its exact representation of the signal.
The DFT may suffer from leakage when frequencies do not align with its bins,
but this can be mitigated using zero-padding or windowing.
Computational Efficiency :
The DTFT is computationally expensive as it evaluates a continuous spectrum,
while the DFT, especially with FFT, is efficient and suitable for digital appli-
cations.
Reconstruction :
The DFT can reconstruct the original signal using the inverse DFT (‘ifft‘) with
high accuracy, while the DTFT theoretically enables perfect reconstruction for
infinite-length signals.
4. How does zero-padding influence the spectrum?
Solution : Zero-padding adds extra zeros to a signal or its Fourier transform,
increasing the resolution of the frequency spectrum without changing the signal’s
actual content. It provides a finer frequency resolution, making the spectrum
appear smoother and more continuous, but it doesn’t introduce new frequencies.
While it helps in visualizing small details and improving the appearance of the
spectrum, zero-padding doesn’t alter the fundamental frequency components
of the signal. It essentially fills in the gaps between existing points, offering
better interpolation for easier interpretation, especially when combined with
windowing functions.
1 % Parameters
2 Fs = 1000; % Sampling frequency ( Hz )
3 Ts = 1 / Fs ; % Sampling period ( s )
4 N = 64; % Original number of samples
5 f0 = 50; % Frequency of the sinusoidal signal ( Hz )
6
7 % Time vector and signal generation
8 n = 0: N -1; % Sample indices
9 t = n * Ts ; % Time vector ( s )
10 x = sin (2 * pi * f0 * t ) ; % Sinusoidal signal
11
10
12 % Compute DFT without zero - padding
13 X = fft ( x ) ; % Compute FFT
14 freq_original = (0: N -1) * ( Fs / N ) ; % Frequency vector for original
signal
15
16 % Zero - padding
17 ZP = 256; % Length after zero - padding
18 x_padded = [x , zeros (1 , ZP - N ) ]; % Append zeros
19 X_padded = fft ( x_padded ) ; % Compute FFT with zero - padding
20 freq_padded = (0: ZP -1) * ( Fs / ZP ) ; % Frequency vector for zero -
padded signal
21
22 % Plot the results
23 figure ;
24
25 % Original spectrum ( without zero - padding )
26 subplot (2 , 1 , 1) ;
27 stem ( freq_original , abs ( X ) , ’b ’ , ’ LineWidth ’ , 1.5 , ’ DisplayName ’ , ’
Original ␣ Spectrum ’) ;
28 title ( ’ Spectrum ␣ Without ␣ Zero - Padding ’) ;
29 xlabel ( ’ Frequency ␣ ( Hz ) ’) ;
30 ylabel ( ’ Magnitude ’) ;
31 grid on ;
32
33 % Spectrum with zero - padding
34 subplot (2 , 1 , 2) ;
35 plot ( freq_padded , abs ( X_padded ) , ’r ’ , ’ LineWidth ’ , 1.5 , ’
DisplayName ’ , ’ Zero - Padded ␣ Spectrum ’) ;
36 title ( ’ Spectrum ␣ With ␣ Zero - Padding ’) ;
37 xlabel ( ’ Frequency ␣ ( Hz ) ’) ;
38 ylabel ( ’ Magnitude ’) ;
39 grid on ;
40
41 % Add legends
42 legend ( ’ show ’) ;
43
44 % Explanation
45 disp ( ’ Notice ␣ how ␣ zero - padding ␣ improves ␣ the ␣ apparent ␣ frequency ␣
resolution , ␣ making ␣ the ␣ spectrum ␣ smoother ␣ and ␣ more ␣ detailed . ’) ;
11
This plot illustrates the effect of zero-padding on the frequency spectrum. In
the top plot, without zero-padding, the frequency resolution is limited by the
number of samples (N = 64), resulting in a discrete and less smooth spectrum.
The frequency bins are sparse, making it harder to pinpoint the exact frequency
of components. In contrast, the bottom plot, with zero-padding (ZP = 256),
shows a smoother and more continuous spectrum due to the increased frequency
bins. While zero-padding does not add new frequency content, it interpolates
the existing spectrum, improving the apparent resolution and making the peaks,
such as the one at 50 Hz, sharper and more distinct. This enhances the clarity
and interpretability of the spectrum.
5. DISCUSSION
References
12
Nishat Jahan
Student ID : 2002012
Student
13