32 lines
770 B
Matlab
32 lines
770 B
Matlab
% 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; |