'Callback', @(~,~) sound (audioLinear, Fs)); % Plot spline interpolation ax5 subplot(6, 1, 5, 'Parent', fig); plot (ax5, interpolatedTime, audioSpline, 'm'); title(ax5, 'Spline Interpolation'); xlabel(ax5, 'Time (s)'); ylabel(ax5, 'Amplitude'); % Button for spline interpolation uicontrol('style', 'pushbutton', 'String', 'Play Spline', 'Units', 'normalized', ... 'Position', [0.88, 0.27, 0.1, 0.05], ... % Right of the fifth subplot 'Callback', @(~,~) sound (audioSpline, Fs)); %Plot PCHIP interpolation ax6 subplot(6, 1, 6, 'Parent', fig); plot (ax6, interpolatedTime, audioPCHIP, 'c'); title (ax6, 'PCHIP Interpolation'); xlabel(ax6, 'Time (s)'); ylabel(ax6, 'Amplitude'); % Button for PCHIP interpolation uicontrol('style', 'pushbutton', 'String', 'Play PCHIP', 'Units', 'normalized', ... 'Position', [0.88, 0.12, 0.1, 0.05], ... % Right of the sixth subplot 'Callback', @(~,~) sound (audioPCHIP, Fs)); disp('GUI is ready. Use the buttons to play audio signals.'); run. Question 1. Do you notice any differences in the interpolation results? Please summarize your observations in this Question 2. What will happen if you change the downsampleFactor from 10 to 20? Please use your own language to explain why this is the case. Question 3. What will happen if you change the downsampleFactor from 10 to 2? Please use your own language to explain why this is the case. % interpolationDemo.m % This script records a 3-second audio segment, performs downsampling, % interpolates the signal using four methods, and provides a GUI with buttons % next to corresponding subplots for playback. % % Record a 3-second audio signal (high quality) %--- Fs = 44100; nBits = 16; nChannels = 1; recObj audiorecorder (Fs, nBits, nChannels); disp('Please start speaking. Three seconds of audio will be recorded...'); recordblocking (recObj, 3); disp('End of Recording. '); audioData getaudiodata (recObj); originalTime % (0:length(audioData)-1) Fs; % Time axis for the original signal % Downsample the audio signal to simulate data loss downsampleFactor = 10; downsampledData = audioData(1: downsampleFactor: end); Fs_down Fs/downsampleFactor; % Define downsampling factor % Keep every 4th sample % New sampling frequency downsampledTime = (0:length(downsampled Data)-1)/ Fs_down; % Time axis for the downsampled signal disp('Downsampling completed.'); % % Interpolate the downsampled signal % interpolatedTime = originalTime; % Use the original time vector for interpolation % Nearest neighbor audioNearest interp1 (downsampledTime, downsampled Data, interpolatedTime, 'nearest', 'extrap'); % Linear interpolation audioLinear interp1 (downsampled Time, downsampled Data, interpolatedTime, 'linear', 'extrap'); % Spline interpolation audioSpline interp1(downsampledTime, downsampledData, interpolatedTime, 'spline', 'extrap'); % PCHIP interpolation audioPCHIP = interp1(downsampledTime, downsampledData, interpolatedTime, 'pchip', 'extrap'); disp('Interpolation completed.'); % * Create GUI for playback and visualization % fig = figure('Name', 'Audio Playback GUI', 'Position', [100, 100, 800, 700]); set(fig, 'Units', 'normalized'); % Set the figure to normalized units %Plot original signal ax1 subplot(6, 1, 1, 'Parent', fig); plot(ax1, originalTime, audioData, 'k'); title(axl, 'Original Signal'); xlabel(ax1, 'Time (s)'); ylabel(ax1, 'Amplitude'); % Button for original signal uicontrol('Style', 'pushbutton', 'String', 'Play Original', ... 'Units', 'normalized', ... Position', [0.88, 0.87, 0.1, 0.05], % Right of the first subplot 'Callback', @(~,~) sound (audioData, Fs)); % Plot downsampled signal ax2 = subplot(6, 1, 2, 'Parent', fig); stem(ax2, downsampled Time, downsampledData, 'r'); title(ax2, 'Downsampled Signal'); xlabel(ax2, 'Time (s)'); ylabel(ax2, 'Amplitude'); % Button for downsampled signal uicontrol('Style', 'pushbutton', 'String', 'Play Downsampled',. 'Units', 'normalized', 'Position', [0.88, 0.72, 0.1, 0.05], ... % Right of the second subplot 'Callback', @(~,~) sound(downsampledData, Fs_down)); * Plot nearest neighbor interpolation ax3 = subplot(6, 1, 3, 'Parent', fig); plot(ax3, interpolatedTime, audioNearest, 'g'); title(ax3, 'Nearest Neighbor Interpolation'); xlabel(ax3, 'Time (s)'); ylabel(ax3, 'Amplitude'); % Button for nearest neighbor interpolation uicontrol('Style', 'pushbutton', 'String', 'Play Nearest', ... 'Units', 'normalized', ... Position', [0.88, 0.57, 0.10, 0.05], ... % Right of the third subplot 'Callback', @(~,~) sound(audioNearest, Fs)); % Plot linear interpolation ax4 = subplot(6, 1, 4, 'Parent', fig); plot(ax4, interpolatedTime, audioLinear, 'b'); title(ax4, 'Linear Interpolation'); xlabel(ax4, 'Time (s)'); ylabel(ax4, 'Amplitude'); % Button for linear interpolation uicontrol('Style', 'pushbutton', 'String', 'Play Linear', . 'Units', 'normalized', ... 'Position', [0.88, 0.42, 0.1, 0.05], ... Right of the fourth subplot
'Callback', @(~,~) sound (audioLinear, Fs)); % Plot spline interpolation ax5 subplot(6, 1, 5, 'Parent', fig); plot (ax5, interpolatedTime, audioSpline, 'm'); title(ax5, 'Spline Interpolation'); xlabel(ax5, 'Time (s)'); ylabel(ax5, 'Amplitude'); % Button for spline interpolation uicontrol('style', 'pushbutton', 'String', 'Play Spline', 'Units', 'normalized', ... 'Position', [0.88, 0.27, 0.1, 0.05], ... % Right of the fifth subplot 'Callback', @(~,~) sound (audioSpline, Fs)); %Plot PCHIP interpolation ax6 subplot(6, 1, 6, 'Parent', fig); plot (ax6, interpolatedTime, audioPCHIP, 'c'); title (ax6, 'PCHIP Interpolation'); xlabel(ax6, 'Time (s)'); ylabel(ax6, 'Amplitude'); % Button for PCHIP interpolation uicontrol('style', 'pushbutton', 'String', 'Play PCHIP', 'Units', 'normalized', ... 'Position', [0.88, 0.12, 0.1, 0.05], ... % Right of the sixth subplot 'Callback', @(~,~) sound (audioPCHIP, Fs)); disp('GUI is ready. Use the buttons to play audio signals.'); run. Question 1. Do you notice any differences in the interpolation results? Please summarize your observations in this Question 2. What will happen if you change the downsampleFactor from 10 to 20? Please use your own language to explain why this is the case. Question 3. What will happen if you change the downsampleFactor from 10 to 2? Please use your own language to explain why this is the case. % interpolationDemo.m % This script records a 3-second audio segment, performs downsampling, % interpolates the signal using four methods, and provides a GUI with buttons % next to corresponding subplots for playback. % % Record a 3-second audio signal (high quality) %--- Fs = 44100; nBits = 16; nChannels = 1; recObj audiorecorder (Fs, nBits, nChannels); disp('Please start speaking. Three seconds of audio will be recorded...'); recordblocking (recObj, 3); disp('End of Recording. '); audioData getaudiodata (recObj); originalTime % (0:length(audioData)-1) Fs; % Time axis for the original signal % Downsample the audio signal to simulate data loss downsampleFactor = 10; downsampledData = audioData(1: downsampleFactor: end); Fs_down Fs/downsampleFactor; % Define downsampling factor % Keep every 4th sample % New sampling frequency downsampledTime = (0:length(downsampled Data)-1)/ Fs_down; % Time axis for the downsampled signal disp('Downsampling completed.'); % % Interpolate the downsampled signal % interpolatedTime = originalTime; % Use the original time vector for interpolation % Nearest neighbor audioNearest interp1 (downsampledTime, downsampled Data, interpolatedTime, 'nearest', 'extrap'); % Linear interpolation audioLinear interp1 (downsampled Time, downsampled Data, interpolatedTime, 'linear', 'extrap'); % Spline interpolation audioSpline interp1(downsampledTime, downsampledData, interpolatedTime, 'spline', 'extrap'); % PCHIP interpolation audioPCHIP = interp1(downsampledTime, downsampledData, interpolatedTime, 'pchip', 'extrap'); disp('Interpolation completed.'); % * Create GUI for playback and visualization % fig = figure('Name', 'Audio Playback GUI', 'Position', [100, 100, 800, 700]); set(fig, 'Units', 'normalized'); % Set the figure to normalized units %Plot original signal ax1 subplot(6, 1, 1, 'Parent', fig); plot(ax1, originalTime, audioData, 'k'); title(axl, 'Original Signal'); xlabel(ax1, 'Time (s)'); ylabel(ax1, 'Amplitude'); % Button for original signal uicontrol('Style', 'pushbutton', 'String', 'Play Original', ... 'Units', 'normalized', ... Position', [0.88, 0.87, 0.1, 0.05], % Right of the first subplot 'Callback', @(~,~) sound (audioData, Fs)); % Plot downsampled signal ax2 = subplot(6, 1, 2, 'Parent', fig); stem(ax2, downsampled Time, downsampledData, 'r'); title(ax2, 'Downsampled Signal'); xlabel(ax2, 'Time (s)'); ylabel(ax2, 'Amplitude'); % Button for downsampled signal uicontrol('Style', 'pushbutton', 'String', 'Play Downsampled',. 'Units', 'normalized', 'Position', [0.88, 0.72, 0.1, 0.05], ... % Right of the second subplot 'Callback', @(~,~) sound(downsampledData, Fs_down)); * Plot nearest neighbor interpolation ax3 = subplot(6, 1, 3, 'Parent', fig); plot(ax3, interpolatedTime, audioNearest, 'g'); title(ax3, 'Nearest Neighbor Interpolation'); xlabel(ax3, 'Time (s)'); ylabel(ax3, 'Amplitude'); % Button for nearest neighbor interpolation uicontrol('Style', 'pushbutton', 'String', 'Play Nearest', ... 'Units', 'normalized', ... Position', [0.88, 0.57, 0.10, 0.05], ... % Right of the third subplot 'Callback', @(~,~) sound(audioNearest, Fs)); % Plot linear interpolation ax4 = subplot(6, 1, 4, 'Parent', fig); plot(ax4, interpolatedTime, audioLinear, 'b'); title(ax4, 'Linear Interpolation'); xlabel(ax4, 'Time (s)'); ylabel(ax4, 'Amplitude'); % Button for linear interpolation uicontrol('Style', 'pushbutton', 'String', 'Play Linear', . 'Units', 'normalized', ... 'Position', [0.88, 0.42, 0.1, 0.05], ... Right of the fourth subplot
Programming Logic & Design Comprehensive
9th Edition
ISBN:9781337669405
Author:FARRELL
Publisher:FARRELL
Chapter12: Event-driven Gui Programming, Multithreading, And Animation
Section: Chapter Questions
Problem 2FTB
Related questions
Question
Solve the 3 questions using MATLAB code & show your work on how pretty please
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 2 steps
Recommended textbooks for you
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Np Ms Office 365/Excel 2016 I Ntermed
Computer Science
ISBN:
9781337508841
Author:
Carey
Publisher:
Cengage
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Np Ms Office 365/Excel 2016 I Ntermed
Computer Science
ISBN:
9781337508841
Author:
Carey
Publisher:
Cengage