Unformatted text preview:

Lecture 6: Modifying Sampled SignalsQuestionsGoals for TodayCreating a Signal in MATLABTime-domain view of signal recoveryReading a Signal into MATLABModifying SoundsSimple Signal OperationsSimple Signal OperationsTime ScalingFiltering: Changing Frequency ContentSpeech ExampleExample: Castanets & GuitarSquare Wave ExampleDifferent Varieties of Filters More on FilteringFor the ambitious….More on Time ScalingResampling vs. Time ScalingFiltering in MATLABLecture 6: Modifying Sampled SignalsThe Digital World of MultimediaProf. Mari OstendorfEE299 Lecture 618 Jan 2008Questions Do you want solutions posted for Lab 1? yes Extra lab hours – what times are good?(We have an undergrad assistant starting next week.) Weds after class?? (tbd) My office hours: Friday change to 9-11 Extra office hours – Thurs after 3:30 (tbd)EE299 Lecture 618 Jan 2008Goals for Today Working with digital signals in MATLAB Simple methods for modifying sounds Filtering Signal generationEE299 Lecture 618 Jan 2008Creating a Signal in MATLAB Desired signal: x(t)=cos(2πF0t), F0=100Hz Pick a sampling rate, say Fs=250Hz (Fs=250;Ts=1/Fs;) Corresponds to Ts=1/250 sec To make a 3 sec signal:  Create a time vector: t3 = [0:Ts:3]; Use that in the cosine function to get a value for x(n) at each time nTs: In math: x(n)= cos(2πF0nTs) In MATLAB: x= cos(2*pi*100*t3); To play the signal, use:sound(x,Fs) NOT sound(x). Why?stem(x) plots samplesplot(x) connects the dotsIf Fs is big enough, why doesn’t plot(x) look like cosine above?Need Fs to get back to the analog world.If not specified, Fs=8192Hz is used.See next slide….EE299 Lecture 618 Jan 2008Time-domain view of signal recovery Straight line interpolation is like putting a triangle at each sample and adding them up Using a smoother function works better (the picture is an approximation) In the frequency domain, it is an ideal low pass filterEE299 Lecture 618 Jan 2008Reading a Signal into MATLAB Demo: What’s wrong with this? haha = wavread(‘haha2’);  sound(haha); Right approach(es)… [haha, Fs, bits] = wavread(‘haha2’); or [haha, Fs] = wavread(‘haha2’); sound(haha,Fs);signal sampling rate quantizationEE299 Lecture 618 Jan 2008Modifying Sounds Amplitude operations Multiplying signals (e.g. for fading) Adding two signals (mixing) Time operations Time reverse Time delay Time-scale modification (speed up, slow down) Changing frequency content: filteringEE299 Lecture 618 Jan 2008Simple Signal Operations Amplitude scaling:y(n) = 3*x(n)Changes loudness, especially useful if you filter out frequency content and end up with a lower energy signal (watch out for clipping) Mixing signals: addition (optionally with scaling)y(n) = x1 (n) + 0.2*x2 (n) Changing the envelope, as in fading: multiplicationy(n) = x1 (n)*x2 (n) (use y=x1.*x2 in MATLAB)EE299 Lecture 618 Jan 2008Simple Signal Operations Time reverse (flipud(x) or fliplr(x) in MATLAB) Examples: music speech Time Delay: y(n) = x(n-T0) in MATLAB: delayed_x = [zeros(T0,1);x]; Echo: (Multiple time delays added)y(n) = x(n) + 0.5*x(n-T0 ) + 0.25*x(n-2T0 ) MATLAB example: relax>> pause=zeros(1500,1);>> echo=[relax;pause;relax*.4;pause;relax*.16;pause;relax*.05];>> sound(echo)EE299 Lecture 618 Jan 2008Time ScalingDrop samples:• speed up in time• higher pitch • higher frequency content(watch out for aliasing!)Insert samples: • slow down in time• lower pitch• lower frequency content(no aliasing worries)2X: Drop in MATLAB:for i=1:len/2cos2(i)=cos1(2*i-1);end0.5X: Insert in MATLAB:for i=1:len-1cos3(2*i-1)=cos1(i);cos3(2*i)=0.5*(cos1(i)+cos(i+1));endX(2n)X(n/2)EE299 Lecture 618 Jan 2008Filtering: Changing Frequency Content Low pass filter: Keeps low frequencies, suppresses high frequencies Smoothing effect High pass filter: Keeps high frequencies, suppresses low frequencies Emphasizes abrupt changes Band pass filter: Keeps some mid range of frequencies, suppresses both high and low frequenciesEE299 Lecture 618 Jan 2008Speech ExampleLow Pass FilteredHigh Pass FilteredOriginal SignalEE299 Lecture 618 Jan 2008Example: Castanets & GuitarEE299 Lecture 618 Jan 2008Square Wave ExampleOriginal signallow pass filteredhigh pass filteredEE299 Lecture 618 Jan 2008Different Varieties of Filters Different LPFsAll with cut-off at 100HzEE299 Lecture 618 Jan 2008More on Filtering Can also be used to “shape” frequency content Any function of the formy(n)=a1 y(n-1)+a2 y(n-2)+…+ap y(n-p)+b0 x(n)+b1 x(n-1)+…+bm (n-m)can be used to shape/change frequency content (input is x(n), output is y(n)) Leads us to the idea of generating signalsEE299 Lecture 618 Jan 2008For the ambitious….EE299 Lecture 618 Jan 2008More on Time Scaling What can you to avoid aliasing when increasing pitch? Low pass filter (LPF) the sound before you time scale Example:  Fs=16kHz, signal uses full 8kHz band,  want to time scale by a factor of 2 LPF at 4kHz cutoff (0.5 cutoff in digital filter design) Can you change the pitch without changing the duration? Yes, but it requires tricky cutting/pasting of pieces of the signal (beyond the scope of this class)EE299 Lecture 618 Jan 2008Resampling vs. Time Scaling Playing a signal with a different Fs has the same effect as time scaling, BUT It’s not a solution if you want to do multiple time scale changes within one sound file Time scaling: add/drop samples, keep Fs the same Resampling: changing Fs but NOT changing the duration/pitch of the signal Needed for combining signals of different sampling rates, or for taking up less disk space Resampling: add/drop samples, change Fs When decreasing Fs, watch out for aliasing! Handy function for resampling….EE299 Lecture 618 Jan 2008Filtering in MATLAB You can implement a filter in MATLAB by: writing a for loop to implement the system function (as in Lab2 “filtersounds.m”) Calling the built-in “filter” function, as in:y=filter(b,a,x) where b=[b0 b1 …bm ], a=[1 a1 a2 …ap ]  You can design a filter… By hand, as in: a=1; b=[1 1 1]/3; Using filter design commands, such as:[b a] = butter(n,Wn,’ftype’) OR b= fir1(n,Wn,'ftype');a=1;low, high, or stopcutoff(s):Ex: Wn=0.5=4k/8kFor 4k analog cutoff of signal with 8k range (Fs=16k)order (size of


View Full Document

UW EE 299 - Modifying Sampled Signals

Download Modifying Sampled Signals
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Modifying Sampled Signals and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Modifying Sampled Signals 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?