DSP Task
DSP Task
DSP Task
سكشن االسم
4 محمد وسيم محمد احمد
3 محمد على عبدالفتاح شلتوت
1
Assignment
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
[whistle Fs]=audioread("whistle.wav");
N = length(whistle); % #samples
time = N/Fs ; % time of recording
sound(whistle , Fs, 16) ;
pause(2);
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 ");
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?
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]);
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]