67 lines
1.4 KiB
Matlab
67 lines
1.4 KiB
Matlab
%%%%%%%%%%%%%%%%
|
|
%
|
|
%Author: Gabriel LUCAS
|
|
%
|
|
%Creation: 20/04/23 10:08
|
|
%
|
|
%Last Modified: 20/04/23 10:08
|
|
%
|
|
%%%%%%%%%%%%%%%%
|
|
pkg load signal;
|
|
|
|
samplingFreq = 300; %Hz
|
|
|
|
fMin = 30; %Hz
|
|
fMax = 40; %Hz
|
|
|
|
signal = csvread('unknownsignal.csv');
|
|
|
|
signalDuration = size(signal,2)/samplingFreq; %s
|
|
t=[0:1/samplingFreq:(size(signal,2)-1)/samplingFreq];
|
|
windowDuration = signalDuration/2;
|
|
|
|
figure;
|
|
plot(t,signal)
|
|
xlabel('Time (s)');
|
|
ylabel('Sound (dB)');
|
|
title('unknown Signal');
|
|
|
|
blackmanWin = zeros(1, length(t));
|
|
for l_sample=1:windowDuration*samplingFreq
|
|
blackmanWin(l_sample+signalDuration*samplingFreq/4) = (0.42 - 0.5 * cos(2*pi*(l_sample)/(signalDuration*samplingFreq/2)) + 0/08*cos(4*pi*(l_sample)/(windowDuration*samplingFreq/2)));
|
|
end
|
|
|
|
% plot Blackman window
|
|
%~ figure;
|
|
%~ plot(t, blackmanWin);
|
|
|
|
% apply the Blackman window
|
|
for l_sample=1:length(t)
|
|
signal_blackman(l_sample) = signal(l_sample) * blackmanWin(l_sample);
|
|
end
|
|
|
|
% plot signal windowed by rectangular window
|
|
%~ figure;
|
|
%~ plot(t, signal_blackman);
|
|
|
|
% plot the frequency spectrum of this windowed signal
|
|
power_blackman = frequencySpectrum(signal_blackman, samplingFreq);
|
|
|
|
|
|
fft_signal = fft(signal);
|
|
size(fft_signal)
|
|
|
|
figure;
|
|
plot(t, fft_signal);
|
|
xlabel('Time (s)');
|
|
ylabel('Sound (dB)');
|
|
title('FFT of signal');
|
|
|
|
|
|
%b = fir1(600, [1/fMax, 1/fMin], 'bandpass');
|
|
%filtered_signal = filter(b, signal);
|
|
%figure;
|
|
%plot(t,filtered_signal)
|
|
%xlabel('Time (s)');
|
|
%ylabel('Sound (dB)');
|