Basic Digital Audio Signal Processing

Basic Digital Audio Signal Processing

Basic Digital Audio Signal Processing In this section we look at some basic aspects of Digital Audio Signal CM0268 Processing: MATLAB DSP GRAPHICS Some basic definitions and principles • 174 Filtering • Basic Digital Audio Effects • 1 JJ II J I Back Close Simple Waveforms CM0268 MATLAB DSP GRAPHICS 175 Frequency is the number of cycles per second and is measured in 1 • Hertz (Hz) Wavelength is inversely proportional to frequency JJ • II i.e. Wavelength varies as 1 frequency J I Back Close The Sine Wave and Sound CM0268 MATLAB DSP GRAPHICS 176 The general form of the sine wave we shall use (quite a lot of) is as follows: y = A:sin(2π:n:Fw=Fs) where: 1 A is the amplitude of the wave, JJ Fw is the frequency of the wave, II Fs is the sample frequency, J n is the sample index. I MATLAB function: sin() used — works in radians Back Close MATLAB Sine Wave Radian Frequency Period CM0268 MATLAB DSP Basic 1 period Simple Sine wave — 1 period is 2π radians GRAPHICS 177 % Basic 1 period Simple Sine wave i=0:0.2:2*pi; y = sin(i); figure(1) plot(y); % use stem(y) as alternative plot as in lecture notes to 1 % see sample values title(’Simple 1 Period Sine Wave’); JJ II J I Back Close MATLAB Sine Wave Amplitude CM0268 MATLAB DSP Sine Wave Amplitude is -1 to +1. GRAPHICS 178 To change amplitude multiply by some gain (amp): % Now Change amplitude amp = 2.0; y = amp*sin(i); 1 figure(2) plot(y); JJ title(’Simple 1 Period Sine Wave Modified Amplitude’); II J I Back Close MATLAB Sine Wave Frequency % Natural frequency is 2*pi radians % If sample rate is F_s HZ then 1 HZ is 2*pi/F_s CM0268 MATLAB % If wave frequency is F_w then freequency is F_w* (2*pi/F_s) DSP GRAPHICS % set n samples steps up to sum duration nsec*F_s where nsec is the % duration in seconds 179 % So we get y = amp*sin(2*pi*n*F_w/F_s); F_s = 11025; F_w = 440; nsec = 2; dur= nsec*F_s; n = 0:dur; 1 y = amp*sin(2*pi*n*F_w/F_s); figure(3) plot(y(1:500)); JJ title(’N second Duration Sine Wave’); II J I Back Close MATLAB Sine Wave Plot of n cycles CM0268 MATLAB DSP GRAPHICS % To plot n cycles of a waveform 180 ncyc = 2; n=0:floor(ncyc*F_s/F_w); y = amp*sin(2*pi*n*F_w/F_s); figure(4) plot(y); title(’N Cycle Duration Sine Wave’); 1 JJ II J I Back Close Cosine, Square and Sawtooth Waveforms MATLAB functions cos() (cosine), square() and sawtooth() CM0268 similar. MATLAB DSP GRAPHICS 181 1 JJ II J I Back Close MATLAB Cos v Sin Wave % Cosine is same as Sine (except 90 degrees out of phase) CM0268 yc = amp cos(2 pi n F_w/F_s); MATLAB * * * * DSP GRAPHICS figure(5); 182 hold on plot(yc,’b’); plot(y,’r’); title(’Cos (Blue)/Sin (Red) Plot (Note Phase Difference)’); hold off; 1 JJ II J I Back Close Relationship Between Amplitude, Frequency and Phase CM0268 MATLAB DSP GRAPHICS 183 1 JJ II J I Back Close Amplitudes of a Sine Wave % Simple Sin Amplitude Demo CM0268 MATLAB samp_freq = 400; DSP dur = 800; % 2 seconds GRAPHICS amp = 1; phase = 0; freq = 1; 184 s1 = mysin(amp,freq,phase,dur,samp_freq); axisx = (1:dur)*360/samp_freq; % x axis in degrees plot(axisx,s1); set(gca,’XTick’,[0:90:axisx(end)]); fprintf(’Initial Wave: \t Amplitude = ...\n’, amp, freq, phase,...); % change amplitude amp = input(’\nEnter Ampltude:\n\n’); 1 s2 = mysin(amp,freq,phase,dur,samp_freq); hold on; JJ plot(axisx, s2,’r’); II set(gca,’XTick’,[0:90:axisx(end)]); J The code is sinampdemo.m I Back Close mysin MATLAB code The above call function mysin.m which a simple modified version CM0268 of previous MATLAB sin function to account for phase. MATLAB DSP GRAPHICS function s = mysin(amp,freq,phase,dur, samp_freq) % example function to so show how amplitude,frequency and phase 185 % are changed in a sin function % Inputs: amp - amplitude of the wave % freq - frequency of the wave % phase - phase of the wave in degree % dur - duration in number of samples % samp_freq - sample frequncy x = 0:dur-1; 1 phase = phase*pi/180; s = amp*sin( 2*pi*x*freq/samp_freq + phase); JJ II J I Back Close Amplitudes of a Sine Wave: sinampdemo output CM0268 MATLAB DSP 1 GRAPHICS 0.8 186 0.6 0.4 0.2 0 −0.2 −0.4 1 −0.6 −0.8 JJ −1 II 0 90 180 270 360 450 540 630 720 J I Back Close Frequencies of a Sine Wave % Simple Sin Frequency Demo CM0268 MATLAB samp_freq = 400; DSP dur = 800; % 2 seconds GRAPHICS amp = 1; phase = 0; freq = 1; 187 s1 = mysin(amp,freq,phase,dur,samp_freq); axisx = (1:dur)*360/samp_freq; % x axis in degrees plot(axisx,s1); set(gca,’XTick’,[0:90:axisx(end)]); fprintf(’Initial Wave: \t Amplitude = ...\n’, amp, freq, phase,...); % change amplitude freq = input(’\nEnter Frequency:\n\n’); 1 s2 = mysin(amp,freq,phase,dur,samp_freq); hold on; JJ plot(axisx, s2,’r’); II set(gca,’XTick’,[0:90:axisx(end)]); J The code is sinfreqdemo.m I Back Close Amplitudes of a Sine Wave: sinfreqdemo output CM0268 MATLAB DSP 1 GRAPHICS 0.8 188 0.6 0.4 0.2 0 −0.2 −0.4 1 −0.6 −0.8 JJ −1 0 90 180 270 360 450 540 630 720 II J I Back Close Phases of a Sine Wave % Simple Sin Phase Demo CM0268 samp_freq = 400; MATLAB DSP dur = 800; % 2 seconds GRAPHICS amp = 1; phase = 0; freq = 1; 189 s1 = mysin(amp,freq,phase,dur,samp_freq); axisx = (1:dur)*360/samp_freq; % x axis in degrees plot(axisx,s1); set(gca,’XTick’,[0:90:axisx(end)]); fprintf(’Initial Wave: \t Amplitude = ...\n’, amp, freq, phase,...); % change amplitude phase = input(’\nEnter Phase:\n\n’); 1 s2 = mysin(amp,freq,phase,dur,samp_freq); hold on; JJ plot(axisx, s2,’r’); II set(gca,’XTick’,[0:90:axisx(end)]); J The code is sinphasedemo.m I Back Close Amplitudes of a Sine Wave: sinphasedemo output CM0268 MATLAB DSP 1 GRAPHICS 0.8 190 0.6 0.4 0.2 0 −0.2 −0.4 1 −0.6 −0.8 JJ −1 0 90 180 270 360 450 540 630 II J I Back Close MATLAB Square and Sawtooth Waveforms % Square and Sawtooth Waveforms created using Radians CM0268 MATLAB ysq = amp*square(2*pi*n*F_w/F_s); DSP GRAPHICS ysaw = amp*sawtooth(2*pi*n*F_w/F_s); 191 figure(6); hold on plot(ysq,’b’); plot(ysaw,’r’); title(’Square (Blue)/Sawtooth (Red) Waveform Plots’); hold off; 1 JJ II J I Back Close Triangular Waveform MATLAB function sawtooth(t,width = 0.5) can create a CM0268 triangular waveform, but its easy to build one ourselves (later we MATLAB DSP make a smoother sounding sawtooth in similar fashion): GRAPHICS % Half Frequency 192 delta = 2*F_w/F_s; % min and max values of simple waveform minf=0;maxf=1; % create triangle wave of centre frequency values figure(7); hold on ytri = []; % plot n cycles while(length(ytri) < floor(ncyc*F_s/F_w) ) ytri = [ ytri amp*(minf:delta:maxf) ]; %upslope doplot = input(’\nPlot Figure? y/[n]:\n\n’, ’s’); if doplot == ’y’, plot(ytri,’r’); 1 figure(7); end lasti = length(ytri); ytri = [ ytri amp*(maxf:-delta:minf) ]; %downslope doplot = input(’\nPlot Figure? y/[n]:\n\n’, ’s’); JJ if doplot == ’y’, II plot(ytri,’b’); figure(7); J end end I title(’Triangular Waveform Plots’); hold off; Back Close Triangular Waveform Display 2 1.8 CM0268 MATLAB DSP 1.6 GRAPHICS 193 1.4 1.2 1 0.8 1 0.6 0.4 JJ II 0.2 J I 0 0 5 10 15 20 25 30 35 40 Back Close Using these Waveforms All above waveforms used (as seen in Lecture notes): CM0268 MATLAB DSP Modulators and Carrier waveforms for various Digital Audio GRAPHICS • effects. 194 – Low Frequency Oscillators (LFO) to vary filter cut-off frequencies and delay times Base waveforms for various forms of synthesis: Subtractive, FM, • Additive (CM0340 Multimedia Year 3) 1 JJ II J I Back Close Simple Digital Audio Effects Example Over the next few slides consider the following example: CM0268 f = 1 f = 1 MATLAB s T s T DSP GRAPHICS 195 x(t) ADCx(n) DAFXy(n) DAC y(t) × e.g. 0.5 1 T -> <- JJ II J I Back Close 1 Sample Interval and Sample Frequency An analog signal, x(t) with signal amplitude continuous over • CM0268 t MATLAB time, . DSP GRAPHICS Following ADC the signal is converted into a a 196 • discrete-time and quantised amplitude signal, x(n) — a stream of samples over discrete time index, n – The time distance between two consecutive samples, the sample interval, T (or sampling period). 1 – The the sampling frequency is fs = T — the number of samples per second measured in Hertz (Hz). 1 Next we apply some simple DAFX — E.g here we • multiply the signal by a factor of 0.5 to produce y(n) = 0:5:x(n). JJ The signal y(n) is then forwarded to the DAC which reconstruct II • an analog signal y(t) J I Back Close The Sine Wave and Sound CM0268 MATLAB DSP GRAPHICS 197 The general form of the sine wave we shall use (quite a lot of) is as follows: y = A:sin(2π:n:Fw=Fs) where: 1 A is the amplitude of the wave, JJ Fw is the frequency of the wave, II Fs is the sample frequency, J n is the sample index.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    58 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us