BumbleBee09 said:Hi all,
I have just started out with my signals and systems course and as an exercise I am trying to do visualise the sampling theorem on MATLAB Hence I need to do something as simple as multiplying a continous signal with an impulse train. I am struggling to write the code . Please help me!!
I can plot the sine/cosine signal and the impulse train separately but cannot multiply them
% Cosine from -pi to pi
t1 = linspace(0, 6 , 1000);
x = cos( 2* pi * t);
%Impulse train
t2 = linspace ( 0,6,7 );
train = ones(1,t2);
% sampledsig = x.*train;
Now when I try to multiply them , I am always getting an error which is obvious since the vector size is different . Any help is greatly appreciated .
Thanks & Regards
Well, I disagree: cos(2*pi*f*t1) is the most bandlimited signal you can think of! and according to the Nyquist theorem, you only need to sample at fs>2*f.Communications_Engineer said:In fact, you will observe that since cos(2*pi*t1) is not bandlimited, therefore you will require a sampling frequency much greater than 2*fmax
JoannesPaulus said:Well, I disagree: cos(2*pi*f*t1) is the most bandlimited signal you can think of! and according to the Nyquist theorem, you only need to sample at fs>2*f.Communications_Engineer said:In fact, you will observe that since cos(2*pi*t1) is not bandlimited, therefore you will require a sampling frequency much greater than 2*fmax
Try:
t=linspace(0,1,32);
f=3; x=cos(2*pi*f*t);
plot(t,x)
and then
f=28; x=cos(2*pi*f*t);
plot(t,x)
what is the difference?
No, not at all: it depends on the sampling rate! This is what the Nyquist theorem is telling you. If you want an alias free reconstruction of your signal, you need to sample with the proper rate. If you do not, you will not be able to reconstruct your signal correctly (in this case, you will not be able to tell whether the input signal has frequency f=3 or f=28...).Communications_Engineer said:Question for you:
Don't you think that since the frequencies are different then you should see "two different signals" in time domain?
No mistake there, it as exactly what I wanted to show!Communications_Engineer said:Let me also tell you that the mistake you have done is where you define t.
You have a step of 1/31, it means that the sampling frequency is 31 Hz and fmax can only be ≈ 15 Hz, meaning that the second plot you get is an alias of 28 Hz and not the original 28 Hz
JoannesPaulus said:Communications_Engineer said:Question for you:
Don't you think that since the frequencies are different then you should see "two different signals" in time domain?
This was to show that the cosine is bandlimited an therefore you can sample it with a rate lower than its frequency (a process called undersampling). :?:
The Nyquist theorem says that the sampling rate must be greater than the signal bandwidth and the cosine has the smallest possible bandwidth.
No mistake there, it as exactly what I wanted to show!
I hope this now clears the confusion.
JoannesPaulus said:can you please show me how the two signals in frequency domain are different (using the same sampling rate)?
figure(1)
plot(0:31,x1)
axis([0 31 -1 1]);
grid on
title('Time domain for signal with f=3Hz')
figure(3)
plot(0:31,x3)
axis([0 31 -1 1]);
grid on
title('Time domain for signal with f=28Hz')
I believe it has to be smaller than a certain size but I am not sure (I never tried).Communications_Engineer said:where is the option of displaying pictures here? Do you know?
JoannesPaulus said:How is Fig. 1 different from Fig. 3??
If you keep the same sampling rate (fs=31), f=3 and f=28 look no different! Isn't this what I have been saying all along?
I have about 20 years of experience in the field...Communications_Engineer said:I suggest you read Rick Lyons book on Digital Signal Processing
The result is surely correct! The 28Hz signal is aliased back to 3Hz. If you know what you are dealing with, this is not a problem. As I mentioned in one of my previous posts, sampling a signal at f=28Hz with 31Hz is a process called sub-sampling or undersampling (https://en.wikipedia.org/wiki/Undersampling). You can do it as long as the band of your signal is lower than fs/2. The max frequency could still be much larger than fs (there is a difference between bandwidth and frequency).Communications_Engineer said:JoannesPaulus said:How is Fig. 1 different from Fig. 3??
If you keep the same sampling rate (fs=31), f=3 and f=28 look no different! Isn't this what I have been saying all along?
Yes they are same, but you should see that since the sampling rate is small, you don't get the 28 Hz frequency component showing up, even though it should have.
A 3 Hz signal shows up (an alias of 28 Hz), so the result is incorrect.
Correct!Communications_Engineer said:Its like this, you are observing the following alias,
31 - 1 * 28 = 3 Hz
or generally,
F_alias = f ± k.Fs
where
f = frequency of desired (continuous-time signal that you want to sample)
k = 1 to inf
Fs = sampling frequency
Incorrect! For a pure sinewave there won't be any more aliases. Just two tones ona at -f the other one at +f.Communications_Engineer said:There would be other aliases too, its just that you can't observe them since the frequency axis is limited to 0-Fs
Undersampling is a very common.Communications_Engineer said:So have you used sub-sampling (pure, not multi-rate) with your algorithms?
as long as the composite signal frequency bandwidth is less than fs/2, it always works. It is the Nyquist theorem applied to a band that is not baseband it is not black magic!Communications_Engineer said:if the signal is a composite one (more than a single frequency), would it still work?
search the internet for "IF sampling", sub-sampling, undersampling, "direct IF receivers" and so on...Communications_Engineer said:Kindly give a reference (except wikipedia). I wonder why most books don't talk about it.
This is basic Fourier transform: a pure sinewave in the frequency domain is represented by two delta functions, one at +f and the other at -f. In matlab, you need to use the function "fftshift" after fft in order to see the spectrum represented correctly (X11=fftshift(X1)). Your frequency axis should be defined as: f = k*Fs/length(X1)-Fs/2; then you can plot(f,abs(X11)) and see the two delta functions at +3 and -3.Communications_Engineer said:Furthermore, I need a reference for the third part, i.e. a CT-sine wave, once sampled would not have any more aliases except fs-f and fs+f and no more aliases. Is the math wrong?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?