In: Electrical Engineering
Problem 4 ..... you can use Matlab
Using the same initial code fragment as in Problem 1, add code that calculates and plays y (n)=h(n)?x (n) where h(n) is the impulse response of an IIR bandstop filter with band edge frequencies 750 Hz and 850 Hz and based on a 4th order Butterworth prototype. Name your program p3.sce
the below is the Problem 1 initail code .. you can use it Matlab
The following cilab code generates a 10-second “chirp” with discrete frequencies ranging from 0 to 0.2 with a sampling frequency of 8 kHz.
clear; Fs = 8000; Nbits = 16; tMax = 10; N = Fs*tMax+1; f = linspace(0.0,0.2,N); x = zeros(f); phi = 0; for n=0:N-1 x(n+1) = 0.8*sin(phi); phi = phi+2*%pi*f(n+1); end sound(x,Fs,Nbits); sleep(10000); //allows full sound to play
Matlab code:-
clear;
Fs = 8000;
Nbits = 16;
tMax = 10;
N = Fs*tMax + 1;
f = linspace(0.0,0.2,N);
x = zeros(size(f));
phi = 0;
for n = 0:N-1
x(n+1) = 0.8*sin(phi);
phi = phi + 2*pi*f(n+1);
end
sound(x,Fs,Nbits);
pause(10);
fc = 800;
n =
100;
% filter having 101 elements
Wn = (fc/Fs)*pi;
ftype = 'low';
h = fir1(n,Wn,ftype);
y_low = filter(h,1,x);
sound(y_low,Fs,Nbits);
pause(10);
plot(f,y_low);
xlabel('Freq (Hz)');
title('Low pass output plot vs Freq');
ftype = 'high';
h = fir1(n,Wn,ftype);
y_hi = filter(h,1,x);
sound(y_hi,Fs,Nbits);
pause(10);
figure;
plot(f,y_hi);
xlabel('Freq (Hz)');
title('High pass output plot vs Freq');
Output:-