-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdistortion.m
More file actions
34 lines (31 loc) · 767 Bytes
/
Copy pathdistortion.m
File metadata and controls
34 lines (31 loc) · 767 Bytes
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
function y = distortion(x, gain)
%% This is where the help file goes...
%
% Syntax
% length(x) returns the size of the matrix x.
% The first if statement replaces values equal or greater than 1 with
% 2/3.
% The second if statement replaces values equal or less than -1 with
% -2/3.
% The else clause slightly normalizes any values between 1 and -1.
% Description
% 'x' stores the original signal to be distorted.
% 'y' stores the resultant distorted signal.
%
% Examples
% if x is [-1 -1/2 0 1/2 1], distortion(x,1) would return [-2/3 11/24 0 11/24 2/3]
%
% References
%
% ...
%
x = x.*gain;
for i = 1:length(x)
if(x(i) >= 1)
y(i) = 2/3;
elseif(x(i) <= -1)
y(i) = -2/3;
else
y(i) = x(i) - (x(i)^3)/3;
end
end