Disusun Oleh:
1. glassDance.mat
a. Plot sinyal
freqsignal = 50;
timesampling = time(2)-time(1);
freqsampling = 1/timesampling;
sampleprecycle = freqsampling/freqsignal;
sampleprecycle = int32(sampleprecycle);
nrp = 34;
spike = [];k=0;
for i = 1:length(time)
if i == k*sampleprecycle+nrp
spike = [spike 2];
elseif i == (k+1)*sampleprecycle-nrp
spike = [spike -2];
else
spike = [spike 0];
end
if mod(i,sampleprecycle)==0
k=k+1;
end
end
sine_spike = sine+spike;
figure(1);
subplot(311)
plot(time, sine)
title("Sine Signal")
xlabel('Time (s)'), ylabel('Amplitude')
xlim([0 0.1])
subplot(312)
plot(time, spike)
title("Spike Signal")
xlabel('Time (s)'), ylabel('Amplitude')
xlim([0 0.1])
subplot(313)
plot(time, sine_spike)
title("Sin + Spike Signal")
xlabel('Time (s)'), ylabel('Amplitude')
xlim([0 0.1])
figure(2);
subplot(211)
plot(time, sine_spike_filtered)
title("Median Filtered Signal")
xlabel('Time (s)'), ylabel('Amplitude')
xlim([0 0.1])
subplot(212)
plot(time, smoothed_signal)
title("Smoothed Signal")
xlabel('Time (s)'), ylabel('Amplitude')
figure(2);
subplot(211)
plot(time, sine_spike_filtered)
title("Median Filtered Signal")
xlabel('Time (s)'), ylabel('Amplitude')
xlim([0 0.1])
subplot(212)
plot(time, smoothed_signal)
title("Smoothed Signal")
xlabel('Time (s)'), ylabel('Amplitude')
xlim([0 0.1])
𝑖+𝑘
b. 𝑓𝑖𝑙𝑡𝑠𝑖𝑔𝐺(𝑡) = ∑𝑗=𝑖−𝑘 signal(j). gauswin(j − 1 + k)
[whale,fs] = audioread('mbari-mars.wav');
% soundsc(whale,fs)
pnts = length(whale);
timevec = (0:pnts-1)/fs;
figure;
subplot(211), cla
plot(timevec, whale)
xlabel('Time (s)'), ylabel('Amplitude')
hold on
plot(timevec, WLF)
xlabel('Time (s)'), ylabel('Amplitude')
subplot(212), cla
plot(hz1,powr1(1:length(hz1)))
set(gca,'xlim',[100 2000],'ylim',[0 max(powr1)])
xlabel('Frequency (Hz)'), ylabel('Amplitude')
hold on
plot(hz2,powr2(1:length(hz2)))
set(gca,'xlim',[100 2000],'ylim',[0 max(powr2)])
xlabel('Frequency (Hz)'), ylabel('Amplitude')
soundsc(WLF,fs)
Kesimpulan
Saat frekuensi cutoff diubah-ubah, maka akan didapatkan hasil seperti
gambar diatas. Untuk nilai minimum cutoff dapat digunakan sebesar 0,1 Hz
dikarenakan hasil yang didapatkan tidak berbeda jauh dengan cutoff 0,3 Hz. Untuk
nilai maksimal cutoff dapat digunakan sebesar 150 Hz. Hal tersebut didapatkan jika
memainkan suara hasil filter dengan sample waktu 2:22 – 2:42 dengan syntax
“soundsc(WLF(2272000:2592000,:), fs)” maka noise masih terdengar pada
frekuensi cutoff 200 Hz.
Zoom sinyal di 50 Hz
Zoom pada 50 Hz
6. Script Matlab:
clear, clc
%Generate Signal
srate = 1000;
time = -1:1/srate:1;
pnts = length(time);
hz = linspace(0,srate/2,floor(pnts/2)+1);
%Sine Wave Signal
sinewave1 = 5*sin(2*pi*3*time+pi/7); % Signal: 5sin(2𝜋3𝑡+𝜋/7)
sinewave2 = 15*sin(2*pi*10*time+pi/8); % Signal: 15sin(2𝜋10𝑡+𝜋/8)
sinewave3 = 10*sin(2*pi*5*time+pi); % Signal: 10sin(2𝜋5𝑡+𝜋)
sinewave4 = 5*sin(2*pi*15*time+pi/2); % Signal: 5sin(2𝜋15𝑡+𝜋/2)
sinewave5 = 7*sin(2*pi*35*time-pi/4); % Signal: 7sin(2𝜋35𝑡-𝜋/4)
% Plot All Input Signal
figure(1);
sgtitle("Input Signal")
subplot (511), cla
plot(time, sinewave1)
xlim([-1 1])
ylim([-10 10])
subplot (512), cla
plot(time, sinewave2)
xlim([-1 1])
ylim([-20 20])
subplot (513), cla
plot(time, sinewave3)
xlim([-1 1])
ylim([-15 15])
subplot (514), cla
plot(time, sinewave4)
xlim([-1 1])
ylim([-10 10])
subplot (515), cla
plot(time, sinewave5)
xlim([-1 1])
ylim([-10 10])
% Sum of Sinewave
sum_sinewave = sinewave1 + sinewave2 + sinewave3 + sinewave4 +
sinewave5;
figure(2);
sgtitle("Sum of Sinewave")
subplot(211)
plot(time, sum_sinewave)
xlabel('Time (s)'), ylabel('Amplitude')
xlim([-1 1])
title("Time Domain")
hz1 = linspace(0,srate/2,floor(length(sum_sinewave)/2)+1);
powr1 = abs(fft(sum_sinewave)/pnts);
subplot (212)
plot(hz1,powr1(1:length(hz1)))
xlabel('Frequency (Hz)'), ylabel('Amplitude')
xlim([0 50])
title("Frequency Domain")
% BPF Sum of Sinewave
FilSig1 = bandpass(sum_sinewave, [2.5 3.5], srate);
FilSig2 = bandpass(sum_sinewave, [4.5 5.5], srate);
FilSig3 = bandpass(sum_sinewave, [9.5 10.5], srate);
FilSig4 = bandpass(sum_sinewave, [14.5 15.5], srate);
FilSig5 = bandpass(sum_sinewave, [34.5 35.5], srate);
% Plot Frequency Domain Filtered Signal
hzfilt1 = linspace(0,srate/2,floor(length(FilSig1)/2)+1);
powrfilt1 = abs(fft(FilSig1)/pnts);
hzfilt2 = linspace(0,srate/2,floor(length(FilSig2)/2)+1);
powrfilt2 = abs(fft(FilSig2)/pnts);
hzfilt3 = linspace(0,srate/2,floor(length(FilSig3)/2)+1);
powrfilt3 = abs(fft(FilSig3)/pnts);
hzfilt4 = linspace(0,srate/2,floor(length(FilSig4)/2)+1);
powrfilt4 = abs(fft(FilSig4)/pnts);
hzfilt5 = linspace(0,srate/2,floor(length(FilSig5)/2)+1);
powrfilt5 = abs(fft(FilSig5)/pnts);
figure(3);
sgtitle("Filtered Sum of Sinewave Properties")
subplot(511)
plot(hz1,powr1(1:length(hz1)))
xlabel('Frequency (Hz)'), ylabel('Amplitude')
hold on
plot(hzfilt1,powrfilt1(1:length(hzfilt1)))
xlabel('Frequency (Hz)'), ylabel('Amplitude')
xlim([0 50])
subplot(512)
plot(hz1,powr1(1:length(hz1)))
xlabel('Frequency (Hz)'), ylabel('Amplitude')
hold on
plot(hzfilt2,powrfilt2(1:length(hzfilt2)))
xlabel('Frequency (Hz)'), ylabel('Amplitude')
xlim([0 50])
subplot(513)
plot(hz1,powr1(1:length(hz1)))
xlabel('Frequency (Hz)'), ylabel('Amplitude')
hold on
plot(hzfilt3,powrfilt3(1:length(hzfilt3)))
xlabel('Frequency (Hz)'), ylabel('Amplitude')
xlim([0 50])
subplot(514)
plot(hz1,powr1(1:length(hz1)))
xlabel('Frequency (Hz)'), ylabel('Amplitude')
hold on
plot(hzfilt4,powrfilt4(1:length(hzfilt4)))
xlabel('Frequency (Hz)'), ylabel('Amplitude')
xlim([0 50])
subplot(515)
plot(hz1,powr1(1:length(hz1)))
xlabel('Frequency (Hz)'), ylabel('Amplitude')
hold on
plot(hzfilt5,powrfilt5(1:length(hzfilt5)))
xlabel('Frequency (Hz)'), ylabel('Amplitude')
xlim([0 50])
Dari script di atas didapatkan hasil sebagai berikut:
Bentuk masing-masing sinyal sin: