-
Notifications
You must be signed in to change notification settings - Fork 1
/
am.m
48 lines (39 loc) · 1.21 KB
/
am.m
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
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
%am.m
%Program author: Akihiro Inui
%Program details: Implement Amplitude Modulation
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
clear all; close all; clc;
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
% 1. Preamble and variable declaration
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
% Read audio file
[x,Fs] = audioread('filename');
% Normalise the input signal
xn = x/max(abs(x(:)));
% Create time vector
t = ([0:length(x)-1]/Fs)';
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
% 2. Amplitude Modulation
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
% Amplitude modulation
A=1; % Amplitude
fc=0.75; % Carrier frequency
a= A*cos(2*pi*fc*t);
y=(1+a).*xn;
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
% 3. Visualise signals
%~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
figfont = 16;
figure
plot(t,a,t,xn,t,y)
xlabel('Time (s)','FontSize',figfont)
ylabel('Amplitude (arbitrary)','FontSize',figfont)
title(['Amplitude modulation'],'FontSize',figfont)
l1 = legend('Modulator','Original','Amplitude modulated');
set(l1,'FontSize',figfont-2)
set(gca,'FontSize',figfont-2)
grid on
% Play back the unmodulated and modulated sounds
%soundsc(x,Fs)
%soundsc(y,Fs)