Time domain signal representation problem - sampling frequency

9 visualizzazioni (ultimi 30 giorni)
Lukasz
Lukasz il 8 Ago 2023
Risposto: Divyam il 19 Nov 2024 alle 6:09
Good Day
I am trying to go through the basics of the signal processing in Matlab. I generated two cosine signals each 5Hz freq and sampling frequencies 1kHz and 10kHz. Next I've upsampled the signal (with sampling frequency 1kHz) with factor 10. The problem is, that on the plot in time domain, it looks that upsampling has changed the frequency of the signal to 0.5Hz. On the plots in frequency domain - three signals have same frequency 5Hz- what is correct.
Is there any way to represent signals in time domain in absolute way - where frequency is not affected by sampling frequency? Please see below the code and plots attached. Please note that 10kHz sampling frequency cosine signal is reduced to 500 to show that both 1kHz and 10kHz sampling frequency looks the same.
clear all
close all
f= 5;% signal frequency
t= 0:0.001:3-0.001;% time space for lower sampling freq
tt= 0:0.0001:30-0.0001;% time space for higher sampling freq
Fs = 1000; %Lower sampling Freq
N = size(t,2);% time space lower sampling freq
FsFs = 10000;% Higher Sampling Freq
NN = size(tt,2);% time space higher sampling freq
h= cos(2*pi*f*t);% cosine shape signal with lower sampling freq
hh=cos(2*pi*f*tt); % cosine shape signal with higher sampling freq
g= upsample(h, 10);% upsampled signal
f3 = 0:Fs/N:Fs/2-Fs/N; % space of freq domain lower sampling freq
Y = fft(h)/N;% Fourier transform of signal lower sampling freq
f3f3 = 0:FsFs/NN:FsFs/2-FsFs/NN;% space of freq domain higher sampling freq
YY = fft(hh)/NN;% Fourier transform of signal higher sampling freq
Yupsamp = fft(g)/N; % Fourier transform upsampled freq
subplot(5,1,1);
plot(t(1:1000),h(1:1000),'-o');
hold on;
plot(tt(1:5000), hh(1:5000), 'r-o');
hold on;
plot(t(1:1000), g(1:1000), 'b-o');
xlabel('Time');
ylabel('Signal');
title('Sinusoidal Signal Low Sampling Freq,High Sampling Freq, Low Sampling Freq upsampled 10 times');
subplot(5,1,2)
plot(f3, 2*abs(Y(1:N/2)));
xlabel('freq');
ylabel('Signal');
title('Sinusoidal Signal Low Sampling Freq - Freq Doamin');
subplot(5,1,3)
plot(f3f3, 2*abs(YY(1:NN/2)), 'c-o');
xlabel('freq');
ylabel('Signal');
title('Sinusoidal Signal High Sampling Freq - Freq Doamin');
subplot(5,1,4)
plot(f3, 2*abs(Yupsamp(1:N/2)));
xlabel('freq');
ylabel('Signal');
title('Sinusoidal Signal Low Sampling Freq upsampled 10 times')

Risposte (1)

Divyam
Divyam il 19 Nov 2024 alle 6:09
Hi @Lukasz,
Unsampling a signal increases the sample number due to insertion of zeros between the original samples. This process cannot change the frequency of the signal as you mentioned. However, it can cause unexpected behaviors when you are trying to visualize signals in the time domain.
To handle the problems with visualization in the time domain, ensure that after Unsampling, the signal is low-pass filtered to interpolate the inserted zeros and while plotting the time vector reflects the new sampling frequency. This will ensure that the frequency is not influenced by the sampling frequency. I have modified your code to incorporate the changes:
clear all
f = 5; % Signal frequency
t = 0:0.001:3-0.001; % Time vector for 1kHz sampling frequency
tt = 0:0.0001:3-0.0001; % Time vector for 10kHz sampling frequency
Fs = 1000; % Lower sampling frequency (1kHz)
FsFs = 10000; % Higher sampling frequency (10kHz)
h = cos(2*pi*f*t); % Cosine signal with lower sampling frequency
hh = cos(2*pi*f*tt); % Cosine signal with higher sampling frequency
% Upsample the signal with a factor of 10
g = upsample(h, 10);
% Low-pass filter the upsampled signal to interpolate
g_filtered = interp1(t, h, linspace(t(1), t(end), length(g)), 'linear');
% Fourier transforms
N = length(t);
NN = length(tt);
Y = fft(h)/N;
YY = fft(hh)/NN;
Yupsamp = fft(g_filtered)/length(g_filtered);
% Frequency vectors
f3 = 0:Fs/length(g_filtered):(Fs/2-Fs/length(g_filtered));
f3f3 = 0:FsFs/NN:FsFs/2-FsFs/NN;
% Plotting
figure;
subplot(5,1,1);
plot(t, h, '-o');
hold on;
% Uncomment these lines one by one to observe that the plots now overlap
%plot(tt(1:5000), hh(1:5000), 'r-o');
%plot(linspace(t(1), t(end), length(g_filtered)), g_filtered, 'b-o');
hold off;
xlabel('Time (s)');
ylabel('Signal');
title('Cosine Signal: Original, High Sampling, Upsampled and Interpolated');
legend('1kHz', '10kHz', 'Upsampled & Interpolated');
subplot(5,1,2);
plot(0:Fs/N:Fs/2-Fs/N, 2*abs(Y(1:N/2)));
xlabel('Frequency (Hz)');
ylabel('Magnitude');
title('Frequency Domain: 1kHz Sampling');
subplot(5,1,3);
plot(f3f3, 2*abs(YY(1:NN/2)), 'c-o');
xlabel('Frequency (Hz)');
ylabel('Magnitude');
title('Frequency Domain: 10kHz Sampling');
subplot(5,1,4);
plot(f3, 2*abs(Yupsamp(1:length(g_filtered)/2)));
xlabel('Frequency (Hz)');
ylabel('Magnitude');
title('Frequency Domain: Upsampled and Interpolated');

Categorie

Scopri di più su Signal Generation and Preprocessing in Help Center e File Exchange

Prodotti


Release

R2015a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by