LabHints0 - Lab Exercise Hints (Worksheet 0): ...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Lab Exercise Hints (Worksheet 0): MATLAB Revision / Audio, Image and Video Processing Audio Data 1. Use load(‘handel’) to load the built ­in handel wave. Or if handel.wav is downloaded from Blackboard, use [y, Fs] = wavread(‘handel.wav’); Use plot(y) to plot the waveform. Use y=y(end: ­1:1); to reverse the wave. Modify the volume by element ­wise multiplication, e.g. y=y.*1.1; increases volume by 10%. To segment the audio into short segments and reverse every other segment (i.e. for every 2048 samples, reverse the order of the first 1024 samples). for i=1:2048:length(y) ­1023 y(i:i+1023)=y(i+1023: ­1:i); end 2. To create a vector with random numbers, use y = rand(2 * 8192, 1) The sound is white noise, which lasts for length(y) / Fs = (2 * 8192) / 8192 = 2 seconds. Image Data 1. a. To load a data file, use load(‘A.dat’) b. To scale the values to 0—1, use A=A./max(max(A)) ; c. To show the image, use imshow(A); d. Use im = imread(‘filename’) ; to read an image file into MATLAB e. Use im = 255 – im; to inverse an image 2. Random numbers: A=rand(512); This looks like a (white) noise image. 3. The three components of a coloured image can be obtained with something like im(:, :, 1), im(:, :, 2) and im(:, :, 3) assuming im corresponds to the image. To manually calculate the intensity intensity = im(:, :, 1)/3 + im(:, :, 2)/3 + im(:, :, 3) / 3; Use imshow(intensity) to see the result. 1 Reduce the intensity by 30%: intensity = intensity * 0.7; Take out the top ­left 256x256: A=intensity(1:256, 1:256); Decompose the image into e.g. 16x16 blocks, and fill in each block with numbers 1, 2, 3, … sz = 16; % block size S=qtdecomp(A, 0, [sz sz]); % decomposition [i, j, s] = find(S); blocks = zeros(size(A)); for k=1:length(s) blocks(i(k):i(k)+sz-1, j(k):j(k)+sz-1) = k; end Video Data 1. Use v = aviread(‘origdave.avi’); to read in an avi movie. Use v(1:end)=v(end: ­1:1); to reverse the order. Use v=v(randperm(length(v))); to randomly permute the frames. randperm(n) returns a random permutation of numbers 1, 2, … n. MATLAB Basic Digital Signal Processing 1. Try the given MATLAB code with different parameters, as given in the lab sheet. 2. Simple waveforms of sine and sawtooth can be synthesized using a similar approach as the demo code synthe.m, downloadable from BlackboardModule DocumentsLab ClassesDataAudio Synthesis – Supporting Files. 3. Following MATLAB help for butter to generate filter parameters A and B for butterworth filter: BUTTER Butterworth digital and analog filter design. [B,A] = BUTTER(N,Wn) designs an Nth order lowpass digital Butterworth filter and returns the filter coefficients in length N+1 vectors B (numerator) and A (denominator). The coefficients are listed in descending powers of z. The cutoff frequency Wn must be 0.0 < Wn < 1.0, with 1.0 corresponding to half the sample rate. If Wn is a two ­element vector, Wn = [W1 W2], BUTTER returns an order 2N bandpass filter with passband W1 < W < W2. [B,A] = BUTTER(N,Wn,'high') designs a highpass filter. [B,A] = BUTTER(N,Wn,'low') designs a lowpass filter. [B,A] = BUTTER(N,Wn,'stop') is a bandstop filter if Wn = [W1 W2]. Assume the sampling rate is 44.1kHz, 2nd order butterworth lowpass filter with cutoff frequency at 16kHz can be obtained with [B, A] = butter(2, 16/(44.1/2), ‘low’) Other cases can be obtained similarly. 2 ...
View Full Document

This note was uploaded on 01/26/2012 for the course CM 0340 taught by Professor Davidmarshall during the Fall '09 term at Cardiff University.

Ask a homework question - tutors are online