Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function plotSignalCharacteristics(signal, fs)
- % Plot amplitude
- t = (0:length(signal)-1) / fs;
- figure;
- subplot(3,1,1);
- plot(t, signal);
- title('Amplitude');
- xlabel('Time (s)');
- ylabel('Amplitude');
- % Compute FFT and plot magnitude components
- N = length(signal);
- f = (0:N-1) * fs / N;
- magnitude = abs(fft(signal)/N);
- subplot(3,1,2);
- plot(f, magnitude(1:N/2+1));
- title('Magnitude Components (FFT)');
- xlabel('Frequency (Hz)');
- ylabel('Magnitude');
- % Plot spectrogram
- windowSize = 512;
- overlap = 256;
- subplot(3,1,3);
- spectrogram(signal, windowSize, overlap, windowSize, fs, 'yaxis');
- title('Spectrogram');
- xlabel('Time (s)');
- ylabel('Frequency (Hz)');
- end
- % Example usage
- fs = 1000; % Sampling frequency in Hz
- t = 0:1/fs:1-1/fs; % Time vector from 0 to 1 second with 1/fs spacing
- signal = sin(2*pi*50*t) + 0.5*cos(2*pi*150*t) + randn(size(t)); % Example signal with noise
- plotSignalCharacteristics(signal, fs);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement