0% found this document useful (0 votes)
5 views15 pages

DSP Lab 5

This lab report examines upsampling and downsampling techniques for digital audio signals, focusing on converting music excerpts for high-quality streaming and low-bandwidth transmission. The implementation in MATLAB includes filtering techniques to preserve signal quality, with analyses of time-domain and frequency-domain characteristics. Key findings highlight the importance of filter design and the trade-offs between audio quality and practical constraints in real-world applications.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views15 pages

DSP Lab 5

This lab report examines upsampling and downsampling techniques for digital audio signals, focusing on converting music excerpts for high-quality streaming and low-bandwidth transmission. The implementation in MATLAB includes filtering techniques to preserve signal quality, with analyses of time-domain and frequency-domain characteristics. Key findings highlight the importance of filter design and the trade-offs between audio quality and practical constraints in real-world applications.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

Digital Signal Processing Lab Report

Lab 5: Music Sampling Rate Conversion

Abstract
This lab report explores the concepts of upsampling and downsampling ap-
plied to digital audio signals. The report investigates the process of converting a
music excerpt between different sampling rates for high-quality streaming and low-
bandwidth transmission applications. We implement both upsampling (increasing
the sampling rate) and downsampling (decreasing the sampling rate) operations
in MATLAB, applying appropriate filtering techniques to maintain signal quality.
The analysis includes time-domain and frequency-domain visualizations, along with
discussions on practical considerations for real-world applications.

Contents

1 Introduction 3

2 Theoretical Background 3
2.1 Sampling and Nyquist Theorem . . . . . . . . . . . . . . . . . . . . . . . 3
2.2 Upsampling Process . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2.3 Downsampling Process . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

3 Question 1: Upsampling a Music Excerpt for High-Quality Streaming 4


3.1 Music File Acquisition & Exploration . . . . . . . . . . . . . . . . . . . . 4
3.2 Upsampling Implementation . . . . . . . . . . . . . . . . . . . . . . . . . 5
3.3 Interpolation Filter Design . . . . . . . . . . . . . . . . . . . . . . . . . . 5
3.4 Time-Domain & Frequency-Domain Analysis . . . . . . . . . . . . . . . . 6
3.5 Discussion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

4 Question 2: Downsampling a Music Excerpt for Low-Bandwidth Trans-


mission 8
4.1 Bandwidth Constraints & Downsampling Factor . . . . . . . . . . . . . . 8
4.2 Anti-Aliasing Filter Design . . . . . . . . . . . . . . . . . . . . . . . . . . 8
4.3 MATLAB Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . 9
4.4 Time-Domain & Subjective Analysis . . . . . . . . . . . . . . . . . . . . 9
4.5 Real-World Considerations . . . . . . . . . . . . . . . . . . . . . . . . . . 11

5 Conclusion 11

1
Your Name DSP Lab 5

6 Appendix 12
6.1 MATLAB Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
6.2 Audio Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
6.3 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15

2
Your Name DSP Lab 5

1 Introduction
This lab focuses on the implementation and analysis of sampling rate conversion tech-
niques for digital audio signals. Sampling rate conversion is a fundamental operation in
digital signal processing, particularly in audio applications where different systems may
operate at various sampling rates. The lab explores two main scenarios:

1. Upsampling for High-Quality Streaming: Converting a low sample rate audio


signal to a higher sample rate for improved streaming quality.

2. Downsampling for Low-Bandwidth Transmission: Reducing the sampling


rate of an audio signal to meet bandwidth constraints while maintaining essential
music content.

Through these exercises, we gain practical experience with rate conversion algorithms,
digital filtering, and the impact of sampling rate on audio quality. The implementations
are carried out in MATLAB, allowing for both theoretical analysis and auditory evalua-
tion.

2 Theoretical Background
2.1 Sampling and Nyquist Theorem
Digital audio signals are created by sampling continuous audio waveforms at discrete time
intervals. The Nyquist-Shannon sampling theorem states that to perfectly reconstruct
a continuous bandlimited signal, the sampling rate must be at least twice the highest
frequency present in the signal. For audio signals, which typically contain frequencies up
to 20 kHz (the upper limit of human hearing), standard CD-quality audio uses a 44.1
kHz sampling rate.

2.2 Upsampling Process


Upsampling increases the sampling rate of a digital signal by inserting new samples
between the original ones. The process involves:

1. Zero insertion: Placing zeros between original samples to create a higher-rate


signal.

2. Interpolation filtering: Applying a low-pass filter to smooth the signal and re-
move spectral images introduced by zero insertion.

The mathematical expression for upsampling by a factor of L is:


(
x[n/L], if n is a multiple of L
yup [n] = (1)
0, otherwise

3
Your Name DSP Lab 5

2.3 Downsampling Process


Downsampling reduces the sampling rate by keeping only every M th sample, where M is
the downsampling factor. The process requires:
1. Anti-aliasing filtering: Applying a low-pass filter before downsampling to prevent
aliasing.
2. Sample reduction: Keeping only every M th sample from the filtered signal.
The mathematical expression for downsampling by a factor of M after applying an
anti-aliasing filter h[n] is:
ydown [n] = (x ∗ h)[nM ] (2)
where ∗ denotes convolution.

3 Question 1: Upsampling a Music Excerpt for High-


Quality Streaming
3.1 Music File Acquisition & Exploration
For this experiment, I selected a music excerpt from [describe your music selection]. The
original file had the following characteristics:
• Original sampling rate: 22.05 kHz
• Duration: 12 seconds
• Content description: [Describe the musical content, instruments, vocals, etc.]
The time-domain waveform of the original music excerpt is shown in Figure 1.

Figure 1: Time-domain waveform of the original music excerpt

4
Your Name DSP Lab 5

3.2 Upsampling Implementation


I chose an upsampling factor of 2 to convert the original sampling rate of 22.05 kHz to
44.1 kHz. This factor is suitable because:
• 44.1 kHz is the standard CD-quality audio sampling rate
• It allows for representation of frequencies up to 22.05 kHz, which covers the entire
range of human hearing
• It is a common sampling rate used in high-quality audio streaming platforms
The upsampling process was implemented in MATLAB using the following steps:
1. Zero insertion: Inserting zeros between each original sample
2. Designing a low-pass interpolation filter
3. Applying the filter to the zero-inserted signal
4. Scaling the result by the upsampling factor to maintain energy

3.3 Interpolation Filter Design


A low-pass FIR filter was designed to remove the spectral images introduced by zero
insertion. The filter specifications were:
• Filter order: 100
• Normalized cutoff frequency: 1
L
= 0.5 (where L = 2 is the upsampling factor)
• Filter type: FIR with linear phase
The magnitude response of the interpolation filter is shown in Figure 2.

Figure 2: Magnitude response of the interpolation filter

5
Your Name DSP Lab 5

The cutoff frequency was chosen to be at half the new Nyquist frequency (around
11.025 kHz) to preserve the entire frequency content of the original signal while suppress-
ing the spectral images.

3.4 Time-Domain & Frequency-Domain Analysis


Figure 3 shows the time-domain waveform of the upsampled signal. Note that the time
axis now corresponds to the new sampling rate of 44.1 kHz.

Figure 3: Time-domain waveform of the upsampled music excerpt

A frequency-domain comparison of the original and upsampled signals is presented in


Figure 4.

6
Your Name DSP Lab 5

Figure 4: Frequency spectra comparison between original and upsampled signals

3.5 Discussion
Upon listening to both the original and upsampled audio files, the following observations
were made:

• Audible differences: [Describe any audible differences you noticed]

• Quality assessment: [Evaluate the quality difference between original and up-
sampled]

In a real-world streaming platform context, several factors need consideration:

• Computational cost: The upsampling process requires significant computational


resources, especially for the filtering operation. For a streaming platform serving
millions of users, this could represent substantial processing overhead.

• Memory usage: Higher sampling rates require more memory for both storage and
processing.

• Quality vs. file size trade-off: While upsampling does not add new frequency
information beyond what was in the original recording, it may improve playback
quality on certain systems. However, this comes at the cost of approximately dou-
bling the file size.

• Target audience considerations: For casual listeners using basic headphones or


speakers, the benefits of higher sampling rates may be imperceptible, making the
increased bandwidth unnecessary.

7
Your Name DSP Lab 5

4 Question 2: Downsampling a Music Excerpt for


Low-Bandwidth Transmission
4.1 Bandwidth Constraints & Downsampling Factor
For the low-bandwidth transmission scenario, I identified the maximum allowable sam-
pling rate as 11.025 kHz. Based on the original sampling rate of 44.1 kHz (or whatever
your original rate was), a downsampling factor of 4 was chosen.
This factor was selected because:

• It reduces the original sampling rate of 44.1 kHz to approximately 11.025 kHz

• This meets the bandwidth constraints of the low-bandwidth channel

• It still preserves frequencies up to approximately 5.5 kHz, which is sufficient for


speech intelligibility and basic musical content

4.2 Anti-Aliasing Filter Design


To prevent aliasing during downsampling, a low-pass filter was designed and applied
before reducing the sample rate. The filter specifications were:

• Filter order: 100

• Cutoff frequency: 4.96 kHz (90% of the new Nyquist frequency of 5.5125 kHz)

• Normalized cutoff: 0.225 (relative to the original sampling rate)

• Filter type: FIR with linear phase

The magnitude response of the anti-aliasing filter is shown in Figure 5.

8
Your Name DSP Lab 5

Figure 5: Magnitude response of the anti-aliasing filter with the new Nyquist frequency
marked

The cutoff frequency was set slightly below the new Nyquist frequency to ensure
effective suppression of frequency components that could cause aliasing. This conservative
approach ensures cleaner audio at the expense of slightly reduced high-frequency content.

4.3 MATLAB Implementation


The downsampling process was implemented in MATLAB with the following steps:

1. Designing and applying the anti-aliasing filter to the original signal

2. Selecting every M th sample from the filtered signal, where M = 4 is the downsam-
pling factor

4.4 Time-Domain & Subjective Analysis


Figure 6 shows a comparison of the time-domain waveforms between the original and
downsampled signals.

9
Your Name DSP Lab 5

Figure 6: Comparison of original and downsampled signal waveforms

A frequency-domain comparison is presented in Figure 7.

Figure 7: Frequency spectra comparison between original and downsampled signals

Upon listening to the downsampled audio, the following observations were made re-
garding perceived quality:

• Overall quality: [Describe the overall perceived quality]

10
Your Name DSP Lab 5

• Effect on specific instruments/vocals: [Describe which elements were most


affected]

• Audible artifacts: [Describe any artifacts like aliasing or loss of clarity]

4.5 Real-World Considerations


For low-bandwidth transmission scenarios, several practical considerations emerge:

• Content adaptation: Different types of audio content (speech vs. music) have
different minimum quality requirements. Speech may remain intelligible at lower
sampling rates compared to music.

• Adaptive sampling rates: Modern streaming platforms often implement adap-


tive quality based on available bandwidth. During congestion, sampling rates might
be dynamically reduced.

• Psychoacoustic coding: In practice, low-bandwidth audio transmission often


combines downsampling with psychoacoustic compression techniques (like MP3) to
achieve better perceived quality at lower bit rates.

• Application context: For applications like telephony or voice messages, the down-
sampled quality might be perfectly adequate, while for music appreciation, it rep-
resents a significant compromise.

5 Conclusion
This lab provided practical experience with sampling rate conversion techniques for dig-
ital audio signals. Through the implementation of both upsampling and downsampling
processes, we gained insights into the theoretical and practical aspects of these operations.
Key findings from the lab include:

• Upsampling can prepare audio for high-quality playback systems but does not add
information beyond what was present in the original signal.

• Proper filter design is crucial for both upsampling (interpolation) and downsampling
(anti-aliasing) operations to maintain signal integrity.

• Downsampling inevitably results in loss of high-frequency content but can be im-


plemented strategically to maintain acceptable quality for specific applications.

• Real-world applications must balance technical quality with practical constraints


such as bandwidth, computational resources, and user requirements.

These concepts and techniques are fundamental to digital audio processing systems,
including streaming platforms, telecommunications, and multimedia applications.

11
Your Name DSP Lab 5

6 Appendix
6.1 MATLAB Code
Below is the MATLAB code implementation for both the upsampling and downsampling
operations:
1 % DSP Spring 2025 - Lab 5 Implementation
2 % Music Sampling Rate Conversion ( Upsampling and Downsampling )
3
4 % % Question 1: Upsampling a Music Excerpt for High - Quality Streaming
5
6 % 1. Music File Acquisition & Exploration
7 fprintf ( ’ Question 1: Upsampling Music for High - Quality Streaming \ n ’) ;
8 fprintf ( ’ = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = \ n \ n ’) ;
9
10 % Load the audio file - replace with your file path
11 [ y_orig , Fs_orig ] = audioread ( ’ sample_music . wav ’) ;
12

13 % If stereo , convert to mono for simplicity


14 if size ( y_orig , 2) > 1
15 y_orig = mean ( y_orig , 2) ;
16 fprintf ( ’ Converted stereo to mono \ n ’) ;
17 end
18

19 % Extract a 10 -15 second clip if the file is longer


20 duration_sec = 12; % desired clip duration
21 samples_to_keep = min ( duration_sec * Fs_orig , length ( y_orig ) ) ;
22 y_orig = y_orig (1: samples_to_keep ) ;
23
24 % Display original file info
25 fprintf ( ’ Original sampling rate : % d Hz \ n ’ , Fs_orig ) ;
26 fprintf ( ’ Original clip duration : %.2 f seconds \ n ’ , length ( y_orig ) /
Fs_orig ) ;
27
28 % Plot the time - domain waveform
29 t_orig = (0: length ( y_orig ) -1) / Fs_orig ;
30 figure (1) ;
31 plot ( t_orig , y_orig ) ;
32 title ( ’ Original Music Waveform ’) ;
33 xlabel ( ’ Time ( seconds ) ’) ;
34 ylabel ( ’ Amplitude ’) ;
35 grid on ;
36
37 % 2. Upsampling Process
38 % Choose upsampling factor ( e . g . , 2 for 22.05 kHz to 44.1 kHz )
39 ups ampling_fact or = 2;
40 Fs_upsampled = Fs_orig * up sampli ng_fac tor ;
41

42 fprintf ( ’\ nUpsampling by a factor of % d \ n ’ , u psampl ing_fa ctor ) ;


43 fprintf ( ’ New sampling rate : % d Hz \ n ’ , Fs_upsampled ) ;
44
45 % Implement upsampling using zero - insertion
46 y_zeros = zeros ( length ( y_orig ) * upsampling_factor , 1) ;
47 y_zeros (1: u psampl ing_fa ctor : end ) = y_orig ;
48
49 % 3. Filtering & Analysis
50 % Design a low - pass filter for interpolation

12
Your Name DSP Lab 5

51 cutoff_norm = 1/ upsa mpling _facto r ; % Normalized cutoff ( relative to


new Fs )
52 filter_order = 100; % Filter order
53
54 % Create a low - pass FIR filter
55 b = fir1 ( filter_order , cutoff_norm ) ;
56

57 % Plot filter frequency response


58 figure (2) ;
59 [h , w ] = freqz (b , 1 , 1024) ;
60 plot ( w / pi * Fs_upsampled /2 , 20* log10 ( abs ( h ) ) ) ;
61 title ( ’ Interpolation Filter Magnitude Response ’) ;
62 xlabel ( ’ Frequency ( Hz ) ’) ;
63 ylabel ( ’ Magnitude ( dB ) ’) ;
64 grid on ;
65
66 % Apply the filter and scale by upsampling factor to maintain energy
67 y_upsampled = upsa mpling _facto r * filter (b , 1 , y_zeros ) ;
68

69 % Plot time - domain waveform of upsampled signal


70 t_upsampled = (0: length ( y_upsampled ) -1) / Fs_upsampled ;
71 figure (3) ;
72 plot ( t_upsampled , y_upsampled ) ;
73 title ( ’ Upsampled Music Waveform ’) ;
74 xlabel ( ’ Time ( seconds ) ’) ;
75 ylabel ( ’ Amplitude ’) ;
76 grid on ;
77
78 % Frequency domain analysis
79 NFFT_orig = 2^ nextpow2 ( length ( y_orig ) ) ;
80 Y_orig = fft ( y_orig , NFFT_orig ) ;
81 f_orig = Fs_orig /2 * linspace (0 , 1 , NFFT_orig /2+1) ;
82
83 NFFT_up = 2^ nextpow2 ( length ( y_upsampled ) ) ;
84 Y_up = fft ( y_upsampled , NFFT_up ) ;
85 f_up = Fs_upsampled /2 * linspace (0 , 1 , NFFT_up /2+1) ;
86

87 figure (4) ;
88 subplot (2 ,1 ,1) ;
89 plot ( f_orig , 2* abs ( Y_orig (1: NFFT_orig /2+1) ) / length ( y_orig ) ) ;
90 title ( ’ Original Signal Spectrum ’) ;
91 xlabel ( ’ Frequency ( Hz ) ’) ;
92 ylabel ( ’ Magnitude ’) ;
93 grid on ;
94
95 subplot (2 ,1 ,2) ;
96 plot ( f_up , 2* abs ( Y_up (1: NFFT_up /2+1) ) / length ( y_upsampled ) ) ;
97 title ( ’ Upsampled Signal Spectrum ’) ;
98 xlabel ( ’ Frequency ( Hz ) ’) ;
99 ylabel ( ’ Magnitude ’) ;
100 grid on ;
101
102 % Save upsampled audio
103 audiowrite ( ’ upsampled_music . wav ’ , y_upsampled , Fs_upsampled ) ;
104

105 % % Question 2: Downsampling a Music Excerpt for Low - Bandwidth


Transmission
106

13
Your Name DSP Lab 5

107 fprintf ( ’ Question 2: Downsampling Music for Low - Bandwidth Transmission \


n ’) ;
108 fprintf ( ’ = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = \ n \ n
’) ;
109
110 % For this example , we ’ ll use the original audio again
111 % Assume we have a maximum allowable sampling rate
112 max_allowed_rate = 11025; % 11.025 kHz , common for low bandwidth
113
114 % 1. Determine downsampling factor
115 d ow n s am p l i ng _ f ac t o r = floor ( Fs_orig / max_allowed_rate ) ;
116 new_Fs = Fs_orig / d ow n s am p l in g _ fa c t or ;
117

118 fprintf ( ’ Original sampling rate : % d Hz \ n ’ , Fs_orig ) ;


119 fprintf ( ’ Maximum allowed rate : % d Hz \ n ’ , max_allowed_rate ) ;
120 fprintf ( ’ Chosen downsampling factor : % d \ n ’ , d o wn s a mp l i ng _ f ac t o r ) ;
121 fprintf ( ’ New sampling rate after downsampling : % d Hz \ n ’ , new_Fs ) ;
122
123 % 2. Anti - aliasing filter design
124 % Cutoff should be slightly less than the new Nyquist frequency
125 nyquist_new = new_Fs / 2;
126 cutoff_freq = 0.9 * nyquist_new ; % 90% of new Nyquist to ensure good
filtering
127 cutoff_norm = cutoff_freq / ( Fs_orig /2) ; % Normalized to [0 ,1]
128

129 % Design anti - aliasing filter


130 filter_order = 100; % Higher order for steeper roll - off
131 b_anti_alias = fir1 ( filter_order , cutoff_norm ) ;
132
133 % Plot filter frequency response
134 figure (5) ;
135 [ h_aa , w_aa ] = freqz ( b_anti_alias , 1 , 1024) ;
136 plot ( w_aa / pi * Fs_orig /2 , 20* log10 ( abs ( h_aa ) ) ) ;
137 title ( ’ Anti - aliasing Filter Magnitude Response ’) ;
138 xlabel ( ’ Frequency ( Hz ) ’) ;
139 ylabel ( ’ Magnitude ( dB ) ’) ;
140 grid on ;
141 hold on ;
142 % Plot vertical line at the new Nyquist frequency
143 xline ( nyquist_new , ’ --r ’ , [ ’ New Nyquist : ’ num2str ( nyquist_new ) ’ Hz ’ ])
;
144 hold off ;
145

146 % 3. Apply anti - aliasing filter


147 y_filtered = filter ( b_anti_alias , 1 , y_orig ) ;
148
149 % Downsample the filtered signal
150 y_downsampled = y_filtered (1: d o w ns a m pl i n g_ f a ct o r : end ) ;
151

152 % Save downsampled audio


153 audiowrite ( ’ downs ampled _music . wav ’ , y_downsampled , new_Fs ) ;
Listing 1: MATLAB implementation for upsampling and downsampling

6.2 Audio Files


The following audio files were created during this lab:

14
Your Name DSP Lab 5

• Original: sample music.wav (22.05 kHz)

• Upsampled: upsampled music.wav (44.1 kHz)

• Downsampled: downsampled music.wav (11.025 kHz)

6.3 References
1. Smith, J. O. (2007). Mathematics of the Discrete Fourier Transform (DFT). W3K
Publishing.

2. Oppenheim, A. V., & Schafer, R. W. (2014). Discrete-time signal processing (3rd


ed.). Pearson.

3. Harris, F. J. (1978). On the use of windows for harmonic analysis with the discrete
Fourier transform. Proceedings of the IEEE, 66(1), 51-83.

4. Proakis, J. G., & Manolakis, D. G. (2006). Digital Signal Processing (4th ed.).
Pearson.

5. Mitra, S. K. (2010). Digital Signal Processing: A Computer-Based Approach (4th


ed.). McGraw-Hill.

15

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy