Recently, I enrolled in a class on Digital Signals and Systems. One of our first homework assignments was to implement a reverb filter and image smoother in Matlab. I’m not a Matlab expert, but I thought someone else might like to see what I did. Please suggest improvements!
function [ y ] = reverb( Fs, D, Attenuation, x ) %REVERB (Fs, D, Attenuation, x) % Applies reverb to the given sound file % Fs - Sample Rate % D - Delay in milliseconds % Attenuation - Attenuation factor % x - WAV file as a column vector % Convert delay to samples D = round(Fs * D / 1000); % Generate the b array (corresponds to X coeffecients) b = [1 zeros(1,D+1)]; % Generate the a array (corresponds to Y coeffecients) a = [1 zeros(1,D-1) Attenuation]; % Apply the filter y = filter(b, a, x); end
The image smoothing function is as follows
function [ y ] = imagesmooth( filename, N ) %IMAGESMOOTH Smooths the given image with an NxN matrix % filename - The image file to use % N - The size of the smoothing matrix image = imread(filename); h = ones(N) / (N*N); newimage = filter2(h,image); y = uint8(newimage); end
Basically, a reverb and an image smoother are types of difference equations. This is one of the things I’m learning about in my signals class. Essentially, what is happening is every sample y[N] of the output is calculated from an input sample, x[N], along with other past samples from either the input or the output. In the case of the reverb, x[N] is combined with y[N-D] to compute y[N]. For the image smoother, y[N,M] is a function of x[N,M] and all the surrounding samples, x[N-1,M-1], x[N-1,M]], x[N-1,M+1], x[N,M-1], x[N,M], x[N,M+1], x[N+1,M-1], x[N+1,M], and x[N+1,M+1].