0% found this document useful (0 votes)
9 views8 pages

DSP HW 1

The document describes signal processing operations on audio signals including filtering and convolution. It generates sine waves, designs FIR filters, convolves input signals with the filters, and analyzes the results using power spectral density estimates. It also compares the results of a custom convolution function to MATLAB's conv function.

Uploaded by

aboodm20th
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views8 pages

DSP HW 1

The document describes signal processing operations on audio signals including filtering and convolution. It generates sine waves, designs FIR filters, convolves input signals with the filters, and analyzes the results using power spectral density estimates. It also compares the results of a custom convolution function to MATLAB's conv function.

Uploaded by

aboodm20th
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

% load x_sound.

mat
% Fs = 8000;
% x_n = y';
% input_sound = audioplayer(y,Fs);
% play(input_sound);
% audiowrite('input.wav',x_n,Fs)
% pwelch(x_n)

n = 1:5000;
x_n = cos((pi/6) * n) + cos((pi/2) * n) +cos((5*pi/6) * n);
pwelch(x_n)

h1 = fir1(64,1/3);
h2 = fir1(64,[1/3 2/3]);
h3 = fir1(64,2/3,'high');
freqz(h1,1,512);

1
freqz(h2,1,512);

freqz(h3,1,512);

2
y_1 = convme(x_n,h1);
y_2 = convme(x_n,h2);
y_3 = convme(x_n,h3);

pwelch(y_1)

pwelch(y_2)

3
pwelch(y_3)

g = length(y_1);
b = ones(1,g);
i = 1;
while i < g
b(1,i+1)=(-1)^i;
i = i + 1;
end

y_4 = y_1 .* b; % cos(pi*n) = -1^i

4
y_5 = y_3 .* b;

pwelch(y_4)

pwelch(y_5)

y_6 = y_4;y_7 = y_2;y_8 = y_5; % same so no need to plot


y_n = y_6 + y_7 + y_8;

pwelch(y_n)

5
y_n_d = [zeros(1,2) y_n(1,1:5062)]; % delay by 2

hold on
pwelch(y_n)
pwelch(y_n_d)
hold off

% Fs = 8000;
% input_sound = audioplayer(y_n,Fs);
% play(input_sound);

6
% audiowrite('out_to_TX.wav',y_n,Fs)

g = length(y_n_d);
b = ones(1,g);
i = 1;
while i < g
b(1,i+1)=(-1)^i;
i = i + 1;
end

y_n_d_cos = y_n_d .* b; % cos(pi*n) = -1^i

y_1_d = convme(y_n_d_cos,h3);
y_2_d = convme(y_n_d,h2);
y_3_d = convme(y_n_d_cos,h1);

x_n_d = y_1_d + y_2_d + y_3_d;


pwelch(x_n_d)

% input_sound = audioplayer(x_n_d,Fs);
% play(input_sound);
% audiowrite('output.wav',x_n,Fs)

% this is a comparison between my_conv and matlab conv


% it is the same but the problem is that the output
% should be len(x) + len(h) but here the answer is
% less by 1 I do not know why....

x = [1, 2, 3,5,4,5,7];

7
h = [2 ,3,9,7];

y_original = conv(x,h)

y_original = 1×10
2 7 21 44 64 88 100 94 98 49

y_me = convme(x,h)

y_me = 1×10
2 7 21 44 64 88 100 94 98 49

function output = convme(X_n, b_coff)


X_n = [X_n zeros(1,length(b_coff))];

loop = length(X_n) ;
output = zeros(1, loop-1);

for n = 1:loop
Y_n = 0;
for k = 1:length(b_coff)
if n - k >= 1
Y_n = Y_n + b_coff(k) * X_n(n - k);
end
end

% Output the result


if n == 1
continue
else
output(1,n-1) = Y_n;
end
end
end

You might also like