% lab 4 presentation % lcb 10.26.2000 % time vector fs=44100; % sampling rate n=1:fs; % 1 second at sampling rate display=1:400; % number of samples to display in time domain stem plots % square wave (x[n] input to filter) squarecomponent=[ones(1,100), -1.*ones(1,100)]; % make a single period of the square wave square=[repmat(squarecomponent,1,220) ones(1,100)]; % repeat this period 220.5 times to fill out time vector -> 220.5 Hz frequency at 44.1 kHz srate % display square wave in the time and frequency domains figure(1); subplot(2,1,1); stem(display,square(display)); subplot(2,1,2); specgram(square); soundsc(square,fs); pause % first filter: one-zero (lowpass) b0 = [1 1]; % filter coefficients y0 = firfilt(b0,square); % matlab fir filtering function % display one-zero's output in the time and frequency domains figure(2); subplot(2,1,1); stem(display,y0(display)); % note that filter output is longer than filter input subplot(2,1,2); specgram(y0); % note the relative strength of the high frequencies soundsc(y0,fs); pause % second filter: one-zero with altered coefficients (highpass) b1 = [1 -1]; y1 = firfilt(b1,square); % display new one-zero's output in the time and frequency domains figure(3); subplot(2,1,1); stem(display,y1(display)); subplot(2,1,2); specgram(y1); soundsc(y1,fs); pause % third filter: running average (lowpass) b2 = 1/10.*ones(1,10); y2 = firfilt(b2,square); % display running average's output in the time and frequency domains figure(4); subplot(2,1,1); stem(display,y2(display)); subplot(2,1,2); specgram(y2); soundsc(y2,fs); pause % fourth filter: well-designed lowpass b3=fir1(96,0.2); % order 96 -> long filter; normalized cutoff frequency 0.2 y3 = firfilt(b3,square); % stem filter coefficients figure(5); stem(0:96, b3); pause % display filter output in the time and frequency domains display2=1:200; % zoom in a bit in the time domain figure(6); subplot(2,1,1); stem(display2,y3(display2)); subplot(2,1,2); specgram(y3); soundsc(y3,fs); % scale because filter is outputting values > 1