71 lines
2.2 KiB
Matlab
71 lines
2.2 KiB
Matlab
#Date: 19/07/2023
|
|
#Author: Adrien COMBE
|
|
#Description: Retake exam Signal Processing
|
|
|
|
% Load the CSV file containing the signal
|
|
signal = csvread('unknownsignal.csv');
|
|
|
|
% Given sampling frequency Fs = 650 Hz
|
|
Fs = 650;
|
|
|
|
% Time vector
|
|
t = (0:length(signal)-1) / Fs;
|
|
|
|
% Plot the signal in the time domain
|
|
figure;
|
|
plot(t, signal);
|
|
xlabel('Time (s)');
|
|
ylabel('Amplitude');
|
|
title('Mysterious Signal in Time Domain');
|
|
|
|
% Define the window length in seconds
|
|
window_length_sec = 0.5; % You can adjust this value based on your needs
|
|
|
|
% Convert window length to samples
|
|
window_length_samples = round(window_length_sec * Fs);
|
|
|
|
% Create the Rectangular window
|
|
rectangular_window = rectwin(window_length_samples);
|
|
|
|
% Create the Hamming window
|
|
hamming_window = hamming(window_length_samples);
|
|
|
|
% Create the Hanning window
|
|
hanning_window = hanning(window_length_samples);
|
|
|
|
% Create the Blackman window
|
|
blackman_window = blackman(window_length_samples);
|
|
|
|
% Apply each window and perform spectral analysis using FFT
|
|
windows = {'Rectangular', 'Hamming', 'Hanning', 'Blackman'};
|
|
window_functions = {rectangular_window, hamming_window, hanning_window, blackman_window};
|
|
|
|
for i = 1:length(windows)
|
|
% Apply the current window to the signal
|
|
current_window = window_functions{i} .* signal(1:window_length_samples);
|
|
|
|
% Perform the Fast Fourier Transform (FFT) on the window
|
|
fft_result = fft(current_window);
|
|
|
|
% Compute the frequency axis for the FFT plot
|
|
f = (0:length(current_window)-1) * Fs / length(current_window);
|
|
|
|
% Identify the dominant frequencies (sine wave components) in the window
|
|
% Set a threshold to filter out noise
|
|
threshold = 50;
|
|
dominant_indices = find(abs(fft_result) > threshold);
|
|
|
|
% Display the dominant frequencies and their magnitudes for the current window
|
|
disp(['Dominant Frequencies (Hz) - ', windows{i}, ' Window:']);
|
|
disp(f(dominant_indices));
|
|
disp(['Magnitudes - ', windows{i}, ' Window:']);
|
|
disp(abs(fft_result(dominant_indices)));
|
|
|
|
% Plot the magnitude spectrum of the current window
|
|
figure;
|
|
plot(f, abs(fft_result));
|
|
xlabel('Frequency (Hz)');
|
|
ylabel('Magnitude');
|
|
title(['Magnitude Spectrum (FFT) of Mysterious Signal - ', windows{i}, ' Window']);
|
|
end
|