问题标签 [resampling]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
3 回答
5089 浏览

image-resizing - Lanczos 重采样错误

我已经使用 Lanczos 重新采样编写了一个图像缩放器。我直接从 wikipedia 上的说明进行了实施。结果在视觉上看起来不错,但由于某种原因,它与 Matlab 使用 Lanczos 调整大小的结果不匹配(像素错误)。

有人看到任何错误吗?这根本不是我的专业领域...

这是我的过滤器(我默认使用 Lanczos3):

还有我调整图像大小的代码:

0 投票
2 回答
1503 浏览

c# - 如何实现 Matlab 的“速率转换”(在 C# 中)

我有一个以 10 000 Hz 的速率采样的信号,我需要将其重新采样到 4 000 Hz。在 MATLAB 中,我使用具有三个简单块的 simulink 模型:“From Workspace”,具有指定的采样时间(0.0001 s)->“Rate Transition”,指定的输出采样时间为 0.00025 s ->“To Workspace”来保存输出数据。(一个速率转换块我看到“No Op”)。

我认为可以使用诸如“interp1”之类的Matlab函数来插入数据,但没有运气。我已经尝试了所有方法,但我仍然不知道如何实现“速率转换”具有的相同功能。

我需要用 C# 编写这个数据重采样,我的问题是:这个 simulink 的底层算法是什么,将数据从一个采样频率移植到另一个采样频率?或者我怎样才能得到我需要的效果?

谢谢,KP

0 投票
1 回答
4257 浏览

pandas - 熊猫将每小时时间序列重新采样为每小时比例时间序列

我正在使用每小时时间序列(日期,时间(小时),P)并尝试计算每小时每日总“金额”的比例。我知道我可以使用 Pandas 的 resample('D', how='sum') 来计算 P (DailyP) 的每日总和,但在同一步骤中,我想使用每日 P 来计算每日 P 在每小时(因此,P/DailyP)以每小时时间序列结束(即,与原始频率相同)。我不确定这是否可以在 Pandas 术语中称为“重采样”。这从我对术语的使用中可能很明显,但我绝对是 Python 或编程的新手。如果有人可以建议一种方法来做到这一点,我将不胜感激。谢谢!

0 投票
1 回答
421 浏览

python - 带有熊猫重采样的额外箱

我有一个这样定义的熊猫数据框:

当我去重新取样时:

我最终得到了一个我不希望看到的额外空垃圾箱——2001-06-01。我不希望那个垃圾箱在那里,因为我的 28 天可以平均分为我正在执行的 7 天重新采样。我试过弄乱封闭的kwarg,但我无法逃脱那个额外的垃圾箱。为什么当我没有任何东西可以放入时出现那个额外的垃圾箱,我怎样才能避免生成它?

我最终想要做的是每个 REST_KEY 获得 7 天的平均值,所以做一个

但是那个额外的空垃圾箱正在抛弃我的平均值(例如,对于 COOP_DLY_SLS_AMT,我有 112,即 (20 * 7 * 4) / 5 而不是我从 (20 * 7 * 4) / 4 得到的 140 如果我没有那个额外的垃圾箱。)我也不希望 REST_KEY 出现在聚合中,因为它是 groupby 的一部分,但这确实是一个较小的问题。

PS我正在使用熊猫0.11.0

0 投票
1 回答
244 浏览

group-by - pandas:在组内进行计算的有效方法

我正在处理这样的事务数据:

现在我想按购买日期、买家和产品分组来计算以下问题:

  • 客户每天在该部门呆了多长时间(第一次购买时间 - 最后一次购买时间)?如果仅让我们假设 1h。

  • 直到中午和午夜,每天最畅销的产品是什么?

  • 如何在不使用 avg 而是使用自定义函数的情况下计算平均采购数量等组间统计数据?

更新

  • 是否也有可能遍历组内的列,例如我想计算一个列,该列显示 Carl 和所有其他买家之间的数量差异。它看起来像这样

    /li>
  • 此外,是否有没有发生购买的日子?

我会非常感谢你的帮助谢谢

安迪

0 投票
0 回答
1229 浏览

c++ - FFMPEG 音频上采样/重采样到 48000 Hz 会导致声音喘鸣/噪音/失真

我正在使用以下示例http://svn.gnumonks.org/tags/21c3-video/upstream/ffmpeg-0.4.9-pre1/output_example.c制作视频。如果我使用 44100 Hz 作为输出音频格式,似乎一切都很好,但如果我使用 48000 Hz,任何音频都会发出喘息声。

有什么建议,请。

这是输入音频和带有该音频但在 48 kHz 中具有喘息音频的编码视频: http ://www.unsode.com/test.zip

0 投票
1 回答
3061 浏览

python - 将图像下采样为 Python 中的函数

我正在尝试将一些 tiff 文件从 2000*2000 重新采样到 500*500。我创建了一个函数,我尝试了一个文件,它运行良好。现在我想将它应用于我拥有的所有可用文件。

我想编写函数的输出,并且根据我的知识编写了代码,并且在写入 out_file 时收到错误。我已经复制了函数和主代码供您考虑。主要代码只是根据它们的命名读取tif文件并应用函数。如果某人能指导我的错误在哪里,我将不胜感激。

0 投票
0 回答
876 浏览

python - Pandas:使用 Multiindex 进行复杂的重采样和分组

我有以下数据框:

我想每天重新采样这个 DataFrame 并计算以下复杂的统计数据。

  • 对于每种产品:EMA 价值(前一天)与交易者实际购买之间的每周平均差异是多少

  • 对于每种产品:交易者购买日期的每周平均方差是多少

因此,作为第一步,我取消了 Product 和 Trader 列,并使用以下方法计算 ema:

更新:

感谢 Wouter Overmeire 的评论,我可以使用以下方法将移位的趋势值与原始值结合起来:

基于此 DateFrame,我尝试使用按功能分组来回答上述两个问题。不幸的是,我无法从交易者列中抽象出来,因为它仍在按功能分组的结果中。有人有想法吗?

我将非常感谢任何帮助。

谢谢

安迪

0 投票
1 回答
6431 浏览

python - 如何使用 fill_value 对 Pandas 中的 TimeSeries 重新采样?

我有一个TimeSeries整数,我想使用resample(). 问题是我有一些缺失数据的时期被转换为NaN. 由于 pandas 不支持Integer NA 值,因此整数将转换为浮点数。

是否可以像我一样TimeSeries使用 a对丢失的数据进行重新采样?我不希望我的整数转换成浮点数。fill_valuereindex(fill_value=0)

0 投票
4 回答
16512 浏览

ffmpeg - How to encode resampled PCM-audio to AAC using ffmpeg-API when input pcm samples count not equal 1024

I am working on capturing and streaming audio to RTMP server at a moment. I work under MacOS (in Xcode), so for capturing audio sample-buffer I use AVFoundation-framework. But for encoding and streaming I need to use ffmpeg-API and libfaac encoder. So output format must be AAC (for supporting stream playback on iOS-devices).

And I faced with such problem: audio-capturing device (in my case logitech camera) gives me sample-buffer with 512 LPCM samples, and I can select input sample-rate from 16000, 24000, 36000 or 48000 Hz. When I give these 512 samples to AAC-encoder (configured for appropriate sample-rate), I hear a slow and jerking audio (seems as like pice of silence after each frame).

I figured out (maybe I am wrong), that libfaac encoder accepts audio frames only with 1024 samples. When I set input samplerate to 24000 and resample input sample-buffer to 48000 before encoding, I obtain 1024 resampled samples. After encoding these 1024 sampels to AAC, I hear proper sound on output. But my web-cam produce 512 samples in buffer for any input samplerate, when output sample-rate must be 48000 Hz. So I need to do resampling in any case, and I will not obtain exactly 1024 samples in buffer after resampling.

Is there a way to solve this problem within ffmpeg-API functionality?

I would be grateful for any help.

PS: I guess that I can accumulate resampled buffers until count of samples become 1024, and then encode it, but this is stream so there will be troubles with resulting timestamps and with other input devices, and such solution is not suitable.

The current issue came out of the problem described in [question]: How to fill audio AVFrame (ffmpeg) with the data obtained from CMSampleBufferRef (AVFoundation)?

Here is a code with audio-codec configs (there also was video stream but video work fine):

And resampling and encoding audio: