Saptak
Saptak
%q1
clc
A=10;%Amplitude
l=100;%length
f=20000;
fs1=1000;%Sampling frequency
p=pi/2;% phase
n=0:l-1;
phi1=2*pi*fs1/f; %Angular frequency
x1=A*cos(phi1*n+p);
figure
subplot(3,1,1);
stem(n,x1);
xlabel('Time');
ylabel("Sinusoidal wave with fs=1000Hz");
fs2=8000;%Sampling frequency
phi2=2*pi*fs2/f; %Angular frequency
x2=A*cos(phi2*n+p);
subplot(3,1,2);
stem(n,x2);
xlabel('Time');
ylabel("Sinusoidal wave with fs=8000Hz");
fs3=10000;%Sampling frequency
phi3=2*pi*fs3/f; %Angular frequency
x3=A*cos(phi3*n+p);
subplot(3,1,3);
stem(n,x3);
xlabel('Time');
ylabel("Sinusoidal wave with fs=10000Hz");
%q2
clc,clearvars
l=100;
n=0:l-
1; %original
signal
s=2*(n.*(0.9).^n);
figure
subplot(2,3,1);
stem(n,s);
xlabel('Time');
ylabel("Original signal");
%noise signal
d=rand(1,l) - 0.5;
subplot(2,3,2);
stem(n,d);
xlabel('Time');
ylabel("Noise signal");
subplot(2,3,3);
stem(n,x);
xlabel('Time');
ylabel("Noise corrupted signal");
%filter
M = 5;
b = ones(1,M)/M;
y = filter(b,1,x);
subplot(2,3,4);
stem(n,x);
xlabel('Time');
ylabel("Filtered signal with length =5 ");
M = 7;
b = ones(1,M)/M;
y = filter(b,1,x);
subplot(2,3,5);
stem(n,x);
xlabel('Time');
ylabel("Filtered signal with length =7 ");
M = 9;
b = ones(1,M)/M;
y = filter(b,1,x);
subplot(2,3,6);
stem(n,x);
xlabel('Time');
ylabel("Filtered signal with length =9 ");
q3
clc,clearvars
n=0:1000; %inp
ut signal
u=(n>=0);
a=16;
p=sqrt(a);
x=a*u;
figure;
subplot(2,1,1);
stem(n,x);
xlabel("Time");
3
ylabel("Input signal x[n]");
i=n+1;
y=ones(size(i));
y(1)=0.5*(1+x(1));
for t=2:size(n)-1
y(t)=0.5*(p+x(t)/p);
p=y(t);
end
subplot(2,1,2);
plot(n,y);
xlabel("Time");
ylabel("Output signal y[n]");
%% q4
%Speech file read
[speech, fs]=audioread('sample-
6s.mp3'); %Speech signal plot
n=(0:length(speech)-1)/fs;
figure
plot(n,speech);
xlabel('Time');
ylabel('Amplitude');
4
title('Speech signal');
%Quantization range
minValue=min(speech);
maxValue=max(speech);
for i=1:length(bitNum)
num=bitNum(i);
quantizedSpeech=quantize(speech,num,minValue,maxValue);
%SNR
snrVal=snr(speech,speech-quantizedSpeech);
plot(num,snrVal, 'o', 'DisplayName',sprintf('%d bits',num));
end
hold off;
title('SNR vs. Number of Bits/Sample');
xlabel('Number of Bits/Sample');
ylabel('SNR (dB)');
legend('show');
grid on;
5
% Function to quantize the speech signal