4 svar
96 visningar
AstridG är nöjd med hjälpen
AstridG 66
Postad: 5 nov 2020 16:45

Matlab resample funktion

Hej jag behöver lite hjälp med matlab eftersom jag är inte så duktigt med kodning. Det så att jag behöver använda resample commando i samma graf för varje 4th o 128th punkter. vet inte riktigt hur och sen jag måste använda stem istället plot.

 

close all
clear all
[y,fs] = audioread('Sound4.wav');
t=linspace(0,length(y)/fs,length(y));
figure
stem(t,y(:,2),'*',t,y(:,1),'o')
figure ('name','Signal 1')
stem(t,y(:,1))
figure('name', 'Signal 2')
stem(t,y(:,2))
player = audioplayer(y,fs);
play(player)

Resample the signal at every 4th and 128th points. Plot the resampled signals in the
same graph as the original sample using “resample” in MATLAB. Describe the
difference between the three curves by zooming in on a short time segment.

JockeR 67
Postad: 5 nov 2020 20:56

I hjälpen för 'resample' finns följande som verkar lämpligt

y = resample(x,tx) resamples the values, x, of a signal sampled at the instants specified in vector tx. The function interpolates x linearly onto a vector of uniformly spaced instants with the same endpoints and number of samples as tx. NaNs are treated as missing data and are ignored.

Nu behövs en tidsvektor med aktuella tidpunkter.

Vet du hur man indexerar en befintlig vektor med 4 respektive 128 steg? 

 

'stem' anropas på samma sätt som 'plot', argumenten är x- respektive y-värden.

För att få alla i samma graf anropar du 'hold on' efter det första 'stem' / 'plot'.

Kommer du vidare då? 

AstridG 66
Postad: 5 nov 2020 22:23
JockeR skrev:

I hjälpen för 'resample' finns följande som verkar lämpligt

y = resample(x,tx) resamples the values, x, of a signal sampled at the instants specified in vector tx. The function interpolates x linearly onto a vector of uniformly spaced instants with the same endpoints and number of samples as tx. NaNs are treated as missing data and are ignored.

Nu behövs en tidsvektor med aktuella tidpunkter.

Vet du hur man indexerar en befintlig vektor med 4 respektive 128 steg? 

 

'stem' anropas på samma sätt som 'plot', argumenten är x- respektive y-värden.

För att få alla i samma graf anropar du 'hold on' efter det första 'stem' / 'plot'.

Kommer du vidare då? 

jag skulle gissa x = [0:4:max]

 x = [0:128:max]  men vet inte vad som är max. 

Dr. G 9326
Postad: 5 nov 2020 22:28

Sista elementet i en vektor kan du nå med end, t.ex

x(end)

eller även mindre kompakt som

x(length(x))

JockeR 67
Postad: 6 nov 2020 06:48

Dessutom har Matlab den lilla egenheten att vektorindexering börjar på 1.

Svara Avbryt
Close