Hello, can you please help me with this MATLAB script, especially with the code
ID: 2293336 • Letter: H
Question
Hello, can you please help me with this MATLAB script, especially with the code and the commands. I have no idea what to do. Please, do NOT use any code involving FFT. This must literally use the .wav files given in the instructions and follow the instructions given in the comments; otherwise, it's of no use. (It's actually very simple--if you know what you're doing--which I don't. lol) Thank you so much!
Convolution reverb in audio processing. For this assignment, take the short recording of an opera singer in a sound-proof room (singing.wav file) and see how it would sound if recorded at the Milan Opera House, St. Nicolas Church, and the Grand Canyon. Use the following impulse responses from each place. Download the sound file “singing.wav” for the opera singer, as well as the impulse responses, “ScalaMilanOperaHall.wav”, “StNicolasChurch.wav” and “GrandCanyon.wav.” Submit the Matlab plots for each scenario/location (three in total – opera house, church, and Grand Canyon). On each plot there should be three subplots: the song as the first subplot, the impulse response as the second output, and the convoluted song as the third plot. The impulse response of a system/venue/environment is recorded while a pseudo audio impulse is played, such as a loud clap or any loud short bang. The impulse responses of the Milan Opera Hall and St Nicolas Church are downloaded from http://www.voxengo.com/files/impulses/ Their file names are: ScalaMilanOperaHall.wav and StNicolasChurc.wav. The impulse responses of the Grand Canyon is downloaded from http://eleceng.dit.ie/dorran/matlab/impulse_responses/ Its file name is: GrandCanyon.wav
close all; clear all;
% make sure all .wav files are in the same directory of this script
% all audio files are sampled at 44100Hz
% import, plot and play singing recording
[song, fs] = audioread('singing.wav'); % import the song
t = [1:length(song)]/fs; % change from index number to time
subplot(3, 1, 1) % first plot of the three plots in the plot window
plot(t, song) % plot the song
xlabel('t (second)')
ylabel('Relative signal strength')
title('Song')
soundsc(song, fs) % play the song
pause % need to press spacebar to continue the progam to listen to next tone
% USE the code segment above as an example
% now import, plot and play the impulse response
subplot(3, 1, 2)
% CONVOLUTE the audio with the system impulse responses
% using the command conv(sig1, sig2)
% the convolution could take a couple of seconds to complete
% plot and play the output,
% it should sounds as if it was actually recorded in those spaces subplot(3, 1, 3)
Explanation / Answer
Don’t worry, I’ll try my best to explain it. Consider the following code
[song, fs] = audioread('singing.wav');
It reads data from the file named ‘singing.wav’, and returns sampled data, in variable ‘song’, and a sample rate for that data, in variable ‘fs’
t = [1:length(song)]/fs;
Since you have a song sampled at 44.1 KHz, then for a 1 second audio clip you will have 44100 samples in the clip. To plot it with x-axis as time you need another variable‘t’ (time) which can be formulated as above. As an example, let us say, the audio clip is sampled at 3 Hz. So in 2 second audio clip, there would be 6 samples.
Song: 12.4 33.6 10 23 5 10
Now when you will plot this, you will get 6 values, and someone can mistakenly think that the song is of about 6 seconds and each second has some value.
When we use this formula t = [1:length(song)]/fs;
Actually this happens t =[1 2 3 4 5 6]/3
t = [0.33 0.66 1 1.33 1.66 2]
now if you label the above plot with these values than one can understand that the audio was of 2 seconds and each 0.33 second has some value.
Explanation of commands:
Commands ‘close all’ closes all the open windows(like plots), clear all clears all the variables i.e. deletes them.
Subplot(‘m’,’n’,’position’) should be used before plotting and tells matlab to display your plot in the position indicated by you in m x n grid.
plot(‘x-axis values’,’y-axis values’) these x-axis and y-axis values must be a set of values(array)
xlabel, ylabel and title are used for labelling and giving title to our plot. They must be used after plotting.
Soundsc(song,fs) plays the song.
I have edited the code for one of the impulse responses. It remains same for the others except at some places for which I have added the comments in the code. Past the following code in matlab editor for better viewing.
close all; clear all;
% make sure all .wav files are in the same directory of this script
% all audio files are sampled at 44100Hz
% import, plot and play singing recording
[song, fs] = audioread('singing.wav'); % import the song
t = [1:length(song)]/fs; % change from index number to time
subplot(3, 1, 1) % first plot of the three plots in the plot window
plot(t, song) % plot the song
xlabel('t (second)')
ylabel('Relative signal strength')
title('Song')
soundsc(song, fs) % play the song
pause % need to press spacebar to continue the progam to listen to next tone
% USE the code segment above as an example
% now import, plot and play the impulse response
[impulse, fs] = audioread('ScalaMilanOperaHall.wav'); %Replace file name ScalaMilanOperaHall.wav with StNicolasChurch.wav and GrandCanyon.wav for the 2nd and third assignment. Rest everything is same
subplot(3, 1, 2)
plot(t, song) % plot the song
xlabel('t (second)')
ylabel('Relative signal strength')
title('Impulse Response Scala Milan') %Change the title according to the impulse response you will be using
soundsc(song, fs)
% CONVOLUTE the audio with the system impulse responses
% using the command conv(sig1, sig2)
% the convolution could take a couple of seconds to complete
% plot and play the output,
% it should sounds as if it was actually recorded in those spaces subplot(3, 1, 3)
output = conv(impulse,song)
subplot(3, 1, 3)
plot(t, output) % plot the song
xlabel('t (second)')
ylabel('Relative signal strength')
title('Output')
soundsc(song, fs)
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.