main content

extract voices from music signal -凯发k8网页登录

implement a basic digital music synthesizer and use it to play a traditional song in a three-voice arrangement. specify a sample rate of 2 khz. save the song as a matlab® timetable.

fs = 2e3;
t = 0:1/fs:0.3-1/fs; fq = [-inf -9:2]/12;
note = @(f,g) [1 1 1]*sin(2*pi*440*2.^[fq(g)-1 fq(g) fq(f) 1]'.*t);
mel = [5 3 1 3 5 5 5 0 3 3 3 0 5 8 8 0 5 3 1 3 5 5 5 5 3 3 5 3 1] 1;
acc = [5 0 8 0 5 0 5 5 3 0 3 3 5 0 8 8 5 0 8 0 5 5 5 0 3 3 5 0 1] 1;
song = [];
for kj = 1:length(mel)
    song = [song note(mel(kj),acc(kj)) zeros(1,0.01*fs)];
end
song = song'/(max(abs(song)) 0.1);
% to hear, type sound(song,fs)
tune = timetable(song,samplerate=fs);

open signal analyzer and drag the timetable from the workspace browser to the signal table. click display grid to create a two-by-two grid of displays. add a spectrum view to the top two displays and the lower left display. select the lower right display, click time-frequency to add a spectrogram view, and click time to remove the time view. drag the song to all four displays. select the lower right display, and on the spectrogram tab, specify a time resolution of 0.31 second and 0% overlap between adjoining segments. set the power limits to –50 db and –10 db.

signal analyzer window showing three copies of the waveform and spectrum of a music signal. a fourth display shows the spectrogram of the signal.

on the analyzer tab, click duplicate three times to create three copies of the song. rename the copies as high, medium, and low by double-clicking the name column in the signal table. move the copies to the top two and lower left displays.

select all three duplicate signals in the signal table and click preprocess to enter the preprocessing mode.

  1. select the high signal by clicking its name in the signal table. select highpass from the functions gallery. in the function parameters panel, enter a passband frequency of 450 hz and increase the steepness to 0.95. click apply.

  2. select the medium signal by clicking its name in the signal table. select bandpass from the functions gallery. in the function parameters panel, enter 230 hz and 450 hz as the lower and upper passband frequencies, respectively. increase the steepness to 0.95. click apply.

  3. select the low signal by clicking its name in the signal table. select lowpass from the functions gallery. in the function parameters panel, enter a passband frequency of 230 hz and increase the steepness to 0.95. click apply.

click accept all to save the preprocessing results and exit the mode.

signal analyzer window showing highpass-filtered, bandpass-filtered, and lowpass-filtered copies of a music signal

view a spectrogram on each of the three displays containing filtered signals.

  1. remove the original signal by clearing the check box next to its name.

  2. on the display tab, click time-frequency to add a spectrogram view and click time to remove the time view.

  3. on the spectrogram tab, specify a time resolution of 0.31 second and 0% overlap between adjoining segments. set the power limits to –50 db and –10 db.

signal analyzer window showing the three voices in a music signal

select the three filtered signals by clicking their name column in the signal table. on the analyzer tab, click export and save the signals to a mat-file called music.mat. in matlab, load the file to the workspace. plot the spectra of the three signals.

load music
pspectrum(low)
hold on
pspectrum(medium)
pspectrum(high)
hold off

figure contains an axes object. the axes object with title fres = 1.9536 hz, xlabel frequency (khz), ylabel power spectrum (db) contains 3 objects of type line.

% to hear the different voices, type 
% sound(low.low,fs), pause(5), sound(medium.medium,fs), pause(5), sound(high.high,fs)

see also

apps

functions

  • | | | |

related examples

more about

网站地图