Skip to content

Instantly share code, notes, and snippets.

@vinesmsuic
Last active October 15, 2019 08:27
Show Gist options
  • Save vinesmsuic/e65c1657ec720a40575f0fd26a88db75 to your computer and use it in GitHub Desktop.
Save vinesmsuic/e65c1657ec720a40575f0fd26a88db75 to your computer and use it in GitHub Desktop.
[MABLAB] Fourier Series Lab Exercises
%3.1
A=2; f0=1000; phi=pi/2;
T0=1/f0;
tt=0:T0/40:4*T0;
xx=A*cos(2*pi*f0*tt+phi);
plot(tt,xx)
axis([0,0.004,-4,4])
xlabel('Time (sec)');
grid on
%3.2
A=2; f0=1000; phi=pi/2;
T0=1/f0;
tt=0:T0/40:4*T0;
xx=A*cos(2*pi*f0*tt+phi);
plot(tt,xx)
axis([0,0.003,-4,4])
xlabel('Time (sec)');
grid on
%4
A=2; f0=1000; phi=-pi/2;
T0=1/f0;
tt = 0:T0/400:4*T0;
xx=(4*A/pi/1)*cos(2*pi*f0*tt +phi)+(4*A/pi/3)*cos(2*pi*3*f0*tt +phi)+(4*A/pi/5)*cos(2*pi*5*f0*tt + phi)+(4*A/pi/7)*cos(2*pi*7*f0*tt + phi);
plot(tt,xx)
axis([0,0.004,-4,4])
xlabel('Time (sec)');
grid on
% 5
fs = 8192;
freq=440*2^(1/12)
t=[0:1/fs:1];
y=sin(2*pi*freq*t);
soundsc(y)
% 5.2
function y = note(n)
fs = 8192;
power = n/12;
freq=440*2^(power)
t=[0:1/fs:1];
y=sin(2*pi*freq*t);
%soundsc(y)
%{ % To Test single note:
function y = note(n)
fs = 8192;
power = n/12;
freq=440*2^(power)
t=[0:1/fs:1];
y=sin(2*pi*freq*t);
soundsc(y)
}
%3.3
function sinwave(A,F,Phi)
T0=1/F;
tt=0:T0/40:4*T0;
xx=A*cos(2*pi*F*tt+Phi);
plot(tt,xx)
axis([0,1/F*3,-abs(A+1),abs(A+1)])
xlabel('Time (sec)');
grid on
function song()
song =[note(2),note(4),note(6),note(4),note(2),note(0),note(2),linspace(0,0,8192),note(2),note(4),note(6),note(4),note(2),note(1),note(2)];
soundsc(song)
%4.2
function squarewave(N)
A=2; f0=1000; phi=-pi/2;
T0=1/f0;
tt = 0:T0/400:4*T0;
xx=0
for i = 1:N
xx= xx+(4*A/pi/(i*2-1))*cos(2*pi*(i*2-1)*f0*tt+phi);
end
plot(tt,xx)
axis([0,0.004,-4,4])
xlabel('Time (sec)');
grid on
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment