Skip to main content
Bumped by Community user
Bumped by Community user
The code is now enclosed in a code block that enhances the readability.
Source Link
lennon310
  • 3.6k
  • 19
  • 25
  • 27

First, I apologize for the repost, I got really confused how Stack Exchange works. I tried my best to improve the question!

Anyhow - I'm fairly new to the world of DSP, and I'm struggling with finding a way to plot the frequency spectrum of a discrete signal I calculated, described by

$$x(k) = 4 \left(\frac{\sin(4\pi k/6)}{4\pi k/6}\right)^2$$

with $x(0)=2$

using Matlab.

I have so far tried 4 different solutions, only one of which looks plausible, but I'd like to be sure. I know it's probably solved using the fft function, but I can't quite put it together.

Could someone help me figure this out? It'd be greatly appreciated!

Edit: As kindly suggested - and I really should have thought of it! -,- this is the Matlab code I'm currently working with:

k = -12:12;

x_k = 4 * (sin(4 * pi * k / 6) ./ (4 * pi * k / 6)).^2;
x_k(k == 0) = 2; 

X_f = fftshift(fft(x_k));

f = linspace(-0.5, 0.5, length(k));  

figure;
stem(f, abs(X_f), 'filled');
title('Frequency Spectrum of the Discrete Signal x(k)');
xlabel('Frequency');
ylabel('Magnitude');
grid on;

And this is a picture of the resulting spectrum:

Spectrum

Thanks a lot for any advice!

First, I apologize for the repost, I got really confused how Stack Exchange works. I tried my best to improve the question!

Anyhow - I'm fairly new to the world of DSP, and I'm struggling with finding a way to plot the frequency spectrum of a discrete signal I calculated, described by

$$x(k) = 4 \left(\frac{\sin(4\pi k/6)}{4\pi k/6}\right)^2$$

with $x(0)=2$

using Matlab.

I have so far tried 4 different solutions, only one of which looks plausible, but I'd like to be sure. I know it's probably solved using the fft function, but I can't quite put it together.

Could someone help me figure this out? It'd be greatly appreciated!

Edit: As kindly suggested - and I really should have thought of it! -, this is the Matlab code I'm currently working with:

k = -12:12;

x_k = 4 * (sin(4 * pi * k / 6) ./ (4 * pi * k / 6)).^2;
x_k(k == 0) = 2; 

X_f = fftshift(fft(x_k));

f = linspace(-0.5, 0.5, length(k));  

figure;
stem(f, abs(X_f), 'filled');
title('Frequency Spectrum of the Discrete Signal x(k)');
xlabel('Frequency');
ylabel('Magnitude');
grid on;

And this is a picture of the resulting spectrum:

Spectrum

Thanks a lot for any advice!

First, I apologize for the repost, I got really confused how Stack Exchange works. I tried my best to improve the question!

Anyhow - I'm fairly new to the world of DSP, and I'm struggling with finding a way to plot the frequency spectrum of a discrete signal I calculated, described by

$$x(k) = 4 \left(\frac{\sin(4\pi k/6)}{4\pi k/6}\right)^2$$

with $x(0)=2$

using Matlab.

I have so far tried 4 different solutions, only one of which looks plausible, but I'd like to be sure. I know it's probably solved using the fft function, but I can't quite put it together.

Could someone help me figure this out? It'd be greatly appreciated!

Edit: As kindly suggested - and I really should have thought of it -- this is the Matlab code I'm currently working with:

k = -12:12;

x_k = 4 * (sin(4 * pi * k / 6) ./ (4 * pi * k / 6)).^2;
x_k(k == 0) = 2; 

X_f = fftshift(fft(x_k));

f = linspace(-0.5, 0.5, length(k));  

figure;
stem(f, abs(X_f), 'filled');
title('Frequency Spectrum of the Discrete Signal x(k)');
xlabel('Frequency');
ylabel('Magnitude');
grid on;

And this is a picture of the resulting spectrum:

Spectrum

The code is now enclosed in a code block that enhances the readability.
Source Link

First, I apologize for the repost, I got really confused how Stack Exchange works. I tried my best to improve the question!

Anyhow - I'm fairly new to the world of DSP, and I'm struggling with finding a way to plot the frequency spectrum of a discrete signal I calculated, described by

$$x(k) = 4 \left(\frac{\sin(4\pi k/6)}{4\pi k/6}\right)^2$$

with $x(0)=2$

using Matlab.

I have so far tried 4 different solutions, only one of which looks plausible, but I'd like to be sure. I know it's probably solved using the fft function, but I can't quite put it together.

Could someone help me figure this out? It'd be greatly appreciated!

Edit: As kindly suggested - and I really should have thought of it! -, this is the Matlab code I'm currently working with:

k = -12:12;

x_k = 4 * (sin(4 * pi * k / 6) ./ (4 * pi * k / 6)).^2; x_k(k == 0) = 2;

X_f = fftshift(fft(x_k));

f = linspace(-0.5, 0.5, length(k));

figure; stem(f, abs(X_f), 'filled'); title('Frequency Spectrum of the Discrete Signal x(k)'); xlabel('Frequency'); ylabel('Magnitude'); grid on;

k = -12:12;

x_k = 4 * (sin(4 * pi * k / 6) ./ (4 * pi * k / 6)).^2;
x_k(k == 0) = 2; 

X_f = fftshift(fft(x_k));

f = linspace(-0.5, 0.5, length(k));  

figure;
stem(f, abs(X_f), 'filled');
title('Frequency Spectrum of the Discrete Signal x(k)');
xlabel('Frequency');
ylabel('Magnitude');
grid on;

And this is a picture of the resulting spectrum:

Spectrum

Thanks a lot for any advice!

First, I apologize for the repost, I got really confused how Stack Exchange works. I tried my best to improve the question!

Anyhow - I'm fairly new to the world of DSP, and I'm struggling with finding a way to plot the frequency spectrum of a discrete signal I calculated, described by

$$x(k) = 4 \left(\frac{\sin(4\pi k/6)}{4\pi k/6}\right)^2$$

with $x(0)=2$

using Matlab.

I have so far tried 4 different solutions, only one of which looks plausible, but I'd like to be sure. I know it's probably solved using the fft function, but I can't quite put it together.

Could someone help me figure this out? It'd be greatly appreciated!

Edit: As kindly suggested - and I really should have thought of it! -, this is the Matlab code I'm currently working with:

k = -12:12;

x_k = 4 * (sin(4 * pi * k / 6) ./ (4 * pi * k / 6)).^2; x_k(k == 0) = 2;

X_f = fftshift(fft(x_k));

f = linspace(-0.5, 0.5, length(k));

figure; stem(f, abs(X_f), 'filled'); title('Frequency Spectrum of the Discrete Signal x(k)'); xlabel('Frequency'); ylabel('Magnitude'); grid on;

And this is a picture of the resulting spectrum:

Spectrum

Thanks a lot for any advice!

First, I apologize for the repost, I got really confused how Stack Exchange works. I tried my best to improve the question!

Anyhow - I'm fairly new to the world of DSP, and I'm struggling with finding a way to plot the frequency spectrum of a discrete signal I calculated, described by

$$x(k) = 4 \left(\frac{\sin(4\pi k/6)}{4\pi k/6}\right)^2$$

with $x(0)=2$

using Matlab.

I have so far tried 4 different solutions, only one of which looks plausible, but I'd like to be sure. I know it's probably solved using the fft function, but I can't quite put it together.

Could someone help me figure this out? It'd be greatly appreciated!

Edit: As kindly suggested - and I really should have thought of it! -, this is the Matlab code I'm currently working with:

k = -12:12;

x_k = 4 * (sin(4 * pi * k / 6) ./ (4 * pi * k / 6)).^2;
x_k(k == 0) = 2; 

X_f = fftshift(fft(x_k));

f = linspace(-0.5, 0.5, length(k));  

figure;
stem(f, abs(X_f), 'filled');
title('Frequency Spectrum of the Discrete Signal x(k)');
xlabel('Frequency');
ylabel('Magnitude');
grid on;

And this is a picture of the resulting spectrum:

Spectrum

Thanks a lot for any advice!

added 596 characters in body
Source Link
Pao
  • 21
  • 3

First, I apologize for the repost, I got really confused how Stack Exchange works. I tried my best to improve the question!

Anyhow - I'm fairly new to the world of DSP, and I'm struggling with finding a way to plot the frequency spectrum of a discrete signal I calculated, described by

$$x(k) = 4 \left(\frac{\sin(4\pi k/6)}{4\pi k/6}\right)^2$$

with $x(0)=2$

using Matlab.

I have so far tried 4 different solutions, only one of which looks plausible, but I'd like to be sure. I know it's probably solved using the fft function, but I can't quite put it together.

Could someone help me figure this out? It'd be greatly appreciated!

Edit: As kindly suggested - and I really should have thought of it! -, this is the Matlab code I'm currently working with:

k = -12:12;

x_k = 4 * (sin(4 * pi * k / 6) ./ (4 * pi * k / 6)).^2; x_k(k == 0) = 2;

X_f = fftshift(fft(x_k));

f = linspace(-0.5, 0.5, length(k));

figure; stem(f, abs(X_f), 'filled'); title('Frequency Spectrum of the Discrete Signal x(k)'); xlabel('Frequency'); ylabel('Magnitude'); grid on;

And this is a picture of the resulting spectrum:

Spectrum

Thanks a lot for any advice!

First, I apologize for the repost, I got really confused how Stack Exchange works. I tried my best to improve the question!

Anyhow - I'm fairly new to the world of DSP, and I'm struggling with finding a way to plot the frequency spectrum of a discrete signal I calculated, described by

$$x(k) = 4 \left(\frac{\sin(4\pi k/6)}{4\pi k/6}\right)^2$$

with $x(0)=2$

using Matlab.

I have so far tried 4 different solutions, only one of which looks plausible, but I'd like to be sure. I know it's probably solved using the fft function, but I can't quite put it together.

Could someone help me figure this out? It'd be greatly appreciated!

First, I apologize for the repost, I got really confused how Stack Exchange works. I tried my best to improve the question!

Anyhow - I'm fairly new to the world of DSP, and I'm struggling with finding a way to plot the frequency spectrum of a discrete signal I calculated, described by

$$x(k) = 4 \left(\frac{\sin(4\pi k/6)}{4\pi k/6}\right)^2$$

with $x(0)=2$

using Matlab.

I have so far tried 4 different solutions, only one of which looks plausible, but I'd like to be sure. I know it's probably solved using the fft function, but I can't quite put it together.

Could someone help me figure this out? It'd be greatly appreciated!

Edit: As kindly suggested - and I really should have thought of it! -, this is the Matlab code I'm currently working with:

k = -12:12;

x_k = 4 * (sin(4 * pi * k / 6) ./ (4 * pi * k / 6)).^2; x_k(k == 0) = 2;

X_f = fftshift(fft(x_k));

f = linspace(-0.5, 0.5, length(k));

figure; stem(f, abs(X_f), 'filled'); title('Frequency Spectrum of the Discrete Signal x(k)'); xlabel('Frequency'); ylabel('Magnitude'); grid on;

And this is a picture of the resulting spectrum:

Spectrum

Thanks a lot for any advice!

deleted 131 characters in body
Source Link
Jdip
  • 6.8k
  • 3
  • 8
  • 31
Loading
added 16 characters in body
Source Link
Jdip
  • 6.8k
  • 3
  • 8
  • 31
Loading
Source Link
Pao
  • 21
  • 3
Loading