You are on page 1of 10

Table of Contents

........................................................................................................................................ 1
Question 3: ........................................................................................................................ 1
Question 4: ........................................................................................................................ 5
Question 5: ........................................................................................................................ 6
Question 6: ........................................................................................................................ 9

clc,clear all,close all;

Question 3:
Part a

load("HW5Problem1.mat")
figure
imagesc(BadImage);
colormap(gray);
colorbar;
% Part b
Ty=45;
% PART C
Tx=10;
% PART D:
wn1=[2*(1/Ty)*0.80 2*(1/Ty)*1.20];
wn2=[2*(1/Tx)*0.80 2*(1/Tx)*1.20];
hy=fir1(199,wn1,'stop');
hx=fir1(199,wn2,"stop");
figure
freqz(hy)
figure
freqz(hx)
% Part e
for k=1:799
filtered_Image(:,k)= filtfilt(hy,1,BadImage(:,k));
end
figure
imagesc(filtered_Image);
colormap(gray);
colorbar;
% Part f
for k=1:1078
filtered_Image(k,:)= filtfilt(hx,1,filtered_Image(k,:));
end
figure;
imagesc(filtered_Image);
colormap(gray);
colorbar;

Warning: Odd order symmetric FIR filters must have a gain of zero at
the Nyquist

1
frequency. The order is being increased by one.
Warning: Odd order symmetric FIR filters must have a gain of zero at
the Nyquist
frequency. The order is being increased by one.

2
3
4
Question 4:
load HW5Problem4.mat
ts=1/fs;
t=(0:1:length(x)-1).*ts;
figure
plot(t,x)
% Part b:
fft_x=fftshift(abs(fft(x)));
df=fs/length(fft_x);
frequency=[-fs/2:df:fs/2-df];
figure
plot(frequency,fft_x)
% part 3:
% there are 3 frequencies present at 10 15 and 20 Hz respectively

5
Question 5:
[y,fs]=audioread('speaker1.wav');
ts=1/fs;
t=(0:1:length(y)-1).*ts;
plot(t,y)
title("Signal 1")
fft_y=fftshift(abs(fft(y)));
df=fs/length(fft_y);
frequency=[-fs/2:df:fs/2-df];
figure
plot(frequency,fft_y)
title("Signal 1")
% File 2:
[y,fs]=audioread('speaker2.wav');
ts=1/fs;
t=(0:1:length(y)-1).*ts;
figure
plot(t,y)
title("Signal 2")
fft_y=fftshift(abs(fft(y)));
df=fs/length(fft_y);
frequency=[-fs/2:df:fs/2-df];
figure
plot(frequency,fft_y)

6
title("Signal 2")

7
8
Question 6:
load HW5Problem6.mat
f_max=fs/2;
fft_data=abs(fft(data));
df=fs/length(fft_data);
frequency=[0:df:fs-df];
plot(frequency,fft_data)

9
Published with MATLAB® R2020a

10

You might also like