Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

PLEASE WR?TE CODE HERE. PLEASE DONT WR?TE ON PAPER, I CANT READ. Summary: Design

ID: 3662219 • Letter: P

Question

PLEASE WR?TE CODE HERE. PLEASE DONT WR?TE ON PAPER, I CANT READ.

Summary: Design and apply a 2-band signal filter. Problem: Use Matlab's signal processing toolbox and filter design tool to design a 2-band filter with magnitude response as shown below. Make a plot showing the magnitude and phase response of your filter. Prepare 10 sec of white noise signal at sampling frequency 500 Hz and use your filter to filter it. Make plots showing the spectra of this signal before and after filtering. Also make plots showing 1 second of your signal before and after filtering, and discuss how they differ and why.

Explanation / Answer

f1=100;f2=200;%the frequencies of sines signal that needs filtered
fs=2000;%sampling frequency
m=(0.3*f1)/(fs/2);%define tansition bandwidth
M=round(8/m);%define the window length
N=M-1;%define the order of filter
b=fir1(N,0.5*f2/(fs/2));%use the firl function to design a filter
%Input parameters are respectively the order number and the cutoff
%frequency of filter
figure(1)
[h,f]=freqz(b,1,512);%amplitude-frequency characteristic graph
plot(f*fs/(2*pi),20*log10(abs(h)))%parameters are respectively
frequency and amplitude
xlabel('frequency/Hz');ylabel('gain/dB');title('The gain response of
lowpass filter');
figure(2)
subplot(211)
t=0:1/fs:0.2;%define the time domain and the steplength
s=sin(2*pi*f1*t)+sin(2*pi*f2*t);%signal before filtering
plot(t,s);%plot the signal graph before filtering
xlabel('time/s');ylabel('amplitude');title('Time-domain diagram before
filtering');
axis([0 0.1 -2 2]);
subplot(212)
Fs=fft(s,512);%transform the signal to frequency domain
AFs=abs(Fs);%take the amplitude
f=(0:255)*fs/512;%frequency sampling
plot(f,AFs(1:256));%plot the frequency domain diagram before filtering
xlabel('frequency/Hz');ylabel('amplitude');title('Frequency-domain
diagram before filtering');
figure(3)
sf=filter(b,1,s);%use filter function to filter
subplot(211)
plot(t,sf)%plot the signal graph after filtering
35
xlabel('time/s');ylabel('amplitude');title('Time-domain diagram after
filtering');
axis([0.1 0.2 -2 2]);
subplot(212)
Fsf=fft(sf,512);%frequency-domain diagram after filtering
AFsf=abs(Fsf);%the amplitude
f=(0:255)*fs/512;%frequency sampling
plot(f,AFsf(1:256))%plot the frequency domain diagram after filtering
xlabel('frequency/Hz');ylabel('amplitude');title('Frequency-domain
diagram after filtering');
(2) Design a bandpass filter using the window function method
Rs=0.01;fs=8000;%sample frequency
fcuts=[1000 1300 2210 2410];a=[0 1 0];
dev=Rs*ones(1,length(a));
[M,Wc,beta,ftype]=kaiserord(fcuts,a,dev,fs);
%M is the minimum order of filter that meets the requirements
%Wc is cutoff frequency
M=mod(M,2)+M;
window=Kaiser(M+1,beta);
b=fir1(M,Wc,ftype,window);
[h,f]=freqz(b,1,512);%amplitude-frequency characteristic diagram
%[H,W]=freqz(B,A,N) when N is an integer, function returns to N frequency
%vector and amplitude-frequency response vector
figure(1)
plot(f*fs/(2*pi),20*log10(abs(h)))% parameters are respectively
frequecy and amplitude
xlabel('frequency/Hz');ylabel('gain/dB');title('The gain response of
bandpass filter');
f1=500;f2=1500;f3=2000;f4=3000;%frequencies of sines signal that needs
filtered
t=(0:200)/fs;%define the time steplength
t1=(0.002:0.00001:0.006);
s=sin(2*f1*pi*t)+sin(2*f2*pi*t)+sin(2*f3*pi*t)+sin(2*f4*pi*t);
s1=sin(2*f1*pi*t1)+sin(2*f2*pi*t1)+sin(2*f3*pi*t1)+sin(2*f4*pi*t1);
sf=filter(b,1,s);%use function filter
figure(2)
subplot(211)
plot(t1,s1);%plot the diagram before filtering
xlabel('time/s');ylabel('amplitude');title('Time-domain diagram before
filtering');
subplot(212)
36
Fs=fft(s,512);AFs=abs(Fs);f=fs/512*(0:255);
plot(f,AFs(1:256));%plot the frequency domain diagram before filtering
xlabel('frequency/Hz');ylabel('amplitude');title('Frequency-domain
diagram before filtering');
figure(3)
subplot(211)
plot(t,sf)%plot the diagram after filtering
xlabel('time/s');ylabel('amplitude');title('Time-domain diagram after
filtering');
axis([0.005 0.025 -4 4]);
subplot(212)
Fsf=fft(sf,512);%frequency-domain diagram after filtering
AFsf=abs(Fsf);%the amplitude
f=(0:255)*fs/512;%frequency sampling
plot(f,AFsf(1:256))%plot the frequency domain diagram after filtering
xlabel('frequency/Hz');ylabel('amplitude');title('Frequency-domain
diagram after filtering');
(3) Design a multi-passband filter using the window function method
Rs=0.01;fs=200;%sample frequency
fcuts=[10 20 40 50 60 70 80 90];a=[0,1,0,1,0];
dev=Rs*ones(1,length(a));
[M,Wc,beta,ftype]=kaiserord(fcuts,a,dev,fs);
M=mod(M,2)+M;window=Kaiser(M+1,beta);b=fir1(M,Wc,ftype,window);
[h,f]=freqz(b,1,512);%amplitude-frequency characteristic graph
figure(1)
plot(f*fs/(2*pi),20*log10(abs(h)))%parameters are respectively
frequency and amplitude
xlabel('frequency/Hz');ylabel('gain/dB');title('The gain response of
multi-passband filter');
f1=5;f2=20;f3=30;f4=55;f5=75;f6=95;%frequencies of sines signal that
needs filtered
t=(0:200)/fs;%define the time steplength
s1=sin(2*f1*pi*t)+sin(2*f2*pi*t)+sin(2*f3*pi*t);
s=s1+sin(2*f4*pi*t)+sin(2*f5*pi*t)+sin(2*f6*pi*t);%the signal before
filtering
sf=filter(b,1,s);%use function filter
figure(2)
subplot(211)
plot(t,s);%plot the diagram before filtering
xlabel('time/s');ylabel('amplitude');title('Time-domain diagram before
filtering');
37
subplot(212)
Fs=fft(s,512);AFs=abs(Fs);f=fs/512*(0:255);
plot(f,AFs(1:256));%plot the frequency domain diagram before filtering
xlabel('frequency/Hz');ylabel('amplitude');title('Frequency-domain
diagram before filtering');
figure(3)
subplot(211)
plot(t,sf)%plot the diagram after filtering
xlabel('time/s');ylabel('amplitude');title('Time-domain diagram after
filtering');
subplot(212)
Fsf=fft(sf,512); AFsf=abs(Fsf);%the amplitude
f=(0:255)*fs/512;%frequency sampling
plot(f,AFsf(1:256))%plot the frequency domain diagram after filtering
xlabel('frequency/Hz');ylabel('amplitude');title('Frequency-domain
diagram after filtering');
App. 2 Frequency sampling method
(1)Design a lowpass filter using frequency sampling method
M=63; Wp=0.5*pi;%the number of samples and the passband cutoff frequency
m=0:(M+1)/2; Wm=2*pi*m./(M+1);%the sampling points and the stopband
cutoff frequency
mtr=floor(Wp*(M+1)/(2*pi))+2;%round to negative
part,i.e.floor(3.5)=3;floor(-3.2)=-4
Ad=[Wm<=Wp];Ad(mtr)=0.38;
Hd=Ad.*exp(-j*0.5*M*Wm);%define frequency-domain sampling vector H(k)
Hd=[Hd conj(fliplr(Hd(2:(M+1)/2)))];
%fliplr is to realize the fliplr of matrix and conj
h=real(ifft(Hd));% h(n)=IDFT[H(k)
w=linspace(0,pi,1000);%get 1000 row vectors between 0 and pi
H=freqz(h,[1],w);%the amplitude -frequency characteristic diagram of the
filter
figure(1)
plot(w/pi,20*log10(abs(H)));%parameters are respectively the
normalized frequency and amplitude
xlabel('the normailzed frequency');ylabel('gian/dB');title('The gain
response of lowpass filter');
axis([0 1 -50 0.5]);
f1=100;f2=300;f3=700;fs=2000;%the frequencies of sines signal that needs
filtered and the sample frequency
figure(2)
38
subplot(211)
t=0:1/fs:0.25;%define the time domain and steplength
s=sin(2*pi*f1*t)+sin(2*pi*f2*t)+sin(2*pi*f3*t);%signal before
filtering
plot(t,s);%plot the diagram before filtering
xlabel('time/s');ylabel('amplitude');title('Time-domain diagram before
filtering');
subplot(212)
Fs=fft(s,512); AFs=abs(Fs);%transform to the frequency domain
f=(0:255)*fs/512;%frequency sampling
plot(f,AFs(1:256));%plot the frequency domain diagram before filtering
xlabel('frequency/Hz');ylabel('amplitude');title('Frequency-domain
diagram before filtering');
figure(3)
sf=filter(h,1,s);%use function filter
subplot(211)
plot(t,sf)%plot the diagram after filtering
xlabel('time/s');ylabel('amplitude');title('Time-domain diagram after
filtering')
axis([0.2 0.25 -2 2]);%set the range of image coordinates
subplot(212)
Fsf=fft(sf,512); AFsf=abs(Fsf);%frequency-domain and the amplitude
diagram
f=(0:255)*fs/512;%frequency sampling
plot(f,AFsf(1:256))%plot the frequency domain diagram before filtering
xlabel('frequency/Hz');ylabel('amplitude');title('Frequency-domain
diagram after filtering');
(2) Design a highpass filter using frequency sampling method
M=32;%the number of samples
Wp=0.6*pi;%passband cutoff frequency
m=0:M/2;%the sampling points
Wm=2*pi*m./(M+1);%stopband cutoff frequency
mtr=ceil(Wp*(M+1)/(2*pi));%round to positive
part,i.e.ceil(3.5)=4;ceil(-3.2)=-3;
Ad=[Wm>=Wp];
Ad(mtr)=0.28;
Hd=Ad.*exp(-j*0.5*M*Wm);%define frequency-domain sampling vector H(k))
Hd=[Hd conj(fliplr(Hd(2:M/2+1)))];
%fliplr is to realize the fliplr of matrix and conj is the conjugate
h=real(ifft(Hd));%h(n)=IDFT[H(k)]
w=linspace(0,pi,1000);%get 1000 row vectors between 0 and pi
39
H=freqz(h,[1],w);%the amplitude -frequency characteristic diagram of the
filter
figure(1)
plot(w/pi,20*log10(abs(H)));%parameters are respectively the
noemalized frequency and amplitude
xlabel('the normailzed frequency');ylabel('gian/dB');title('The gain
response of highpass filter');
axis([0 1 -50 0]);
f1=200;f2=700;f3=800;%the frequencies of sines signal that needs filtered
fs=2000;%the sample frequency
figure(2)
subplot(211)
t=0:1/fs:0.25;%define the time domain and steplength
s=sin(2*pi*f1*t)+sin(2*pi*f2*t)+sin(2*pi*f3*t);%signal before
filtering
plot(t,s);%plot the diagram before filtering
xlabel('time/s');ylabel('amplitude');title('Time-domain diagram before
filtering');
subplot(212)
Fs=fft(s,512);%transform to the frequency domain
AFs=abs(Fs);%the amplitude
f=(0:255)*fs/512;%frequency sampling
plot(f,AFs(1:256));%plot the frequency domain diagram before filtering
xlabel('frequency/Hz');ylabel('amplitude');title('Frequency-domain
diagram before filtering');
figure(3)
sf=filter(h,1,s);%use function filter
subplot(211)
plot(t,sf)%plot the diagram after filtering
xlabel('time/s');ylabel('amplitude');title('Time-domain diagram after
filtering')
axis([0.2 0.25 -2 2]);%set the range of image coordinates
subplot(212)
Fsf=fft(sf,512);AFsf=abs(Fsf);
f=(0:255)*fs/512;%frequency sampling
plot(f,AFsf(1:256))%plot the frequency domain diagram before filtering
xlabel('frequency/Hz');ylabel('amplitude');title('Frequency-domain
diagram after filtering');

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote