## psd ----> spectrum psd?

### Redkap (view profile)

on 29 Feb 2012

Hi

I try to run this prog.

http://www.auditory.org/mhonarc/2000/msg00498.html

du calc. the specific loudness based on the zwicker model.

Whenn I run the prog. i get this back:

"Undefined function 'psd' for input arguments of type 'double'"

the Note in the Editor says

"The function PSD is deprecated. Use SPECTRUM.PSD instead.

What to do?

## Products

### Honglei Chen (view profile)

Answer by Honglei Chen

### Honglei Chen (view profile)

on 29 Feb 2012

You need to replace psd call with corresponding spectrum.psd code. Here is an example showing how to use spectrum.psd to compute PSD of a signal

```Fs = 1000;
t = 0:1/Fs:.3;
x=cos(2*pi*t*200)+randn(size(t));
Hs=spectrum.periodogram;
psd(Hs,x,'Fs',Fs)
```

### Redkap (view profile)

on 29 Feb 2012

thanks for advice, but can't follow you.

this is the m file

```% PowSpec.m
%
%	Methodology:
%
%	Syntax:
%	[Yxx,f]=PowSpec(y,fs,df)
%
%	Variables:
%	INPUT
%	y			=	Time signal
%	fs			=	Sampling frequency
%	df			=	DESIRED df
%
%	WORKING
%	NFFT		=	Nummber of points for a given fft
%	NOVERLAP	=	Number of Points to overlap
%
%	OUTPUT
%	Yxx		=	Power Spectrum Amplitude
%	f			=	Frequency vector of power spectrum
```
```%	Author:	Aaron Hastings, Herrick Labs, Purdue University
%	Date Started:	11 Nov 00
%	Last Revision:	11 Nov 00
%	Status: No Known Bugs
```
```function [Yxx,f]=PowSpec(y,fs,df);
```
```%%	Want to make sure that we have at least df resolution
NFFT=ceil(fs/df);
%%	Set NFFT to power of 2 again err towards higher resolution
NFFT=2^ceil(log2(NFFT));
```
```    NOVERLAP=0;
[Yxx,f] = psd(y,NFFT,fs,NFFT,NOVERLAP);
Yxx=2*Yxx/NFFT;	%%	Scale to get the power spectrum correct
Yxx=Yxx';```
`    return         `

### Honglei Chen (view profile)

Answer by Honglei Chen

### Honglei Chen (view profile)

on 29 Feb 2012

You will replace line

```[Yxx,f] = psd(y,NFFT,fs,NFFT,NOVERLAP);
```

with

```hspec = spectrum.welch('OverlapPercent',0,'SegmentLength',NFFT);
hpsd = psd(hspec,y,'NFFT',NFFT,'Fs',fs);
Yxx = hpsd.Data;
f = hpsd.Frequencies
```

Alternatively, you may also use

```[Yxx,f] = pwelch(y,NFFT,0,NFFT,fs);
```

### Redkap (view profile)

on 2 Mar 2012

sorry to bother again,

it' still not working:

```[Yxx,f]=PowSpec(y,fs,df);
```
```%%	Want to make sure that we have at least df resolution
NFFT=ceil(fs/df);
%%	Set NFFT to power of 2 again err towards higher resolution
NFFT=2^ceil(log2(NFFT));
```
```NOVERLAP=0;
hspec = spectrum.welch('OverlapPercent',0,'SegmentLength',NFFT);
hpsd = psd(hspec,y,'NFFT',NFFT,'Fs',fs);
Yxx = hpsd.Data;
f = hpsd.Frequencies;
Yxx=2*Yxx/NFFT;	%%	Scale to get the power spectrum correct
Yxx=Yxx';
```
```return
Undefined variable "spectrum" or class "spectrum.welch".
```
```Error in PowSpec (line 35)
hspec = spectrum.welch('OverlapPercent',0,'SegmentLength',NFFT);
```

### Wayne King (view profile)

Answer by Wayne King

### Wayne King (view profile)

on 2 Mar 2012

Hi Redkap, Honglei has been giving you very good advice here. What version of MATLAB are you using and do you have the Signal Processing Toolbox?

If you enter

```>>which spectrum.welch
```

What do you get returned?

Something is wrong if you cannot execute this line:

```plot(psd(spectrum.welch,randn(1e3,1)))
```

Can you copy and paste the above line into your workspace and see what happens?

Also, please tell us your version and make sure:

```license('test','signal_toolbox')
```

returns a 1.

By the way, in:

```hspec = spectrum.welch('OverlapPercent',0,'SegmentLength',NFFT);
hpsd = psd(hspec,y,'NFFT',NFFT,'Fs',fs);
Yxx = hpsd.Data;
f = hpsd.Frequencies;
Yxx=2*Yxx/NFFT;	%%	Scale to get the power spectrum correct
Yxx=Yxx';
```

You do not need to scale the output of the spectrum objects. That output is already properly scaled to be the PSD estimate so just use hpsd.Data and hpsd.Frequencies

#### 1 Comment

Elisabeth Debusschere

### Elisabeth Debusschere (view profile)

on 26 Mar 2012

I have the same problem, and checked the plot(psd(spectrum.welch,randn(1e3,1))) and the license

This is what I get
hspec = spectrum.welch('OverlapPercent',0,'SegmentLength',NFFT);
Error using spectrum.welch (line 52)

what is wrong?

Too many input arguments.

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi test

### Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.