Download as odt, pdf, or txt
Download as odt, pdf, or txt
You are on page 1of 19

EXPERIMENT No.

1
AIM: Matlab program to generate sine and cosine wave.

APPARATUS USED: MATLAB R2016a.

MATLAB CODE:
Fs = 8000;
dt = 1/Fs;
StopTime = 0.25;
t = (0:dt:StopTime-dt)';
Fc = 60;

x = sin(2*pi*Fc*t);
y = cos(2*pi*Fc*t);

subplot(2,1,1)
plot(t,x);
xlabel('time (in seconds)');
title('Signal versus Time');
subplot(2,1,2)
plot(t,y);
xlabel('time (in seconds)');
title('Signal versus Time');
zoom xon;

RESULT:
The experiment was performed successfully.

page 1
FIGURE:

page 2
EXPERIMENT No. 2
AIM: Matlab program to generate a sawtooth wave.

APPARATUS USED: MATLAB R2016a.

MATLAB CODE:
close all

clc
clear all
T = 10*(1/50);
fs = 1000;
t = 0:1/fs:T-1/fs;
x = sawtooth(2*pi*50*t,1/2);
plot(t,x)
title('Sawtooth wave generation')
xlabel('time')
ylabel('amplitude')
grid on

RESULT:
The experiment was performed successfully.

page 3
FIGURE:

page 4
EXPERIMENT No. 3
AIM: Matlab program to generate a square wave.

APPARATUS USED: MATLAB R2016a.

MATLAB CODE:
close all

clear all
clc
t=linspace(-pi,2*pi,121)
x = 2*square(2*t)
plot(t/pi,x,'.-',t/pi,2*sin(2*t))
title('Squarewave generation')
xlabel('time')
ylabel('amplitude')
grid on
zoom xon

RESULT:
The experiment was performed successfully.

page 5
FIGURE:

page 6
EXPERIMENT No. 4
AIM: Matlab program to find the linear convolution and circular convolution of two sequences.

APPARATUS USED: MATLAB R2016a.

MATLAB CODE:
clear all

clc
close all
x = [1 1 1 1];
y = [2 2];
clin = conv(x,y);
xpad = [x zeros(1,6-length(x))];
ypad = [y zeros(1,6-length(y))];
ccirc = ifft(fft(xpad).*fft(ypad));
subplot(2,1,1)
stem(clin,'filled')
ylim([0 11])
title('Linear Convolution of x and y')

subplot(2,1,2)
stem(ccirc,'filled')
ylim([0 11])
title('Circular Convolution of xpad and ypad');
N = length(x)+length(y)-1;
xpad = [x zeros(1,12-length(x))];
ypad = [y zeros(1,12-length(y))];
ccirc = ifft(fft(xpad).*fft(ypad));
ccirc = ccirc(1:N);
ccirc2 = cconv(x,y,6);

RESULT:
The experiment was performed successfully.

page 7
FIGURE:

page 8
EXPERIMENT No. 5
AIM: Matlab program to calculate the discrete fourier transform of a sequence.

APPARATUS USED: MATLAB R2016a.

MATLAB CODE:
close all

clear all
clc

t = 0:1/100:10-1/100;

x = sin(2*pi*15*t) + sin(2*pi*40*t);

y = fft(x);

m = abs(y);

p = unwrap(angle(y));

f = (0:length(y)-1)*100/length(y);

subplot(2,1,1)

plot(f,m)
title('Magnitude')
ax = gca;
ax.XTick = [15 40 60 85];
subplot(2,1,2)
plot(f,p*180/pi)
title('Phase')
ax = gca;
ax.XTick = [15 40 60 85];

RESULT:
The experiment was performed successfully.

Page 9
FIGURE:

page 10
EXPERIMENT No. 6
AIM: Matlab program to load, display and playback an audio file.

APPARATUS USED: MATLAB R2016a.

MATLAB CODE:
[y,Fs] = audioread('signalsExp1.wav')

sound(y)

sound(y,6000)

plot(y)

xlabel('Frequency')

ylabel('amplitude')

title('Sample Signal')

grid on

RESULT: The experiment was performed successfully.

Fs=8000

page 11
FIGURE:

page 12
EXPERIMENT No. 7
AIM: Matlab program to read an audio file and find it's sampling rate.

APPARATUS USED: MATLAB R2016a.

MATLAB CODE:
[y,fs]=audioread('signalsExp1.wav');

fprintf('Information of the sound file "%s":\n', 'signalsExp1.wav');

fprintf('Duration = %g seconds\n', length(y)/fs);


fprintf('Sampling rate = %g samples/second\n', fs);

RESULT:

Information of the sound file "signalsExp1.wav":

Duration = 33.5296 seconds

Sampling rate = 8000 samples/second.

page 13
EXPERIMENT No. 8
AIM: Matlab program to perform FFT and IFFT of an audio file.

APPARATUS USED: MATLAB R2016a.

MATLAB CODE:

[y,Fs]=audioread('signalsExp1.wav');

sound(y);

figure(1);

plot(y); xlabel('time');

ylabel('amplitude');
title('original signal');
grid on;
yfft=fft(y);

figure(2);

plot(yfft);
grid on;
xlabel('Frequency')

ylabel('Amplitude')
title('FFT signal')
yifft=ifft(yfft);
figure(3);

plot(yifft);
grid on;
xlabel('Time')
ylabel('Amplitude')
title('IFFT Signal')

RESULT:

The experiment was performed successfully.

page 14
FIGURE:

page 15
page 16
EXPERIMENT No. 9
AIM: Matlab program to play an audio file in reverse order.

APPARATUS USED: MATLAB R2016a.

MATLAB CODE:

close all

clear all
clc
[y,Fs]=audioread('signalsExp1.wav')

plot(y)

grid on;
xlabel('FREQUENCY');
ylabel('AMPLITUDE');
title('ORIGINAL AUDIO FILE');
z=flipud(y);
sound(z)

figure
plot(z)
grid on;
Xlabel('FREQUENCY');
ylabel('AMPLITUDE');
title('FLIPPED AUDIO FILE');

RESULT:

The experiment was performed successfully.

Fs = 8000

page 17
FIGURE:

page 18

You might also like