[go: up one dir, main page]

0% found this document useful (0 votes)
11 views9 pages

DSP Task

Download as pdf or txt
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 9

‫‪DSP Task‬‬

‫سكشن‬ ‫االسم‬
‫‪4‬‬ ‫محمد وسيم محمد احمد‬
‫‪3‬‬ ‫محمد على عبدالفتاح شلتوت‬

‫‪1‬‬
Assignment

1. For each of the following filters plot frequency responses, impulse


responses (DON’T FORGET TO LABEL THE AXES AND TITLE YOUR
PLOTS), Fs = 10 kHz, Is the system stable?
▪ Butterworth filter with n = 4,21 (band pass fc1=200, fc2=2000)

for n=4 :
n = 4;
Fs =10000;
fc1 = 200 ;
fc2 = 2000 ;
f = [0:.001:1]*Fs/2;
[b a] = butter(n,[fc1 fc2]/(Fs/2),"bandpass");
figure(1) ;
subplot(2,1,1);
impz(b,a,50);grid;
title("Impulse Response of butter IIR Bandpass n = 4")
H = freqz(b,a,f,Fs);
subplot(2,1,2);
plot(f,abs(H));grid;
ylim([0 2]);
title("butter IIR Bandpass filter Fs = 10k ,fc1 = 500 ,fc2
=2k ,n=4")
xlabel("Physical Frequency f (HZ)");
ylabel("Frequency Response |H|");
if isstable(b,a)
disp("IIR filter with order n = 4 is Stable");
else
disp("IIR filter with order n = 4 is not Stable");
end

2
For n = 21
n = 21;
Fs =10000;
fc1 = 200 ;
fc2 = 2000 ;
f = [0:.001:1]*Fs/2;
[b a] = butter(n,[fc1 fc2]/(Fs/2),"bandpass");
figure(2);
subplot(2,1,1);
impz(b,a,50);grid;
title("Impulse Response of butter IIR Bandpass n = 21")
H = freqz(b,a,f,Fs);
subplot(2,1,2);
plot(f,abs(H));grid;
ylim([0 2]);
title("butter IIR Bandpass filter Fs = 10k ,fc1 = 500 ,fc2
=2k ,n=4")
xlabel("Physical Frequency f (HZ)");
ylabel("Frequency Response |H|");
if isstable(b,a)
disp("IIR filter with n = 21 is Stable");
else

3
disp("IIR filter with n = 21 is not Stable");
end

2. You have a file named “whistle.wav”:


▪ Read the file into MATLAB, specify #samples and time of recording in sec.

[whistle Fs]=audioread("whistle.wav");
N = length(whistle); % #samples
time = N/Fs ; % time of recording
sound(whistle , Fs, 16) ;
pause(2);

▪ Plot the frequency spectrum of signal x, do you notice the peaks

4
freq_signal = abs(fft(whistle));
f = linspace(0,Fs,N) ;
figure(3);
plot(f,freq_signal);
title('Amplitude Spectrum of whistle
signal')
xlabel('Frequency (Hz)')
ylabel('|whistle Signal|');
figure(9);
subplot(2,1,1);
specgram(whistle,512,Fs)
xlabel("Time");
ylabel("Frequency");
title("Signal with whistle ");

▪ Design a filter to reject the sinusoidal signals from signal x.

a = 1 ;
n = 400 ;
f = (0:.01:1)*Fs/2 ;
b = fir1(n,[400 600]/(Fs/2),"stop");
b1 = fir1(n,[1400 1600]/(Fs/2),"stop");

5
▪ Plot frequency response, impulse response of the designed filter. Is the filter stable?

Filter to remove the first peak :

Filter to remove the second peak :

▪ Plot the frequency spectrum of signal y (the output of the filter).

6
N = length(without_whistle);
without_whistle_in_freq =
abs(fft(without_whistle));
f = linspace(0,Fs,N);
figure(6);
plot(f,without_whistle_in_freq);grid;
title('Amplitude Spectrum of signal without
whistle')
xlabel('Frequency (Hz)')
ylabel('|Signal_without_whistle|');
ylim([0 2500]);

▪ Play the output signal is the whistle still there?

sound(without_whistle,Fs);

7
▪ Calculate the energy for the original signal and the filtered signal.

whisle_energy = sum(whistle.^2);
without_whistle_energy =
sum(without_whistle.^2);
disp("the Original signal Energy :
"+whisle_energy);
disp("the Energy Signal after filtering
: " + without_whistle_energy);

3. For each of the following filters plot frequency responses, impulse responses:
a. 𝑦[𝑛] = 1/8 (𝑥[𝑛] + 𝑥[𝑛 −1]+𝑥[𝑛−2]+𝑥[𝑛−3]+𝑥[𝑛−4]+ 𝑥[𝑛 −5]+𝑥[𝑛−6]+𝑥[𝑛−7])

8
b. 𝑦[𝑛] = 1/8 (𝑥[𝑛] − 𝑥[𝑛 −8])+𝑦[𝑛−1]

You might also like