- fft: https://www.mathworks.com/help/matlab/ref/fft.html
- fftshift: https://www.mathworks.com/help/matlab/ref/fftshift.html
- abs: https://www.mathworks.com/help/matlab/ref/double.abs.html
- linspace: https://www.mathworks.com/help/matlab/ref/double.linspace.html
Divide a signal in interval times and calculate the average spectrum for each interval
3 次查看(过去 30 天)
显示 更早的评论
Hello!
I've created a daily signal (from 4000 files) that I'd like to divide into parts of one hour.
length(daily_signal)=7000000
I would like to break it down into 4000 parts, where each part has a sampling period of 1750
I can't figure out how to write the code to be able to divide the daily signal into parts and, for each part, calculate the average amplitude spectrum
really need ur help...
thank u
0 个评论
回答(1 个)
Aastha
2025-6-20
I understand it is your objective to divide a large signal of size 7,000,000 into 4000 parts of length 1 hour containing 1750 samples each and compute the amplitude spectrum averaged across all the parts. You can refer to the steps mentioned below to do so:
1. First, since you have 1750 samples for each hour (which is 3600 seconds), the sampling frequency can be computed using the below MATLAB code snippet:
Fs = 1750 / 3600; % Sampling frequency in Hz
You can initialize an array "avg_spectrum" to store the average amplitude spectrum and use a for loop to compute the amplitude spectrum and store the scaled amplitude spectrum corresponding to the each segment. You can refer to the below mentioned MATLAB code snippet to do so:
daily_signal = your_signal; % Replace with your 1x7000000 signal vector
L = 1750; % Samples per segment
N_parts = 4000; % Number of parts
Fn = Fs / 2; % Nyquist frequency
Fv = linspace(-Fn, Fn, L); % Frequency vector
avg_spectrum = zeros(1, L); % Initialize average spectrum accumulator
for i = 1:N_parts
idx_start = (i - 1)*L + 1;
idx_end = i * L;
segment = daily_signal(idx_start:idx_end);
Fc = fft(segment) / L;
amp = abs(fftshift(Fc)); % Centered amplitude spectrum
avg_spectrum = avg_spectrum + amp./N_parts;
end
2. The average amplitude spectrum can then be visualized as a function of frequency ranging from "-Fs/2" to "Fs/2" using the below MATLAB code snippet:
figure;
plot(Fv, avg_spectrum);
xlabel('Frequency (Hz)');
ylabel('Average Amplitude');
title('Average Amplitude Spectrum Over 4000 Segments');
For more information, you can refer to the MathWorks documentation below:
I hope this is helpful!
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!