Advertisement
STANAANDREY

apd asig3 fourier

Nov 1st, 2023
1,871
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 1.03 KB | None | 0 0
  1. function plotSignalCharacteristics(signal, fs)
  2.     % Plot amplitude
  3.     t = (0:length(signal)-1) / fs;
  4.     figure;
  5.     subplot(3,1,1);
  6.     plot(t, signal);
  7.     title('Amplitude');
  8.     xlabel('Time (s)');
  9.     ylabel('Amplitude');
  10.    
  11.     % Compute FFT and plot magnitude components
  12.     N = length(signal);
  13.     f = (0:N-1) * fs / N;
  14.     magnitude = abs(fft(signal)/N);
  15.     subplot(3,1,2);
  16.     plot(f, magnitude(1:N/2+1));
  17.     title('Magnitude Components (FFT)');
  18.     xlabel('Frequency (Hz)');
  19.     ylabel('Magnitude');
  20.    
  21.     % Plot spectrogram
  22.     windowSize = 512;
  23.     overlap = 256;
  24.     subplot(3,1,3);
  25.     spectrogram(signal, windowSize, overlap, windowSize, fs, 'yaxis');
  26.     title('Spectrogram');
  27.     xlabel('Time (s)');
  28.     ylabel('Frequency (Hz)');
  29. end
  30. % Example usage
  31. fs = 1000; % Sampling frequency in Hz
  32. t = 0:1/fs:1-1/fs; % Time vector from 0 to 1 second with 1/fs spacing
  33. signal = sin(2*pi*50*t) + 0.5*cos(2*pi*150*t) + randn(size(t)); % Example signal with noise
  34.  
  35. plotSignalCharacteristics(signal, fs);
  36.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement