-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLab_project.m
More file actions
56 lines (38 loc) · 1.65 KB
/
Copy pathLab_project.m
File metadata and controls
56 lines (38 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
% closing previous windows and clearing wokspace---------------------------
close all;
clear all;
% Audio file
% Loading------------------------------------------------------------------
AudioFile = 'E:\songs\Ahankara_Nagare_-_Original__Ranidu_Lankage_Sarigama_lk-[AudioTrimmer.com].mp3'; % File name of audio file
[snd,fs] = audioread(AudioFile); % Reads sound file to snd and sampling freq to fs
%fs = 44100 samples/sec
%Scaling or pitch shifting-----------------------------------------------------------------------------
snd=resample(snd,1,2); %resample(x,p,q) resamples the input sequence, x, at p/q times the original sample rate
pt=30;% plotting time %30sec
N = fs*pt;%samples taken
t = (0:N-1)/fs;
%Time domain representation--------------------------------------------
Xt = snd(1:N,1);
%frequency shifting-------------------------------------------------------
%f0=500;%shifting frequency(default f0=0)
%Xt=cos(2*pi*f0*t).*Xt;% exp(2*pi*f0*t)*x(t)
%filtering--------------------------------------------------------------------------------------------
fc=5000;
[b a] = butter(20,fc/25000, 'low');
Xt = filter(b,a,Xt);
% Normalize(Scale the output between -1,1)
nXt = Xt/max(abs(Xt));
subplot(2,1,1);
plot(t,nXt);
xlabel ('Time (s)');
ylabel ('Amplitude');
title ('Audio Signal (Time Domain)');
%----------------------------------------------------------------------
%Frequancy domain representation---------------------------------------
Xf = abs(fftshift(fft(Xt)));
f = (-N/2:N/2-1)*fs/N;
subplot(2,1,2);
plot(f,Xf);
xlabel ('Frequency (Hz)');
ylabel ('Magnitude');
title ('Audio Signal (Frequency Domain)');