This commit is contained in:
Cagdas Aras CIBLAK 2023-04-20 10:58:19 +02:00
commit 83f10a142a
4 changed files with 115 additions and 0 deletions

10
Hamming_Windower.m Normal file
View File

@ -0,0 +1,10 @@
function windowed_signal = Hamming_Windower(signal)
% Calculate the length of the signal
N = length(signal);
% Create the Hamming window
window_function = hamming(N);
% Apply the Hamming window to the signal
windowed_signal = signal .* window_function;
end

32
Raw_Signal_Plotter.m Normal file
View File

@ -0,0 +1,32 @@
% Loading the signal
pkg load signal
data = csvread('unknownsignal.csv');
signal=data';
N = length(signal); % Number of samples
% Plot the signal in the time domain
t = linspace(0, (N-1)/Fs, N); % Time vector
figure;
plot(t, signal);
xlabel('Time (s)');
ylabel('Amplitude');
title('Signal in Time Domain');
grid on;
% Compute the FFT and normalize
fft_signal = fft(signal, N);
fft_signal_normalized = fft_signal / N;
% Compute the magnitude spectrum
magnitude_spectrum = abs(fft_signal_normalized);
% Generate the frequency vector
frequencies = linspace(0, Fs/2, N/2);
% Plot the spectrum in the frequency domain
figure;
plot(frequencies, magnitude_spectrum(1:N/2));
xlabel('Frequency (Hz)');
ylabel('Magnitude');
title('Magnitude Spectrum of the Signal');
grid on;

View File

@ -0,0 +1,72 @@
% Load Signal
pkg load signal
data = csvread('unknownsignal.csv');
signal=data';
Fs=300
N=length(signal)
% Apply the Hamming Filter
signal_Windowed = Hamming_Windower(signal);
% Spectral Analysis (FFT)
% Compute the FFT of the windowed signal
signal_Windowed_fft = fft(signal_Windowed, N);
% Normalize the FFT
signal_Windowed_fft_norm = signal_Windowed_fft / N;
% Compute the magnitude spectrum
magnitude_spectrum = abs(signal_Windowed_fft_norm);
% Generate the frequency vector
frequencies = linspace(0, Fs/2, N/2);
% Plot the magnitude spectrum in the frequency domain
figure;
plot(frequencies, magnitude_spectrum(1:N/2));
xlabel('Frequency (Hz)');
ylabel('Magnitude');
title('Magnitude Spectrum of the Windowed Signal');
grid on;
% Define the frequency range of interest
low_freq = 27;
high_freq = 66;
% Normalize the frequencies (Nyquist criterion)
low_freq_norm = low_freq / (Fs/2);
high_freq_norm = high_freq / (Fs/2);
% Design a Butterworth bandpass filter
filter_order = 4; % can be adjusted to modify rolloff
[b, a] = butter(filter_order, [low_freq_norm, high_freq_norm], 'bandpass');
% Apply the Butterworth filter to the windowed signal
filtered_signal = filter(b, a, signal_Windowed);
% Plot the filtered signal in the time domain
t = linspace(0, (N-1)/Fs, N); % Time vector
figure;
plot(t, filtered_signal);
xlabel('Time (s)');
ylabel('Amplitude');
title('Filtered Signal in Time Domain');
grid on;
% Compute the FFT of the filtered signal and normalize it
fft_filtered_signal = fft(filtered_signal, N);
fft_filtered_signal_normalized = fft_filtered_signal / N;
% Compute the magnitude spectrum
magnitude_spectrum_filtered = abs(fft_filtered_signal_normalized);
% Generate the frequency vector
frequencies = linspace(0, Fs/2, N/2);
% Plot the magnitude spectrum of the filtered signal in the frequency domain
figure;
plot(frequencies, magnitude_spectrum_filtered(1:N/2));
xlabel('Frequency (Hz)');
ylabel('Magnitude');
title('Magnitude Spectrum of the Filtered Signal');
grid on;

1
unknownsignal.csv Normal file

File diff suppressed because one or more lines are too long