DSP Manual
DSP Manual
DSP Manual
%IMPULSE SEQUENCE
clc;
clear all;
close all;
N=input('enter the length of sequence in even number');
N1=N/2;
x= [zeros(1,N1) ones(1,1) zeros(1,N1)];
n= -N1:1:N1;
stem(n,x);
axis([-N1 N1 -1 2]);
title('impulse sequence');
xlabel('samples');
ylabel('amplitude');
OUTPUT : ENTER THE LENGTH OF SEQUENCE IN EVEN NUMBER: 20
%RAMP SEQUENCE
clc;
clear all;
close all;
N=input('enter the length of sequence in even number');
n=0:1:N-1;
x=n;
stem(n,x);
axis([-1 N -1 N]);
title('Ramp sequence');
xlabel('samples');
ylabel('amplitude');
grid on
OUTPUT : ENTER THE LENGTH OF SEQUENCE IN EVEN NUMBER: 20
%EXPONENTIAL SEQUENCE
clc;
clear all;
close all;
N=input('enter the length of sequence in even number');
n=0:1:N-1;
x=exp(-n);
stem(n,x);
axis([-1 N -1 2]);
title('exponential sequence');
xlabel('samples');
ylabel('amplitude');
grid on
OUTPUT : ENTER THE LENGTH OF SEQUENCE IN EVEN NUMBER: 20
%SAWTOOTH SEQUENCE
clc;
clear all;
close all;
F=input('enter frequency');
f=6;
fs=10*f;
n=0:1/fs:1;
s=sawtooth(2*pi*4*n);
stem(n,s);
title('sawtooth sequence');
xlabel('time');
ylabel('amplitude');
OUTPUT : ENTER THE FREQUENCY: 20
EXPERIMENT-2 : GENERATION OF SUM OF SINUSOIDAL SIGNALS
AIM: TO GENERATE SUM OF SINUSOIDAL SIGNALS
SOFTWARE REQUIRED : PC INSTALLED WITH MATLAB SOFTWARE
PROCEDURE: 1.OPEN MATLAB SOFTWARE
2.OPEN NEW FILE
3.TYPE THE PROGRAM
4.RUN THE PROGRAM
5.CHECK OUTPUT IN COMMAND WINDOW AND OUTPUT GRAPHS
PROGRAM :
clc;
clear all;
close all;
n=-4:0.5:4;
y1=sin(n);
subplot(2,2,1);
stem(n,y1,'filled');
grid on;
xlabel('samples');
ylabel('magnitude');
title('sinusoidal signal');
y2=sin(2*n);
subplot(2,2,2);
stem(n,y2,'filled');
grid on;
xlabel('samples');
ylabel('magnitude');
title('sinusoidal signal');
y3=y1+y2;
subplot(2,1,2);
stem(n,y3,'filled');
xlabel('samples');
ylabel('magnitude');
title('sum of sinusoidal signal');
EXPERIMENT-3 : IMPLEMENTATION AND VERIFICATION OF LINEAR AND CIRCULAR CONVOLUTION
AIM: TO IMPLEMENT AND VERIFY OF LINEAR AND CIRCULAR CONVOLUTION
SOFTWARE REQUIRED : PC INSTALLED WITH MATLAB SOFTWARE
PROCEDURE: 1.OPEN MATLAB SOFTWARE
2.OPEN NEW FILE
3.TYPE THE PROGRAM
4.RUN THE PROGRAM
5.CHECK OUTPUT IN COMMAND WINDOW AND OUTPUT GRAPHS
A)LINEAR CONVOLUTION PROGRAM :
clc;
clear all;
close all;
disp('enter the length of first sequence m=');
m=input(' ');
disp('enter the length of first sequence x(m)=');
for i=1:m;
x(i)=input(' ');
end
disp('enter the length of second sequence n=');
n=input(' ');
disp('enter the length of second sequence h(n)= ');
for j=1:n;
h(j)=input(' ');
end
y=conv(x,h);
figure;
subplot(3,1,1);
stem(x);
ylabel('amplitude');
xlabel('n');
title('x(n) vs n');
subplot(3,1,2);
stem(h);
ylabel('amplitude');
xlabel('n');
title('h(n)vs n');
subplot(3,1,3);
stem(y);
ylabel('amplitude');
xlabel('n');
title('y(n) vs n');
disp('linear convolution of x(n) and h(n) is y');
OUTPUT: enter the length of first sequence m=4
enter the length of first sequence x(m)= 1
2
3
4
enter the length of second sequence n=
5
enter the length of second sequence h(n)=
1
2
3
4
5
linear convolution of x(n) and h(n) is y
OUTPUT:
enter the input sequence x(n)=
[1 2 3 4]
enter the impulse response sequence h(n)=
[1 2 3 4 5]
input sequence x(n):
1 2 3 4
[1 1 0 0 1 1 0 0]
FFT- 4.0000 + 0.0000i 0.0000 + 0.0000i 2.0000 - 2.0000i 0.0000 + 0.0000i
0.0000 + 0.0000i 0.0000 + 0.0000i 2.0000 + 2.0000i 0.0000 + 0.0000i
B)HPF
clear all;
close all;
f=100:20:8000;
fl=400;
k=length(f);
for i=1:k;
m(i)=1/sqrt(1+(fl/f(i))^2);
mag(i)=20*log10(m(i));
end
figure;
semilogx(f,mag);
title('magnitude response of analog of HPF');
xlabel('frequency');
ylabel('magnitude in db');
grid on;
EXPERIMENT-8 : DESIGN OF IIR BUTTERWORTH FILTER AND VERIFY FREQUENCY RESPONSE
AIM: TO DESIGN IIR FILTER
SOFTWARE REQUIRED : PC INSTALLED WITH MATLAB SOFTWARE
PROCEDURE: 1.OPEN MATLAB SOFTWARE
2.OPEN NEW FILE
3.TYPE THE PROGRAM
4.RUN THE PROGRAM
5.CHECK OUTPUT IN COMMAND WINDOW AND OUTPUT GRAPHS
PROGRAM :
A)LPF
clc;
clear all;
close all;
format long;
rp=input('enter pass band ripple');
rs=input('enter the stopband ripple');
wp=input('enter the passband frequency');
ws=input('enter the stopband frequency');
fs=input('enter the sampling frequency');
w1=2*wp/fs;
w2=2*ws/fs;
[n,wn]=buttord(w1,w2,rp,rs,'s');
[z,p,k]=butter(n,wn);
[b,a]=butter(n,wn,'s');
w=0:0.01:pi;
[h,om]=freqs(b,a,w);
m=20*log10(abs(h));
an=angle(h);
subplot(2,1,1);
plot(om/pi,m);
title('magnitude plot of lpf iir');
ylabel('gain in db');
xlabel('(a)normalised freq');
subplot(2,1,2);
plot(om/pi,an);
title('phase response of lpf iir filter');
ylabel('phase in db');
xlabel('(b)normalised freq');
OUTPUT:
OUTPUT:
Enter the passband ripple(rp):
0.01
Enter the stopband ripple(rs):
0.04
Enter the passband frequency(fp):
1000
Enter the stopband frequency(fs):
2000
Enter the sampling frequency(f):
5000
Enter the beta value:
2
a)decimation
clc;
clear all;
close all;
M = input ('enter Down-sampling factor: ');
N = input ('enter number of samples :');
n = 0: N-1;
x = sin (2*pi*0.043*n) + sin (2*pi*0.031*n);
y = decimate(x, M,'fir');
subplot(2, 1, 1);
stem (n,x(1:N));
title ('Input Sequence');
xlabel ('Time index n');
ylabel ('Amplitude');
subplot(2, 1, 2);
m = 0:(N/M)
stem (m,y);
title('Output Sequence');
xlabel('Time index n');
ylabel('Amplitude');
output:
enter Down-sampling factor: 3
enter number of samples :100
b)interpolation
clc;
clear all;
close all;
L=input('enter the upsampling factor');
N=input('enter the length of the input signal'); % Length should be greater than 8
f1=input('enter the frequency of first sinusoidal');
f2=input('enter the frequency of second sinusoidal');
n=0:N-1;
x=sin(2*pi*f1*n)+sin(2*pi*f2*n);
y=interp(x,L);
subplot(2,1,1)
stem(n,x(1:N))
title('input sequence');
xlabel('time(n)');
ylabel('amplitude');
subplot(2,1,2)
m=0:N*L-1;
stem(m,y(1:N*L))
title('output sequence ');
xlabel('time(n)');
ylabel('amplitude');
output:
enter the upsampling factor
4
enter the length of the input signal
12
enter the frequency of first sinusoidal
5
enter the frequency of second sinusoidal
10
a)LPF
clc;
close all;
clear all;
% LPF
[dataIn,Fs]=audioread('mary_trumpet_adsr-38724.mp3');
% Filter the signal
fc=500; % make higher to hear higherfrequnecies
% design a Butterworth filter
[b,a]=butter(6,fc/Fs);
subplot(2,1,1);
stem(a);
xlabel('normalised frequency');
ylabel('magnitude in db');
title('magnitude response of audio signal');
subplot(2,1,2);
stem(b);
xlabel('normalised frequency');
ylabel('phase in db');
title('phase response of audio signal');
% Apply the BUtterworth filter
filtered_signal=filter(b,a,dataIn);
% Play the sound
player=audioplayer(filtered_signal,Fs);
play(player);
b)hpf
clc;
close all;
clear all;
% HPF
[dataIn,Fs]=audioread('mary_trumpet_adsr-38724.mp3');
% Filter the signal
fc=500; % make higher to hear higherfrequnecies
% design a Butterworth filter
[b,a]=butter(6,fc/(Fs/2));
subplot(2,1,1);
stem(a);
xlabel('normalised frequency');
ylabel('magnitude in db');
title('magnitude response of audio signal');
subplot(2,1,2);
stem(b);
xlabel('normalised frequency');
ylabel('phase in db');
title('phase response of audio signal');
% Apply the BUtterworth filter
filtered_signal=filter(b,a,dataIn);
% Play the sound
player=audioplayer(filtered_signal,Fs);
play(player);
EXPERIMENT-13: Compute the correlation coefficient for the two given audio signals of same
length using a digital signal processor.
AIM: To Compute the correlation coefficient for the two given audio signals of same length using a
digital signal processor.