[ seed for this post ] [ assignment & given files ]

SGN-21006 is a course that I need to take! Anyway, I worked a little on this assignment to get more comfortable with using MATLAB’s adaptfilt.lms. This post contains some animated GIFs of my results and the code used.

I had the following assumptions before working on this assignment:

The best results are produced by running the LMS algorithm with –

- Maximum possible length of the filter AND
- Minimum possible step size

This was a very bad starting point. However, after playing around with the values – I have concluded that I was completely wrong. There could be an optimal length and step size – but they don’t have to be max/min that the computer can handle. I feel that understanding the actual implementation of the algorithm would help me predict these optimal values. Some SGN-21006 resources on that:

[ slides ] [ exercise set 4 ]

The assignment basically provided a desired / source signal, and ten similar outputs generated (probably) by the same IIR filter. The goal was to feed these ten filtered signals, one at a time, into an adaptive filter – with the source signal as the desired output.

I made an adaptfilt.LMS object to do that, and I varied the step size and the length of this filter to see how the algorithm worked.

Below are two galleries consisting of animated GIFs. Click on an image to compare different animations.

Effect of decreasing step size:

Effect of increasing the filter’s length:

Interestingly, multiple runs may (not) affect the filter’s weights!

Code used:

% Abhinav Uppal | ECE 3952 | LMS examples % --------------------------------------- % Code skeleton by: % Ionut Schiopu % SGN-21006, ADVANCED SIGNAL PROCESSING % Exercise Set 7 % Link: % http://www.cs.tut.fi/~schiopu/SGN21006/ASP_Set7/ASP_Set7_v2.pdf %------------------------------------ %% for screen recording clc; clear; clf; pause(10); figure(1); fprintf('Recording!') pause(2); %------------------------------------- %% Actual code begins NrOfTrials = 10; % Ten 24-bit files are inputted %% Filters creation length = 40; % this was changed for the runs step = 0.015; % this was changed for the runs leakage = 1; coeffs = zeros(1, length); states = zeros(1, length-1); hLMS = adaptfilt.lms(length, step, leakage, coeffs, states); %% Desired signal [d, fs, nbits1] = wavread('S7_Quake_III_Arena_Gameplay.wav'); dPlay = audioplayer(d, fs); play(dPlay); %% Listen to the filtered signals k = 10; [u, fs2, nbits2] = wavread(['S7_Quake_III_Arena_Gameplay_IIR_', ... num2str(k), '.wav']); dPlay = audioplayer(u*2^(nbits2-nbits1), fs2); % play(dPlay); %uncomment to listen to the file %% for k=1:NrOfTrials %% Input signal [u, fs, nbits2] = wavread(['S7_Quake_III_Arena_Gameplay_IIR_', num2str(k), '.wav']); u = u * 2^(nbits2-nbits1); % what's up with that %% Least Mean Squares algorithm % LMS [y, e] = filter(hLMS, u, d); % Adaptive plotting figure(1); subplot(2,1,1); plot(1:max(size(y)), y, 'b', 1:max(size(y)),e, 'r'); title(['Step Size = ' num2str(step)], 'FontSize', 18); xlabel('sample #', 'FontSize', 16) ylabel('signal value', 'FontSize', 16) legend(['output for track #' num2str(k)], 'error') subplot(2,1,2); stem(hLMS.coefficients); title(['coeffs for length ' num2str(length) ' filter'], 'FontSize', 16) % animate pause(0.2); end

Tip: working on a bigger screen desktop (be it in Ford, DDL or the library) it is advisable to upload a copy of the code to drive. Furthermore, it is advisable to check that the *most recent* copy was uploaded. Else, nevermind the extra practice on implementing MATLAB filters…

Tip 2: documentation takes time, but it would be worth it when I refer back to these posts!

Recordings were made through Quicktime. Here’s a handy MOV -> GIF converter.